decomment

command
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Command decomment strips comments from a document without stripping the things that only look like comments.

decomment < page.html > out.html
decomment -keep-conditional=false -report < page.html

An HTML parser calls several malformed constructs comments, and a handler sees them all. <?php echo $x; ?> is a comment. So is <?xml version="1.0"?>, and so is <!doctype-ish junk>. A rewrite that removes every comment removes those too, silently, because each of them is a perfectly well-formed comment as far as the parser is concerned.

So this keeps, by default:

  • processing instructions and template blocks, recognised by their text beginning with "?", the character that opened them
  • every other bogus comment, which cannot be recognised from the comment at all: "<!x>" and "<!--x-->" both have the text "x". The source range is the only discriminator, which is why this buffers the input rather than streaming it - a real comment starts with "<!--" and a bogus one does not
  • conditional comments, both halves: the downlevel-revealed form is two comments with real markup between them, and only the first contains "[if", so a filter keyed on that keeps the opening half and drops the closing one
  • anything matching -keep, for the comments a build system reads

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL