Skip to content

Commit

Permalink
Support markdown sub/superscript, use external crate for spoilers (Le…
Browse files Browse the repository at this point in the history
…mmyNet#5135)

* Use external crate for spoiler tags

* Also add other plugins

* fix test
  • Loading branch information
Nutomic authored Oct 25, 2024
1 parent 859dfb3 commit 322538b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 206 deletions.
44 changes: 43 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ ts-rs = { workspace = true, optional = true }
enum-map = { workspace = true, optional = true }
cfg-if = "1"
clearurls = { version = "0.0.4", features = ["linkify"] }
markdown-it-block-spoiler = "1.0.0"
markdown-it-sub = "1.0.0"
markdown-it-sup = "1.0.0"
markdown-it-ruby = "1.0.0"

[dev-dependencies]
reqwest = { workspace = true }
Expand Down
18 changes: 15 additions & 3 deletions crates/utils/src/utils/markdown/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ use std::sync::LazyLock;

pub mod image_links;
mod link_rule;
mod spoiler_rule;

static MARKDOWN_PARSER: LazyLock<MarkdownIt> = LazyLock::new(|| {
let mut parser = MarkdownIt::new();
markdown_it::plugins::cmark::add(&mut parser);
markdown_it::plugins::extra::add(&mut parser);
spoiler_rule::add(&mut parser);
markdown_it_block_spoiler::add(&mut parser);
markdown_it_sub::add(&mut parser);
markdown_it_sup::add(&mut parser);
markdown_it_ruby::add(&mut parser);
link_rule::add(&mut parser);

parser
Expand Down Expand Up @@ -102,12 +104,22 @@ mod tests {
(
"basic spoiler",
"::: spoiler click to see more\nhow spicy!\n:::\n",
"<details><summary>click to see more</summary><p>how spicy!\n</p></details>\n"
"<details><summary>click to see more</summary>how spicy!\n</details>\n"
),
(
"escape html special chars",
"<script>alert('xss');</script> hello &\"",
"<p>&lt;script&gt;alert(‘xss’);&lt;/script&gt; hello &amp;&quot;</p>\n"
),("subscript","log~2~(a)","<p>log<sub>2</sub>(a)</p>\n"),
(
"superscript",
"Markdown^TM^",
"<p>Markdown<sup>TM</sup></p>\n"
),
(
"ruby text",
"{漢|Kan}{字|ji}",
"<p><ruby>漢<rp>(</rp><rt>Kan</rt><rp>)</rp></ruby><ruby>字<rp>(</rp><rt>ji</rt><rp>)</rp></ruby></p>\n"
)
];

Expand Down
202 changes: 0 additions & 202 deletions crates/utils/src/utils/markdown/spoiler_rule.rs

This file was deleted.

0 comments on commit 322538b

Please sign in to comment.