diff --git a/Cargo.lock b/Cargo.lock index b2a5269e..0f6418eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -128,6 +128,31 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "bon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a636f83af97c6946f3f5cf5c268ec02375bf5efd371110292dfd57961f57a509" +dependencies = [ + "bon-macros", + "rustversion", +] + +[[package]] +name = "bon-macros" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7eaf1bfaa5b8d512abfd36d0c432591fef139d3de9ee54f1f839ea109d70d33" +dependencies = [ + "darling", + "ident_case", + "prettyplease", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + [[package]] name = "bumpalo" version = "3.16.0" @@ -237,13 +262,13 @@ dependencies = [ [[package]] name = "comrak" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8c32ff8b21372fab0e9ecc4e42536055702dc5faa418362bffd1544f9d12637" +checksum = "949f8e6b02ebac005a8be2df9ec0876cafc83fdb9c510796c37f0fadf92dcd0e" dependencies = [ + "bon", "caseless", "clap", - "derive_builder", "emojis", "entities", "memchr", @@ -310,37 +335,6 @@ dependencies = [ "powerfmt", ] -[[package]] -name = "derive_builder" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0350b5cb0331628a5916d6c5c0b72e97393b8b6b03b47a9284f4e7f5a405ffd7" -dependencies = [ - "derive_builder_macro", -] - -[[package]] -name = "derive_builder_core" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d48cda787f839151732d396ac69e3473923d54312c070ee21e9effcaa8ca0b1d" -dependencies = [ - "darling", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "derive_builder_macro" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "206868b8242f27cecce124c19fd88157fbd0dd334df2587f36417bafbc85097b" -dependencies = [ - "derive_builder_core", - "syn", -] - [[package]] name = "deunicode" version = "1.6.0" @@ -642,11 +636,21 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" +[[package]] +name = "prettyplease" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" +dependencies = [ + "proc-macro2", + "syn", +] + [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -753,6 +757,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustversion" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" + [[package]] name = "ryu" version = "1.0.18" @@ -842,9 +852,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.72" +version = "2.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" dependencies = [ "proc-macro2", "quote", diff --git a/ext/commonmarker/Cargo.toml b/ext/commonmarker/Cargo.toml index a881e828..cd25542c 100644 --- a/ext/commonmarker/Cargo.toml +++ b/ext/commonmarker/Cargo.toml @@ -10,7 +10,7 @@ magnus = { version = "0.7", features = ["rb-sys"] } rb-sys = { version = "*", default-features = false, features = [ "stable-api-compiled-fallback", ] } -comrak = { version = "0.29", features = ["shortcodes"] } +comrak = { version = "0.30", features = ["shortcodes"] } syntect = { version = "5.2", features = ["plist-load"] } typed-arena = "2.0" rctree = "0.6" diff --git a/ext/commonmarker/src/lib.rs b/ext/commonmarker/src/lib.rs index f3ea977c..f0374eb4 100644 --- a/ext/commonmarker/src/lib.rs +++ b/ext/commonmarker/src/lib.rs @@ -76,7 +76,7 @@ fn commonmark_to_html(args: &[Value]) -> Result { )) } -fn format_options<'c>(rb_options: Option) -> Result, magnus::Error> { +fn format_options(rb_options: Option) -> Result { let mut comrak_options = ComrakOptions::default(); if let Some(rb_options) = rb_options { diff --git a/ext/commonmarker/src/node.rs b/ext/commonmarker/src/node.rs index ea6f0a43..fb644a8a 100644 --- a/ext/commonmarker/src/node.rs +++ b/ext/commonmarker/src/node.rs @@ -66,6 +66,7 @@ impl CommonmarkerNode { Option, Option, Option, + Option, ), (), >( @@ -78,11 +79,12 @@ impl CommonmarkerNode { "delimiter", "bullet_char", "tight", + "task_list", ], )?; let (list_type,) = kwargs.required; - let (marker_offset, padding, start, delimiter, bullet_char, tight) = + let (marker_offset, padding, start, delimiter, bullet_char, tight, task_list) = kwargs.optional; let commonmark_list_type = list_type.to_string(); @@ -121,6 +123,7 @@ impl CommonmarkerNode { // Whether the list is [tight](https://github.github.com/gfm/#tight), i.e. whether the // paragraphs are wrapped in `

` tags when formatted as HTML. tight: tight.unwrap_or(false), + is_task_list: task_list.unwrap_or(false), }) } "description_list" => ComrakNodeValue::DescriptionList, @@ -335,6 +338,7 @@ impl CommonmarkerNode { "strong" => ComrakNodeValue::Strong, "strikethrough" => ComrakNodeValue::Strikethrough, "superscript" => ComrakNodeValue::Superscript, + "subscript" => ComrakNodeValue::Subscript, "link" => { let kwargs = scan_args::get_kwargs::<_, (String,), (Option,), ()>( args.keywords, @@ -462,6 +466,7 @@ impl CommonmarkerNode { ComrakNodeValue::WikiLink(NodeWikiLink { url }) } + _ => panic!("unknown node type {}", node_type), }; @@ -550,6 +555,7 @@ impl CommonmarkerNode { ComrakNodeValue::Math(..) => Symbol::new("math"), ComrakNodeValue::WikiLink(..) => Symbol::new("wikilink"), ComrakNodeValue::Underline => Symbol::new("underline"), + ComrakNodeValue::Subscript => Symbol::new("subscript"), ComrakNodeValue::SpoileredText => Symbol::new("spoilered_text"), ComrakNodeValue::EscapedTag(_) => Symbol::new("escaped_tag"), } diff --git a/ext/commonmarker/src/options.rs b/ext/commonmarker/src/options.rs index 061fa639..7b274e49 100644 --- a/ext/commonmarker/src/options.rs +++ b/ext/commonmarker/src/options.rs @@ -116,6 +116,7 @@ const EXTENSION_WIKILINKS_TITLE_BEFORE_PIPE: &str = "wikilinks_title_before_pipe const EXTENSION_UNDERLINE: &str = "underline"; const EXTENSION_SPOILER: &str = "spoiler"; const EXTENSION_GREENTEXT: &str = "greentext"; +const EXTENSION_SUBSCRIPT: &str = "subscript"; fn iterate_extension_options(comrak_options: &mut ComrakOptions, options_hash: RHash) { options_hash @@ -185,6 +186,9 @@ fn iterate_extension_options(comrak_options: &mut ComrakOptions, options_hash: R Ok(Cow::Borrowed(EXTENSION_GREENTEXT)) => { comrak_options.extension.greentext = TryConvert::try_convert(value)?; } + Ok(Cow::Borrowed(EXTENSION_SUBSCRIPT)) => { + comrak_options.extension.subscript = TryConvert::try_convert(value)?; + } _ => {} } Ok(ForEach::Continue) diff --git a/lib/commonmarker/config.rb b/lib/commonmarker/config.rb index f419bb45..23e4b018 100644 --- a/lib/commonmarker/config.rb +++ b/lib/commonmarker/config.rb @@ -45,6 +45,7 @@ module Config underline: false, spoiler: false, greentext: false, + subscript: false, }.freeze, format: [:html].freeze, }.freeze diff --git a/test/extensions_test.rb b/test/extensions_test.rb index 8eab60ba..1eae6bcc 100644 --- a/test/extensions_test.rb +++ b/test/extensions_test.rb @@ -76,4 +76,20 @@ def test_can_disable_emoji_renders Commonmarker.to_html("Happy Friday! :smile:", options: options), ) end + + def test_subscript_disabled_by_default + assert_equal( + "

H2O

\n", + Commonmarker.to_html("~~H~2~O~~"), + ) + end + + def test_can_support_subscript + options = { extension: { subscript: true } } + + assert_equal( + "

H2O

\n", + Commonmarker.to_html("~~H~2~O~~", options: options), + ) + end end diff --git a/test/node_test.rb b/test/node_test.rb index 188637af..20368bc1 100644 --- a/test/node_test.rb +++ b/test/node_test.rb @@ -74,7 +74,7 @@ def test_can_render_back_to_commonmark assert(@document.first_child.first_child.replace(strikethrough_node)) - assert_match(/~bazinga~\*there\*/, @document.to_commonmark) + assert_match(/~~bazinga~~\*there\*/, @document.to_commonmark) end def test_last_child