Skip to content

Commit

Permalink
Merge pull request #1869 from Urgau/html-ignore
Browse files Browse the repository at this point in the history
Ignore inline HTML and HTML blocks
  • Loading branch information
ehuss authored Jan 6, 2025
2 parents 1f0165a + fdd2173 commit 9342f73
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 12 deletions.
13 changes: 10 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ authors = ["Mark Rousskov <[email protected]>"]
edition = "2021"

[dependencies]
pulldown-cmark = "0.7.0"
pulldown-cmark = "0.12.0"
log = "0.4"
regex = "1.6.0"
8 changes: 7 additions & 1 deletion parser/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,13 @@ fn review_errors() {
#[test]
fn review_ignored() {
// Checks for things that shouldn't be detected.
for input in ["r", "reviewer? abc", "r foo"] {
for input in [
"r",
"reviewer? abc",
"r foo",
"<a>\n r? @bot\n</a>",
"<!--\nr? foo\n-->",
] {
let mut input = Input::new(input, vec!["bot"]);
assert_eq!(input.next(), None);
}
Expand Down
57 changes: 50 additions & 7 deletions parser/src/ignore_block.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pulldown_cmark::{Event, Parser, Tag};
use pulldown_cmark::{Event, Parser, Tag, TagEnd};
use std::ops::Range;

#[derive(Debug)]
Expand All @@ -14,25 +14,35 @@ impl IgnoreBlocks {
if let Event::Start(Tag::CodeBlock(_)) = event {
let start = range.start;
while let Some((event, range)) = parser.next() {
if let Event::End(Tag::CodeBlock(_)) = event {
if let Event::End(TagEnd::CodeBlock) = event {
ignore.push(start..range.end);
break;
}
}
} else if let Event::Start(Tag::BlockQuote) = event {
} else if let Event::Start(Tag::BlockQuote(_)) = event {
let start = range.start;
let mut count = 1;
while let Some((event, range)) = parser.next() {
if let Event::Start(Tag::BlockQuote) = event {
if let Event::Start(Tag::BlockQuote(_)) = event {
count += 1;
} else if let Event::End(Tag::BlockQuote) = event {
} else if let Event::End(TagEnd::BlockQuote(_)) = event {
count -= 1;
if count == 0 {
ignore.push(start..range.end);
break;
}
}
}
} else if let Event::Start(Tag::HtmlBlock) = event {
let start = range.start;
while let Some((event, range)) = parser.next() {
if let Event::End(TagEnd::HtmlBlock) = event {
ignore.push(start..range.end);
break;
}
}
} else if let Event::InlineHtml(_) = event {
ignore.push(range);
} else if let Event::Code(_) = event {
ignore.push(range);
}
Expand Down Expand Up @@ -92,15 +102,27 @@ fn cbs_1() {
fn cbs_2() {
assert_eq!(
bodies("`hey you` <b>me too</b>"),
[Ignore::Yes("`hey you`"), Ignore::No(" <b>me too</b>")]
[
Ignore::Yes("`hey you`"),
Ignore::No(" "),
Ignore::Yes("<b>"),
Ignore::No("me too"),
Ignore::Yes("</b>")
]
);
}

#[test]
fn cbs_3() {
assert_eq!(
bodies(r"`hey you\` <b>`me too</b>"),
[Ignore::Yes(r"`hey you\`"), Ignore::No(" <b>`me too</b>")]
[
Ignore::Yes("`hey you\\`"),
Ignore::No(" "),
Ignore::Yes("<b>"),
Ignore::No("`me too"),
Ignore::Yes("</b>")
]
);
}

Expand Down Expand Up @@ -239,3 +261,24 @@ fn cbs_11() {
],
);
}

#[test]
fn cbs_12() {
assert_eq!(
bodies(
"
Test
<!-- Test -->
<!--
This is an HTML comment.
-->
"
),
[
Ignore::No("\nTest\n\n"),
Ignore::Yes("<!-- Test -->\n"),
Ignore::Yes("<!--\nThis is an HTML comment.\n-->\n")
],
);
}

0 comments on commit 9342f73

Please sign in to comment.