From 2c229152cf07e921d1b30765bb90b7d73067c3ec Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Thu, 12 Sep 2024 20:29:09 +0100 Subject: [PATCH] Use separate property for tracking tasklists --- src/cm.rs | 4 ++-- src/html.rs | 13 +++++++------ src/nodes.rs | 6 +++--- src/parser/mod.rs | 6 ++++-- src/tests/api.rs | 1 - src/tests/tasklist.rs | 4 ++-- src/xml.rs | 6 +++--- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/cm.rs b/src/cm.rs index 4721f97c..fc15a1ad 100644 --- a/src/cm.rs +++ b/src/cm.rs @@ -462,7 +462,7 @@ impl<'a, 'o, 'c> CommonMarkFormatter<'a, 'o, 'c> { let mut listmarker = vec![]; - let marker_width = if matches!(parent.list_type, ListType::Bullet | ListType::Task) { + let marker_width = if parent.list_type == ListType::Bullet { 2 } else { let last_stack = self.ol_stack.last_mut().unwrap(); @@ -487,7 +487,7 @@ impl<'a, 'o, 'c> CommonMarkFormatter<'a, 'o, 'c> { }; if entering { - if matches!(parent.list_type, ListType::Bullet | ListType::Task) { + if parent.list_type == ListType::Bullet { let bullet = char::from(self.options.render.list_style as u8); write!(self, "{} ", bullet).unwrap(); } else { diff --git a/src/html.rs b/src/html.rs index 998de043..10a75d72 100644 --- a/src/html.rs +++ b/src/html.rs @@ -482,16 +482,17 @@ impl<'o, 'c: 'o> HtmlFormatter<'o, 'c> { match nl.list_type { ListType::Bullet => { self.output.write_all(b"\n")?; - } - ListType::Task => { - self.output.write_all(b"\n")?; } else { self.output.write_all(b"\n")?; diff --git a/src/nodes.rs b/src/nodes.rs index dde1fef3..2051badd 100644 --- a/src/nodes.rs +++ b/src/nodes.rs @@ -297,6 +297,9 @@ pub struct NodeList { /// Whether the list is [tight](https://github.github.com/gfm/#tight), i.e. whether the /// paragraphs are wrapped in `

` tags when formatted as HTML. pub tight: bool, + + /// Whether the list contains tasks (checkbox items) + pub is_task_list: bool, } /// The metadata of a description list @@ -318,9 +321,6 @@ pub enum ListType { /// An ordered list. Ordered, - - /// A task list i.e. a checkbox list. - Task, } /// The delimiter for ordered lists, i.e. the character which appears after each number. diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 4df54a9c..79f40d41 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -223,7 +223,7 @@ pub struct ExtensionOptions { /// options.extension.tasklist = true; /// options.render.unsafe_ = true; /// assert_eq!(markdown_to_html("* [x] Done\n* [ ] Not done\n", &options), - /// "

\n", "\n", - "\n", + "\n", "\n", "