zola/components/markdown/tests
sinofp 22dc32a589 Add support for lazy loading images (#2211)
* Add optional decoding="async" loading="lazy" for img

In theory, they can make the page load faster and show content faster.

There’s one problem: CommonMark allows arbitrary inline elements in alt text.
If I want to get the correct alt text, I need to match every inline event.

I think most people will only use plain text, so I only match Event::Text.

* Add very basic test for img

This is the reason why we should use plain text when lazy_async_image is enabled.

* Explain lazy_async_image in documentation

* Add test with empty alt and special characters

I totaly forgot one can leave the alt text empty.
I thought I need to eliminate the alt attribute in that case,
but actually empty alt text is better than not having an alt attribute at all:
https://www.w3.org/TR/WCAG20-TECHS/H67.html
https://www.boia.org/blog/images-that-dont-need-alternative-text-still-need-alt-attributes
Thus I will leave the empty alt text.

Another test is added to ensure alt text is properly escaped.
I will remove the redundant escaping code after this commit.

* Remove manually escaping alt text

After removing the if-else inside the arm of Event::Text(text),
the alt text is still escaped.
Indeed they are redundant.

* Use insta for snapshot testing

`cargo insta review` looks cool!

I wanted to dedup the cases variable,
but my Rust skill is not good enough to declare a global vector.
2023-12-18 23:24:06 +01:00
..
snapshots Add support for lazy loading images (#2211) 2023-12-18 23:24:06 +01:00
codeblocks.rs Fix some bugs + cargo fmt 2022-07-12 00:09:38 +02:00
common.rs Reenable link rewriting for colocated assets 2022-06-10 20:41:24 +02:00
img.rs Add support for lazy loading images (#2211) 2023-12-18 23:24:06 +01:00
links.rs Re-organise content and remove slotmap indirection level (#1827) 2022-04-26 20:51:04 +02:00
markdown.rs Insert anchor as full heading (#1916) 2022-07-10 15:02:07 +02:00
shortcodes.rs Re-organise content and remove slotmap indirection level (#1827) 2022-04-26 20:51:04 +02:00
summary.rs Re-organise content and remove slotmap indirection level (#1827) 2022-04-26 20:51:04 +02:00
toc.rs Re-organise content and remove slotmap indirection level (#1827) 2022-04-26 20:51:04 +02:00