Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump comrak from 0.29.0 to 0.30.0 #321

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 48 additions & 38 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion ext/commonmarker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion ext/commonmarker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn commonmark_to_html(args: &[Value]) -> Result<String, magnus::Error> {
))
}

fn format_options<'c>(rb_options: Option<RHash>) -> Result<comrak::Options<'c>, magnus::Error> {
fn format_options(rb_options: Option<RHash>) -> Result<comrak::Options, magnus::Error> {
let mut comrak_options = ComrakOptions::default();

if let Some(rb_options) = rb_options {
Expand Down
8 changes: 7 additions & 1 deletion ext/commonmarker/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl CommonmarkerNode {
Option<String>,
Option<u8>,
Option<bool>,
Option<bool>,
),
(),
>(
Expand All @@ -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();
Expand Down Expand Up @@ -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 `<p>` tags when formatted as HTML.
tight: tight.unwrap_or(false),
is_task_list: task_list.unwrap_or(false),
})
}
"description_list" => ComrakNodeValue::DescriptionList,
Expand Down Expand Up @@ -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<String>,), ()>(
args.keywords,
Expand Down Expand Up @@ -462,6 +466,7 @@ impl CommonmarkerNode {

ComrakNodeValue::WikiLink(NodeWikiLink { url })
}

_ => panic!("unknown node type {}", node_type),
};

Expand Down Expand Up @@ -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"),
}
Expand Down
4 changes: 4 additions & 0 deletions ext/commonmarker/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/commonmarker/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module Config
underline: false,
spoiler: false,
greentext: false,
subscript: false,
}.freeze,
format: [:html].freeze,
}.freeze
Expand Down
16 changes: 16 additions & 0 deletions test/extensions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"<p><del>H<del>2</del>O</del></p>\n",
Commonmarker.to_html("~~H~2~O~~"),
)
end

def test_can_support_subscript
options = { extension: { subscript: true } }

assert_equal(
"<p><del>H<sub>2</sub>O</del></p>\n",
Commonmarker.to_html("~~H~2~O~~", options: options),
)
end
end
2 changes: 1 addition & 1 deletion test/node_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading