Skip to content

Commit 59e2ef5

Browse files
committed
relaxed_tasklist_matching: suggested fix
1 parent a5efb05 commit 59e2ef5

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

src/parser/mod.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,24 +1652,18 @@ impl<'a, 'o, 'c> Parser<'a, 'o, 'c> {
16521652
}
16531653

16541654
fn process_tasklist(&mut self, node: &'a AstNode<'a>, text: &mut Vec<u8>) {
1655-
let relaxed_tasklist_matching = self.options.parse.relaxed_tasklist_matching;
16561655
static TASKLIST: OnceCell<Regex> = OnceCell::new();
1657-
let r = TASKLIST.get_or_init(|| {
1658-
if relaxed_tasklist_matching {
1659-
Regex::new(r"\A(\s*\[(.)\])(?:\z|\s)").unwrap()
1660-
} else {
1661-
Regex::new(r"\A(\s*\[([xX\s])\])(?:\z|\s)").unwrap()
1662-
}
1663-
});
1656+
let r = TASKLIST.get_or_init(|| Regex::new(r"\A(\s*\[(.)\])(?:\z|\s)").unwrap());
16641657

16651658
let (symbol, end) = match r.captures(text) {
16661659
None => return,
1667-
Some(c) => (
1668-
c.get(2).unwrap().as_bytes().to_owned(),
1669-
c.get(0).unwrap().end(),
1670-
),
1660+
Some(c) => (c.get(2).unwrap().as_bytes()[0], c.get(0).unwrap().end()),
16711661
};
16721662

1663+
if !self.options.parse.relaxed_tasklist_matching && !matches!(symbol, b' ' | b'x' | b'X') {
1664+
return;
1665+
}
1666+
16731667
let parent = node.parent().unwrap();
16741668
if node.previous_sibling().is_some() || parent.previous_sibling().is_some() {
16751669
return;
@@ -1689,8 +1683,8 @@ impl<'a, 'o, 'c> Parser<'a, 'o, 'c> {
16891683
let checkbox = inlines::make_inline(
16901684
self.arena,
16911685
NodeValue::TaskItem {
1692-
checked: symbol != b" ",
1693-
symbol: symbol[0],
1686+
checked: symbol != b' ',
1687+
symbol: symbol,
16941688
},
16951689
);
16961690
node.insert_before(checkbox);

src/tests.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,11 @@ fn tagfilter() {
759759
#[test]
760760
fn tasklist() {
761761
html_opts!(
762-
[render.unsafe_, extension.tasklist],
762+
[
763+
render.unsafe_,
764+
extension.tasklist,
765+
parse.relaxed_tasklist_matching
766+
],
763767
concat!(
764768
"* [ ] Red\n",
765769
"* [x] Green\n",

0 commit comments

Comments
 (0)