@onlinemad/markdown-it-image-lazy-loading

1.1.2 • Public • Published

A markdown-it plugin supporting Chrome 75's native image lazy-loading.

Install

$ npm install markdown-it-image-lazy-loading

Usage

const md = require('markdown-it')();
const lazy_loading = require('markdown-it-image-lazy-loading');
md.use(lazy_loading);

md.render(`![](example.png "image title")`);
// <p><img src="example.png" alt="" title="image title" loading="lazy"></p>\n

The plugin can also add width and height attributes to each image. This can prevent cumulative layout shifts (CLS):

md.use(lazy_loading, {
    image_size: true,

    // Where your images are stored
    base_path: __dirname + 'src/',
});

md.render(`![](example.png "image title")`);
// <p><img src="example.png" alt="" title="image title" loading="lazy" width="100" height="100"></p>\n

To keep images responsive, also include the following CSS:

img{
    max-width: 100%;
    height: auto;
}

License

MIT

Package Sidebar

Install

npm i @onlinemad/markdown-it-image-lazy-loading

Weekly Downloads

1

Version

1.1.2

License

MIT

Unpacked Size

2.84 kB

Total Files

3

Last publish

Collaborators

  • onlinemad