Documentation
¶
Overview ¶
Command descript removes script elements and reports what that saved.
descript < page.html > out.html descript -inline-only -report < page.html
Reporting the saving is most of the work, because an element's own SourceLocation is its start tag and nothing else. The extent of an element is the start of its start tag to the end of its end tag, which means holding the start location until the end tag arrives - and an element whose end tag never comes has no measurable extent at all, which is reported rather than guessed.
OnEndTag returns an error for an element that cannot have content, rather than doing nothing, and that error fails the rewrite after a prefix of the document has already been written. A script is never void, but that is not enough: in SVG and MathML a trailing slash really does close an element, so <svg><script/> is a script that cannot have content and has no end tag to wait for. Hence the lolhtml.Element.CanHaveContent guard below, which is needed by any selector that can reach foreign content - which "script" does. A self-closing script has no extent to hold open either: its start tag is the whole element, so the saving is measured on the spot.