histogram

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: 7 Imported by: 0

Documentation

Overview

Command histogram counts the elements in a document by tag name and prints them as a bar chart.

Counting is the simplest thing a rewriter can do, which makes the two questions it raises the whole of the program.

What is a tag name? TagName is lower-cased, which is what a count wants: a page that writes <DIV> and <div> has one kind of element and should have one row. TagNamePreserveCase is the source spelling, which matters for foreign content, where <linearGradient> is a different element from <lineargradient> to everything except an HTML parser. The histogram keys on the lower-case name and records the spellings, so a page that is inconsistent shows it rather than having it averaged away.

And what is the same element? Selectors here do not consider namespaces, so "a" matches both an HTML link and an SVG <a>. They are different elements with the same name, and adding their counts together produces a number that is not about anything.

NamespaceURI does not answer that question by itself, and the way it does not is worth knowing. It reports the namespace an element's *children* are parsed in, which is the element's own namespace everywhere except the integration points - <svg><title>, <math><mi> and the rest - where foreign content switches back to HTML. Asking <mi> for its namespace gives HTML.

But it is exactly the right answer one level up. An element's own namespace is the namespace its parent's children are parsed in, so the program keeps a stack of NamespaceURI values and reads the top. That is the documented meaning used as it is rather than worked around, and it puts <math><mi> in MathML and an HTML <p> inside <svg><foreignObject> back in HTML.

Jump to

Keyboard shortcuts

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