Installations
npm install markdown-it-image-figures
Developer Guide
Typescript
No
Module System
ESM
Min. Node Version
>=12.0.0
Node Version
16.15.1
NPM Version
8.11.0
Score
86.6
Supply Chain
100
Quality
75.5
Maintenance
100
Vulnerability
99.6
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Antonio-Laguna
Download Statistics
Total Downloads
675,475
Last Day
1,573
Last Week
8,604
Last Month
42,846
Last Year
438,039
GitHub Statistics
21 Stars
40 Commits
5 Forks
2 Watching
1 Branches
2 Contributors
Bundle Size
2.45 kB
Minified
1.03 kB
Minified + Gzipped
Package Meta Information
Latest Version
2.1.1
Package Id
markdown-it-image-figures@2.1.1
Unpacked Size
22.14 kB
Size
5.94 kB
File Count
8
NPM Version
8.11.0
Node Version
16.15.1
Total Downloads
Cumulative downloads
Total Downloads
675,475
Last day
-20.6%
1,573
Compared to previous day
Last week
-20.4%
8,604
Compared to previous week
Last month
2.3%
42,846
Compared to previous month
Last year
109.1%
438,039
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
Markdown IT Image Figures
Render images occurring by itself in a paragraph as <figure><img ...></figure>
, similar to pandoc's implicit figures.
This module is a fork from markdown-it-implicit-figures in which I wanted to introduce new features and make sure this was up to what the standard is today.
Example input:
1text with ![](img.png) 2 3![](fig.png) 4 5works with links too: 6 7[![](fig.png)](page.html)
Output:
1<p>text with <img src="img.png" alt=""></p> 2<figure><img src="fig.png" alt=""></figure> 3<p>works with links too:</p> 4<figure><a href="page.html"><img src="fig.png" alt=""></a></figure>
Install
$ npm i markdown-it-image-figures
Usage
1const md = require('markdown-it')(); 2const implicitFigures = require('markdown-it-image-figures'); 3 4md.use(implicitFigures); 5 6const src = 'text with ![](img.png)\n\n![](fig.png)\n\nanother paragraph'; 7const res = md.render(src); 8 9console.log(res); 10 11/* 12<p>text with <img src="img.png" alt=""></p> 13<figure><img src="fig.png" alt=""></figure> 14<p>another paragraph</p> 15*/
Options
-
dataType
: SetdataType
totrue
to declare thedata-type
being wrapped, e.g.:<figure data-type="image">
. This can be useful for applying a special styling for different kind of figures. -
figcaption
: Setfigcaption
totrue
or"title"
to use the title as a<figcaption>
block after the image; setfigcaption
to"alt"
to use the alt text as a<figcaption>
. E.g.:![This is an alt](fig.png "This is a title")
renders to
1<figure> 2 <img src="fig.png" alt="This is an alt"> 3 <figcaption>This is a title</figcaption> 4</figure>
-
tabindex
: Settabindex
totrue
to add atabindex
property to each figure, beginning attabindex="1"
and incrementing for each figure encountered. Could be used with this css-trick, which expands figures upon mouse-over. -
link
: Put a link around the image if there is none yet. -
copyAttrs
: Copy attributes matching (RegExp or string)copyAttrs
tofigure
element. -
lazy
: Applies theloading
attribute aslazy
. -
removeSrc
: Removes the source from the image and saves it ondata-src
.
Code like ![alt](fig.png)
renders to:
1<figure> 2 <img alt="alt" src="fig.png" loading="lazy"> 3</figure>
You can override it for a single image with something like ![alt](fig.png){loading=eager}
which will generate the following markup:
1<figure> 2 <img alt="alt" src="fig.png" loading="eager"> 3</figure>
-
classes
: Adds the classes to the list of classes the image might have. -
async
: Adds the attributedecoding="async"
to all images. As withlazy
you should be able to undo this for singular images![alt](fig.png){decoding=auto}
Web performance recommended settings
Recommended settings for web performance is as follows
{
lazy: true,
async: true
}
Which will add loading="lazy"
and decoding="async"
to all images. This can be changed per image as explained above so you can opt out for a image at the top if you'd like. This will work great for the majority of the browsers.
However, if you need to broad your browser support and ensure that old browsers get lazy loaded images, you should probably use this setting:
1md.use(implicitFigures, { 2 lazy: true, 3 removeSrc: true, 4 async: true, 5 classes: 'lazy' 6}); 7 8const src = '![alt](fig.png)'; 9const res = md.render(src); 10 11console.log(res); 12/* 13<figure> 14 <img alt="alt" data-src="fig.png" class="lazy" loading="lazy" decoding="async"> 15</figure> 16*/
Then you need to load something like Lozad.js and some script like this. You might want to customise the class on the attribute classes
which get added to the img
(for easy selector).
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/Antonio-Laguna/markdown-it-image-figures/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/Antonio-Laguna/markdown-it-image-figures/ci.yml/main?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
Reason
9 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-ghr5-ch3p-vcr6
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/25 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 7 are checked with a SAST tool
Score
3.1
/10
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to markdown-it-image-figures
markdown-it-implicit-figures
Render images occurring by itself in a paragraph as `<figure><img ...></figure>`, similar to pandoc's implicit_figures
@ruanyf/markdown-it-implicit-figures
Render images occurring by itself in a paragraph as `<figure><img ...></figure>`, similar to pandoc's implicit_figures