TagBalance
Whether every element that was opened was closed, read from the source.
By the time a parser hands back a tree the question cannot be asked: an unclosed `
` has already been closed for you. Jsoup does notice, but it reports the symptom — "Unexpected EndTag []" — rather than the cause, which leaves you counting tags by hand. This reads the markup as written and names the element and the line it was opened on.
It reads the source as the tokenizer of the HTML Living Standard, as of November 2026, reads it. Comments, doctypes, processing instructions, CDATA in SVG and MathML, quoted attribute values and the elements whose content is text, such as a script, a style or a textarea, open nothing. It departs from the standard twice. A quoted value that never closes ends its tag at the tag's first >, so the element is still reported rather than the rest of the page vanishing into the value. And a noscript is read as markup, as a browser with scripting off reads it.
It nests elements by their tags, knowing what HTML lets you leave out: void elements, the optional end tags, a paragraph ended by the start of a block (though not left open at the end of a link, a media element, an edit, a map, a noscript, a custom element or an SVG or MathML parent), and a slash closing only an SVG or MathML element. These are HTML's rules, so an SVG or MathML element of the same name keeps its own. It puts each element in the namespace a parser would: SVG and MathML, and HTML again at their integration points.
It does not repeat a parser's error recovery, such as breaking out of SVG, closing by scope, the adoption agency or foster parenting: it also reads template fragments with no page around them, and its job is to name the mistake in the source, not the tree a browser repairs it into.
Attributes
- Source
- TagBalance.scala
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
TagBalance.type