Skip to content

Commit a598a55

Browse files
authored
Fix GitHub-flavored markdown task list checkboxes being detected as links (#121)
1 parent b566174 commit a598a55

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/link_extractors/markdown_link_extractor.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ impl LinkExtractor for MarkdownLinkExtractor {
3939
None
4040
};
4141

42-
let parser = Parser::new_with_broken_link_callback(text, Options::empty(), Some(callback));
42+
let parser =
43+
Parser::new_with_broken_link_callback(text, Options::ENABLE_TASKLISTS, Some(callback));
4344

4445
for (evt, range) in parser.into_offset_iter() {
4546
match evt {
@@ -493,4 +494,27 @@ mod tests {
493494
assert_eq!(result[0].as_ref().unwrap().target, "http://a.com/");
494495
assert_eq!(result[1].as_ref().unwrap().target, "http://c.com/");
495496
}
497+
498+
#[test]
499+
fn gfm_checkbox_not_link() {
500+
let le = MarkdownLinkExtractor();
501+
let input = "- [x] checked task\n- [ ] unchecked task";
502+
let result = le.find_links(input);
503+
// GitHub-flavored markdown task list checkboxes should NOT be treated as links
504+
assert!(
505+
result.is_empty(),
506+
"Task list checkboxes should not be detected as links: {:?}",
507+
result
508+
);
509+
}
510+
511+
#[test]
512+
fn gfm_checkbox_with_link() {
513+
let le = MarkdownLinkExtractor();
514+
let input = "- [x] [actual link](http://example.com/)\n- [ ] unchecked task";
515+
let result = le.find_links(input);
516+
// Only the actual link should be detected, not the checkboxes
517+
assert_eq!(1, result.len());
518+
assert_eq!(result[0].as_ref().unwrap().target, "http://example.com/");
519+
}
496520
}

0 commit comments

Comments
 (0)