Skip to content

Commit

Permalink
support new DL logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed Nov 26, 2024
1 parent 10dcda8 commit 7f30034
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
16 changes: 11 additions & 5 deletions ext/commonmarker/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,25 @@ impl CommonmarkerNode {
}
"description_list" => ComrakNodeValue::DescriptionList,
"description_item" => {
let kwargs = scan_args::get_kwargs::<_, (), (Option<usize>, Option<usize>), ()>(
args.keywords,
&[],
&["marker_offset", "padding"],
let kwargs = scan_args::get_kwargs::<
_,
(),
(Option<usize>, Option<usize>, Option<bool>),
(),
>(
args.keywords, &[], &["marker_offset", "padding", "tight"]
)?;

let (marker_offset, padding) = kwargs.optional;
let (marker_offset, padding, tight) = kwargs.optional;

ComrakNodeValue::DescriptionItem(NodeDescriptionItem {
// Number of spaces before the list marker.
marker_offset: marker_offset.unwrap_or(0),
// Number of characters between the start of the list marker and the item text (including the list marker(s)).
padding: padding.unwrap_or(0),
// 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),
})
}
"description_term" => ComrakNodeValue::DescriptionTerm,
Expand Down
8 changes: 3 additions & 5 deletions test/extensions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,18 @@ def test_comments_are_kept_as_expected

def test_definition_lists
markdown = <<~MARKDOWN
~strikethrough disabled to ensure options accepted~
Commonmark Definition
: Ruby wrapper for comrak (CommonMark parser)
MARKDOWN

extensions = { strikethrough: false, description_lists: true }
extensions = { description_lists: true }
options = { extension: extensions, render: { hardbreaks: false } }
output = Commonmarker.to_html(markdown, options: options)

html = <<~HTML
<p>~strikethrough disabled to ensure options accepted~</p>
<dl><dt>Commonmark Definition</dt>
<dl>
<dt>Commonmark Definition</dt>
<dd>
<p>Ruby wrapper for comrak (CommonMark parser)</p>
</dd>
Expand Down

0 comments on commit 7f30034

Please sign in to comment.