2.0.1 • Published 7 months ago

rehype-imgload v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

rehype-imgload

GitHub Workflow Status npm bundle size

Rehype plugin to add loading property into <img> tags.

Installation

# use yarn
$ yarn add rehype-imgload

# use npm
$ npm install rehype-imgload

Usage

General Use

Adds loading property to your <img>s.

import rehypeImgLoad from "rehype-imgload";
import rehypeParse from "rehype-parse";
import rehypeStringify from "rehype-stringify";
import { unified } from "unified";

const processor = unified()
  .use(rehypeParse)
  .use(rehypeImgLoad)
  .use(rehypeStringify);

const output = processor.processSync(
  '<img src="/example.jpg"><img src="/example.jpg" loading="eager">'
);
console.log(output.toString());
// '<img src="/example.jpg" loading="lazy"><img src="/example.jpg" loading="eager">'
// Latter `img` is not changed because `overwrite` is `false` by default.
// Pass { overwrite: true } option to overwrite existing loading property.

API

This package exports no identifiers. Default export is rehypeImgLoad.

unified().use(rehypeImgLoad[, options])

All options are optional.

options.overwrite

boolean. default=false

  • If false, existing loading properties will remain unchanged.
  • If true, all loading properties will be overwritten to loading=options.mode(see below).
options.mode

"lazy" | "eager", default="lazy"

Indicates how the browser should load the image. MDN Reference

LICENSE

MIT

2.0.1

7 months ago

2.0.0

7 months ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.0

3 years ago