Skip to content

Commit c0c76d1

Browse files
Adds tasklist_classes to the list of render options.
1 parent 8bb753a commit c0c76d1

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ Note that there is a distinction in comrak for "parse" options and "render" opti
179179
| `ignore_empty_links` | Ignores empty links, leaving the Markdown text in place. | `false` |
180180
| `gfm_quirks` | Outputs HTML with GFM-style quirks; namely, not nesting `<strong>` inlines. | `false` |
181181
| `prefer_fenced` | Always output fenced code blocks, even where an indented one could be used. | `false` |
182+
| `tasklist_classes` | Add CSS classes to the HTML output of the tasklist extension | `false` |
182183

183184
As well, there are several extensions which you can toggle in the same manner:
184185

ext/commonmarker/src/options.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const RENDER_IGNORE_SETEXT: &str = "ignore_setext";
4949
const RENDER_IGNORE_EMPTY_LINKS: &str = "ignore_empty_links";
5050
const RENDER_GFM_QUIRKS: &str = "gfm_quirks";
5151
const RENDER_PREFER_FENCED: &str = "prefer_fenced";
52+
const RENDER_TASKLIST_CLASSES: &str = "tasklist_classes";
5253

5354
fn iterate_render_options(comrak_options: &mut ComrakOptions, options_hash: RHash) {
5455
options_hash
@@ -90,6 +91,9 @@ fn iterate_render_options(comrak_options: &mut ComrakOptions, options_hash: RHas
9091
Ok(Cow::Borrowed(RENDER_PREFER_FENCED)) => {
9192
comrak_options.render.prefer_fenced = TryConvert::try_convert(value)?;
9293
}
94+
Ok(Cow::Borrowed(RENDER_TASKLIST_CLASSES)) => {
95+
comrak_options.render.tasklist_classes = TryConvert::try_convert(value)?;
96+
}
9397
_ => {}
9498
}
9599
Ok(ForEach::Continue)

lib/commonmarker/config.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module Config
2424
ignore_empty_links: false,
2525
gfm_quirks: false,
2626
prefer_fenced: false,
27+
tasklist_classes: false,
2728
}.freeze,
2829
extension: {
2930
strikethrough: true,

test/tasklists_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,20 @@ def test_to_html
1818

1919
assert_equal(expected, html)
2020
end
21+
22+
def test_to_html_with_tasklist_classes
23+
text = <<-MD
24+
- [x] Add task list
25+
- [ ] Define task list
26+
MD
27+
html = Commonmarker.to_html(text, options: { extension: { tasklist: true }, render: { tasklist_classes: true } })
28+
expected = <<~HTML
29+
<ul class="contains-task-list">
30+
<li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox" checked="" disabled="" /> Add task list</li>
31+
<li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox" disabled="" /> Define task list</li>
32+
</ul>
33+
HTML
34+
35+
assert_equal(expected, html)
36+
end
2137
end

0 commit comments

Comments
 (0)