use serde::Serialize;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
pub struct Position {
pub line: u32,
pub column: u32,
}
impl Position {
pub fn from_span(span: &nom_locate::LocatedSpan<&str>) -> Self {
Self {
line: span.location_line(),
column: span.get_column() as u32,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct Location {
pub start: Position,
pub end: Position,
}
pub const VOID_ELEMENTS: &[&str] = &[
"area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "source", "track",
"wbr",
];
pub const RAW_TEXT_ELEMENTS: &[&str] = &["script", "style"];
pub const RCDATA_ELEMENTS: &[&str] = &["textarea", "title"];
pub fn is_void_element(tag: &str) -> bool {
let lower = tag.to_ascii_lowercase();
VOID_ELEMENTS.contains(&lower.as_str())
}
pub fn is_raw_text_element(tag: &str) -> bool {
let lower = tag.to_ascii_lowercase();
RAW_TEXT_ELEMENTS.contains(&lower.as_str())
}
pub fn is_rcdata_element(tag: &str) -> bool {
let lower = tag.to_ascii_lowercase();
RCDATA_ELEMENTS.contains(&lower.as_str())
}
impl Location {
pub fn from_spans(
start: &nom_locate::LocatedSpan<&str>,
end: &nom_locate::LocatedSpan<&str>,
) -> Self {
Self {
start: Position::from_span(start),
end: Position::from_span(end),
}
}
pub fn is_valid(&self) -> bool {
self.start.line > 0 && self.start.column > 0
}
}