block: enforce valid div classes

This commit is contained in:
Noah Hellman 2023-01-31 21:23:50 +01:00
parent 30351500bb
commit 6a94e694f9
2 changed files with 8 additions and 4 deletions

View file

@ -262,11 +262,11 @@ impl<I: Iterator<Item = char>> Parser<I> {
}
}
fn is_name_start(c: char) -> bool {
pub fn is_name_start(c: char) -> bool {
c.is_ascii_alphanumeric() || matches!(c, '_' | ':')
}
fn is_name(c: char) -> bool {
pub fn is_name(c: char) -> bool {
is_name_start(c) || c.is_ascii_digit() || matches!(c, '-')
}

View file

@ -654,8 +654,12 @@ impl IdentifiedBlock {
f @ ('`' | ':' | '~') => {
let fence_length = 1 + (&mut chars).take_while(|c| *c == f).count();
let spec = &line_t[fence_length..].trim_start();
let valid_spec =
!spec.chars().any(char::is_whitespace) && !spec.chars().any(|c| c == '`');
let valid_spec = if f == ':' && !spec.starts_with('=') {
spec.chars().next().map_or(true, attr::is_name_start)
&& spec.chars().skip(1).all(attr::is_name)
} else {
!spec.chars().any(char::is_whitespace) && !spec.chars().any(|c| c == '`')
};
let skip = line_t.len() - spec.len();
(valid_spec && fence_length >= 3).then(|| {
(