Skip to content

Commit ba16045

Browse files
committed
Update based on ytmimi's review
1 parent b0bda79 commit ba16045

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

Diff for: src/comment.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -963,17 +963,21 @@ fn trim_custom_comment_prefix(s: &str) -> String {
963963

964964
/// Returns `true` if the given string MAY include URLs or alike.
965965
fn has_url(s: &str) -> bool {
966-
// This function may return false positive, but should get its job done in most cases.
967-
// The regex is indended to capture text such as the below.
966+
// A regex matching reference doc links.
968967
//
968+
// ```markdown
969969
// /// An [example].
970970
// ///
971971
// /// [example]: this::is::a::link
972+
// ```
973+
let reference_link_url = static_regex!(r"^\[.+\]\s?:");
974+
975+
// This function may return false positive, but should get its job done in most cases.
972976
s.contains("https://")
973977
|| s.contains("http://")
974978
|| s.contains("ftp://")
975979
|| s.contains("file://")
976-
|| static_regex!(r"^\[.+\]\s?:").is_match(s)
980+
|| reference_link_url.is_match(s)
977981
}
978982

979983
/// Returns true if the given string may be part of a Markdown table.

Diff for: src/test/configuration_snippet.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ impl ConfigurationSection {
2424
fn get_section<I: Iterator<Item = String>>(
2525
file: &mut Enumerate<I>,
2626
) -> Option<ConfigurationSection> {
27+
let config_name_regex = static_regex!(r"^## `([^`]+)`");
28+
// Configuration values, which will be passed to `from_str`:
29+
//
30+
// - must be prefixed with `####`
31+
// - must be wrapped in backticks
32+
// - may by wrapped in double quotes (which will be stripped)
33+
let config_value_regex = static_regex!(r#"^#### `"?([^`]+?)"?`"#);
2734
loop {
2835
match file.next() {
2936
Some((i, line)) => {
@@ -40,15 +47,9 @@ impl ConfigurationSection {
4047
let start_line = (i + 2) as u32;
4148

4249
return Some(ConfigurationSection::CodeBlock((block, start_line)));
43-
} else if let Some(c) = static_regex!(r"^## `([^`]+)`").captures(&line) {
50+
} else if let Some(c) = config_name_regex.captures(&line) {
4451
return Some(ConfigurationSection::ConfigName(String::from(&c[1])));
45-
} else if let Some(c) = static_regex!(r#"^#### `"?([^`]+?)"?`"#).captures(&line)
46-
{
47-
// Configuration values, which will be passed to `from_str`
48-
//
49-
// - must be prefixed with `####`
50-
// - must be wrapped in backticks
51-
// - may by wrapped in double quotes (which will be stripped)
52+
} else if let Some(c) = config_value_regex.captures(&line) {
5253
return Some(ConfigurationSection::ConfigValue(String::from(&c[1])));
5354
}
5455
}

0 commit comments

Comments
 (0)