Skip to content

Commit

Permalink
Update based on ytmimi's review
Browse files Browse the repository at this point in the history
  • Loading branch information
GKFX committed May 2, 2024
1 parent b0bda79 commit 4974262
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
10 changes: 7 additions & 3 deletions src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,17 +963,21 @@ fn trim_custom_comment_prefix(s: &str) -> String {

/// Returns `true` if the given string MAY include URLs or alike.
fn has_url(s: &str) -> bool {
// This function may return false positive, but should get its job done in most cases.
// The regex is indended to capture text such as the below.
// A regex matching reference doc links.
//
// ```markdown
// /// An [example].
// ///
// /// [example]: this::is::a::link
// ```
let reference_link_url = static_regex!(r"^\[.+\]\s?:");

// This function may return false positive, but should get its job done in most cases.
s.contains("https://")
|| s.contains("http://")
|| s.contains("ftp://")
|| s.contains("file://")
|| static_regex!(r"^\[.+\]\s?:").is_match(s)
|| reference_link_url.is_match(s)
}

/// Returns true if the given string may be part of a Markdown table.
Expand Down
17 changes: 9 additions & 8 deletions src/test/configuration_snippet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ impl ConfigurationSection {
fn get_section<I: Iterator<Item = String>>(
file: &mut Enumerate<I>,
) -> Option<ConfigurationSection> {
let config_name_regex = static_regex!(r"^## `([^`]+)`");
// Configuration values, which will be passed to `from_str`:
//
// - must be prefixed with `####`
// - must be wrapped in backticks
// - may by wrapped in double quotes (which will be stripped)
let config_value_regex = static_regex!(r#"^#### `"?([^`]+?)"?`"#);
loop {
match file.next() {
Some((i, line)) => {
Expand All @@ -40,15 +47,9 @@ impl ConfigurationSection {
let start_line = (i + 2) as u32;

return Some(ConfigurationSection::CodeBlock((block, start_line)));
} else if let Some(c) = static_regex!(r"^## `([^`]+)`").captures(&line) {
} else if let Some(c) = config_name_regex.captures(&line) {
return Some(ConfigurationSection::ConfigName(String::from(&c[1])));
} else if let Some(c) = static_regex!(r#"^#### `"?([^`]+?)"?`"#).captures(&line)
{
// Configuration values, which will be passed to `from_str`
//
// - must be prefixed with `####`
// - must be wrapped in backticks
// - may by wrapped in double quotes (which will be stripped)
} else if let Some(c) = config_value_regex.captures(&line) {
return Some(ConfigurationSection::ConfigValue(String::from(&c[1])));
}
}
Expand Down

0 comments on commit 4974262

Please sign in to comment.