rustdoc: align invalid-html-tags lint with commonmark spec

This commit is contained in:
Michael Howell 2022-07-28 13:12:32 -07:00
parent e5682615bb
commit f5cd6b3e9b
3 changed files with 28 additions and 2 deletions

View File

@ -94,6 +94,14 @@ fn extract_path_backwards(text: &str, end_pos: usize) -> Option<usize> {
if current_pos == end_pos { None } else { Some(current_pos) }
}
fn is_valid_for_html_tag_name(c: char, is_empty: bool) -> bool {
// https://spec.commonmark.org/0.30/#raw-html
//
// > A tag name consists of an ASCII letter followed by zero or more ASCII letters, digits, or
// > hyphens (-).
c.is_ascii_alphabetic() || (c.is_ascii_digit() && !is_empty) || (c == '-' && !is_empty)
}
fn extract_html_tag(
tags: &mut Vec<(String, Range<usize>)>,
text: &str,
@ -117,7 +125,7 @@ fn extract_html_tag(
// Checking if this is a closing tag (like `</a>` for `<a>`).
if c == '/' && tag_name.is_empty() {
is_closing = true;
} else if c.is_ascii_alphanumeric() {
} else if is_valid_for_html_tag_name(c, tag_name.is_empty()) {
tag_name.push(c);
} else {
if !tag_name.is_empty() {

View File

@ -108,3 +108,9 @@ pub fn j() {}
/// <Vec<_> shouldn't warn!
/// ``````
pub fn k() {}
/// Web Components style <dashed-tags>
//~^ ERROR unclosed HTML tag `dashed-tags`
/// Web Components style </unopened-tag>
//~^ ERROR unopened HTML tag `unopened-tag`
pub fn m() {}

View File

@ -82,5 +82,17 @@ error: Unclosed HTML comment
LL | /// <!--
| ^^^
error: aborting due to 13 previous errors
error: unopened HTML tag `unopened-tag`
--> $DIR/invalid-html-tags.rs:114:26
|
LL | /// Web Components style </unopened-tag>
| ^^^^^^^^^^^^^^^
error: unclosed HTML tag `dashed-tags`
--> $DIR/invalid-html-tags.rs:112:26
|
LL | /// Web Components style <dashed-tags>
| ^^^^^^^^^^^^^
error: aborting due to 15 previous errors