Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Strict HTML validation in Rust: How to detect unclosed tags and unresolved placeholders?
Strict HTML validation in Rust: How to detect unclosed tags and unresolved placeholders?
โ rust ๐ 2025-06-09 ๐ค surdeus ๐๏ธ 2I'm working on a Rust project that involves validating HTML contentโboth full documents and fragments. My requirements go beyond lenient parsing:
{{field}}
, {{ user.name }}
, or malformed ones like {{{bad}}}
, {{ incomplete
Crates like html5ever
and markup5ever_rcdom
follow the forgiving HTML5 spec and parse even broken HTML successfully. This makes it impossible to detect structural issues at runtime.
For example, this invalid HTML:
<div class="row template-row">
<div class="col-auto">
<a> <!-- โ Unclosed <a> tag -->
</div>
</div>
The above is invalid HTML, yet parsers like html5ever auto-close the <a>
tag, and the document is considered "valid" at the parsing level.
This becomes a problem in scenarios like Angular templates, where unclosed tags can cause runtime or build-time errors. Structural correctness matters more than "valid per HTML5 spec."
I'm searching for a Rust-based approach that supports the following validation features:
<div><a></div>
or <div><span>
should throw an error{{field}}
, {{
, {{{bad}}}
html5ever
to operate in a strict mode or report unclosed tags?tidy
from Rust be the most pragmatic solution?1 post - 1 participant
๐ท๏ธ rust_feed