marked-image-lazy-loading
v0.0.2
Published
Add lazy loading for all images
Readme
marked-image-lazy-loading
Add loading="lazy" to all images rendered by marked.
Install
npm i marked-image-lazy-loadingRequires
marked >= 4(peer dependency).
Usage
ESM / TypeScript
import { marked } from 'marked';
import { lazyImage } from 'marked-image-lazy-loading';
marked.use(lazyImage());
marked.parse('');
// <p><img src="a.png" alt="alt" loading="lazy"></p>CommonJS
const { marked } = require('marked');
const lazyImage = require('marked-image-lazy-loading');
marked.use(lazyImage());API
lazyImage(options?)
Returns a marked extension object.
| Option | Type | Default | Description |
| --- | --- | --- | --- |
| options.loading | 'lazy' \| 'eager' | 'lazy' | Value written to the <img> loading attribute |
marked.use(lazyImage({ loading: 'eager' }));
// <img src="a.png" alt="alt" loading="eager">License
MIT
