microdata

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

Documentation

Overview

Command microdata extracts HTML microdata into a flat key-value report.

microdata page.html
1 Product
  Product.name = Widget
  Product.offers.price = 9.99
  Product.offers.priceCurrency = GBP

It changes nothing: the document goes to standard output byte for byte and the report to standard error.

Microdata is a tree - an itemprop belongs to the nearest enclosing itemscope, and an itemprop can itself open a new scope - and a rewriter has no tree. The shape is recovered with a stack, and the stack has to be of open *elements* rather than of open scopes, because the question is where an element ended and an end-tag callback does not answer it. HTML lets an element be closed by the next start tag - <p itemprop=a>x<p itemprop=b>y is two properties - and there is no end tag for the first one: its callback runs at the enclosing element's end tag instead, by which time the second property's text has already gone by. Popping there gave "a" the value "xy" and made every following property a child of a scope that had closed.

So this keeps every open element and applies the specification's implied end tags on each start tag, the way examples/gip/markdown and examples/gip/depth do, and closes a scope or a property when its element leaves that stack. That costs an end-tag registration per element, which is the price of being exact about where content ends; a program that only needs positions can register far fewer. An element that cannot have content, such as the <meta itemprop content> that most microdata is written with, is never pushed: it has no end tag to pop it, and the stack would never come back down.

One thing this program has to decide that a rewriting program does not. An element can carry the same attribute twice, and the API is split about it: selectors, Attribute and SetAttribute act on the first copy, while iterating the attributes yields every copy. A parser drops all but the first, so the first is what a browser acts on, and this program follows that - which means reading through Attribute rather than through the iterator, even where the iterator would be more convenient.

Jump to

Keyboard shortcuts

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