New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

markdown-it-image-lazy-loading

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markdown-it-image-lazy-loading

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

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.2K
increased by8.92%
Maintainers
1
Weekly downloads
 
Created
Source

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

Install

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

Usage

Load it in ES module.

import markdownit from 'markdown-it';
import lazy_loading from 'markdown-it-image-lazy-loading';

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

Or load it in CommonJS module.

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

If you want the decoding="async" attribute, enable the plugin's decoding option.

md.use(lazy_loading, {
  decoding: true,
});

md.render(`![](example.png "image title")`);
// <p><img src="example.png" alt="" title="image title" loading="lazy" decoding="async"></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

Keywords

FAQs

Package last updated on 19 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc