diff --git a/README.md b/README.md index 0443feb..f132012 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -A markdown-it plugin supporting Chrome 75's [native image lazy-loading](https://addyosmani.com/blog/lazy-loading/). +A markdown-it plugin supporting Chrome 75's [native image lazy-loading](https://addyosmani.com/blog/lazy-loading/) and [async decoding](https://github.com/whatwg/html/pull/3221). ## Install @@ -14,7 +14,7 @@ const lazy_loading = require('markdown-it-image-lazy-loading'); md.use(lazy_loading); md.render(`![](example.png "image title")`); -//

\n +//

\n ``` The plugin can also add `width` and `height` attributes to each image. This can prevent [cumulative layout shifts (CLS)](https://web.dev/cls/): @@ -28,7 +28,7 @@ md.use(lazy_loading, { }); md.render(`![](example.png "image title")`); -//

\n +//

\n ``` To keep images responsive, also include the following CSS: diff --git a/index.js b/index.js index ecb0f0f..01df865 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ module.exports = function lazy_loading_plugin(md, mdOptions) { md.renderer.rules.image = function (tokens, idx, options, env, self) { var token = tokens[idx]; token.attrSet('loading', 'lazy'); + token.attrSet('decoding', 'async'); if(mdOptions && mdOptions.base_path && mdOptions.image_size === true){ const sizeOf = require('image-size'); diff --git a/test/basic.js b/test/basic.js index dccdaff..354764c 100644 --- a/test/basic.js +++ b/test/basic.js @@ -9,7 +9,7 @@ test('lazy loading test', function (t) { t.equal( md.render(`![](example.png "image title")`), - '

\n' + '

\n' ); }); diff --git a/test/image-size.js b/test/image-size.js index e8ae20e..160c6a2 100644 --- a/test/image-size.js +++ b/test/image-size.js @@ -12,7 +12,7 @@ test('image size test', function (t) { t.equal( md.render(`![](dummy-200x200.png "image title")`), - '

\n' + '

\n' ); });