Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore inline HTML and HTML blocks #1869

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
],
);
}
Loading