Skip to main content

shallow

Function shallow 

Source
fn shallow(html: &str) -> Cow<'_, str>
Expand description

The HTML with no element deeper than DEEPEST, in one pass. The parser under ammonia looks through the elements still open at most tags, so elements nested by the thousand cost it the square of their number (32,000 empty blocks in one another: 3 seconds; a megabyte of them, minutes). This follows the elements the parser keeps open without ever counting one closed before the parser closes it: an element closes on its own end tag when it is the innermost, or when the parser surely closes it then (closed_on_the_way, closed_before). Sloppy mail at worst seems deeper than it is; the parser, which also opens elements of its own (a table’s body and row), never holds more than a few times what is counted. A start tag past the depth is left out, a space in its place, so that no word runs into the next and no “<” before it starts a tag; its words stay.