use std::fmt;
#[derive(Debug, Clone)]
pub enum BailReason {
Classifier,
DepthMismatch {
tag: String,
expected: u8,
actual: u8,
},
EofWithOpenBlock {
open_count: usize,
},
LiteralLt {
offset: usize,
},
Cdata {
offset: usize,
},
UnknownCustomElement {
name: Box<str>,
offset: usize,
},
TableRowspanColspan,
TableBlockChildInCell,
TableNestedTable,
TableCaption,
TableSectionOrder,
UnknownEntity {
name: Box<str>,
offset: usize,
},
}
impl fmt::Display for BailReason {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Classifier => write!(f, "classifier forced tier-2"),
Self::DepthMismatch {
tag,
expected,
actual,
} => {
write!(
f,
"depth mismatch for </{tag}>: expected {expected} open(s), got {actual}"
)
}
Self::EofWithOpenBlock { open_count } => {
write!(f, "EOF with {open_count} unclosed block element(s)")
}
Self::LiteralLt { offset } => {
write!(f, "literal '<' at byte offset {offset}")
}
Self::Cdata { offset } => {
write!(f, "CDATA section at byte offset {offset}")
}
Self::UnknownCustomElement { name, offset } => {
write!(f, "unknown custom element <{name}> at byte offset {offset}")
}
Self::TableRowspanColspan => {
write!(f, "table cell has rowspan or colspan != 1")
}
Self::TableBlockChildInCell => {
write!(f, "block-level element inside table cell")
}
Self::TableNestedTable => {
write!(f, "nested <table> inside a table cell")
}
Self::TableCaption => {
write!(f, "<caption> element in table")
}
Self::TableSectionOrder => {
write!(f, "table sections in unsupported order")
}
Self::UnknownEntity { name, offset } => {
write!(f, "unknown HTML entity &{name}; at byte offset {offset}")
}
}
}
}