use crate::diagnostic::Diagnostic;
use crate::rule::LintRule;
use mdwright_document::Document;
use mdwright_document::MathError;
pub struct MathUnbalancedBraces;
impl LintRule for MathUnbalancedBraces {
fn name(&self) -> &str {
"math/unbalanced-braces"
}
fn description(&self) -> &str {
"`{` / `}` inside a math body do not balance; math body normalisation is skipped for that region."
}
fn explain(&self) -> &str {
include_str!("explain/math__unbalanced_braces.md")
}
fn check(&self, doc: &Document, out: &mut Vec<Diagnostic>) {
for err in doc.math_errors() {
let MathError::UnbalancedBraces { offset, region } = err else {
continue;
};
let span = (*offset)..offset.saturating_add(1).min(region.end);
let message = "unbalanced `{` / `}` inside math body — math body normalisation is skipped";
if let Some(d) = Diagnostic::at(doc, 0, span, message.to_owned(), None) {
out.push(d);
}
}
}
}