diff --git a/src/comment.rs b/src/comment.rs index 6908d022082..697af8c1cb8 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -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. diff --git a/src/test/configuration_snippet.rs b/src/test/configuration_snippet.rs index 76957f33fb7..e4a390ada66 100644 --- a/src/test/configuration_snippet.rs +++ b/src/test/configuration_snippet.rs @@ -24,6 +24,13 @@ impl ConfigurationSection { fn get_section>( file: &mut Enumerate, ) -> Option { + 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)) => { @@ -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]))); } }