Skip to content

Commit 919b375

Browse files
committed
Ignore elements in markdown links
We do not want to process things inside links, as this is causing some false positives. GitHub seems to also ignore these.
1 parent 7e55cd5 commit 919b375

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

parser/src/ignore_block.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ impl IgnoreBlocks {
2727
Event::Start(Tag::CodeBlock(_)) => {
2828
ignore_till_end!(TagEnd::CodeBlock);
2929
}
30+
Event::Start(Tag::Link { .. }) => {
31+
ignore_till_end!(TagEnd::Link { .. });
32+
}
33+
Event::Start(Tag::Image { .. }) => {
34+
ignore_till_end!(TagEnd::Image { .. });
35+
}
3036
Event::Start(Tag::BlockQuote(_)) => {
3137
let start = range.start;
3238
let mut count = 1;
@@ -324,11 +330,22 @@ fn cbs_13() {
324330

325331
#[test]
326332
fn ignore_link() {
327-
assert_eq!(bodies("[This is a link](https://example.com)"), []);
328-
assert_eq!(bodies("![This is an image](foo.png)"), []);
333+
assert_eq!(
334+
bodies("[This is a link](https://example.com)"),
335+
[Ignore::Yes("[This is a link](https://example.com)")]
336+
);
337+
assert_eq!(
338+
bodies("![This is an image](foo.png)"),
339+
[Ignore::Yes("![This is an image](foo.png)")]
340+
);
329341

342+
// Unfortunately pulldown_cmark does not give ranges for the link
343+
// definition.
330344
assert_eq!(
331345
bodies("[Link from def]\n\n[Link from def]: https://example.com"),
332-
[]
346+
[
347+
Ignore::Yes("[Link from def]"),
348+
Ignore::No("\n\n[Link from def]: https://example.com")
349+
]
333350
);
334351
}

0 commit comments

Comments
 (0)