Structured data¶
Document.structured_data() pulls every machine-readable metadata format a page embeds in one walk, with the
per-format helpers Document.json_ld(), Document.opengraph(), Document.microdata(),
Document.rdfa(), and Document.dublin_core() beside it. The walk runs in the C core; the typed, read-only
result records below are handed back from it.
- class turbohtml.StructuredData(json_ld, microdata, opengraph, microformats, rdfa, dublin_core)¶
Every machine-readable metadata format a document embeds, the combined result of one walk.
- Parameters:
json_ld (
list[bool|int|float|str|list[bool|int|float|str|list[JSONValue] |dict[str, JSONValue] |None] |dict[str,bool|int|float|str|list[JSONValue] |dict[str, JSONValue] |None] |None]) – each<script type="application/ld+json">block decoded withjson.microdata (
list[MicrodataItem]) – every top-levelMicrodataItem.opengraph (
dict[str,str]) – eachog:/twitter:<meta>key mapped to its content.microformats (
list[bool|int|float|str|list[bool|int|float|str|list[JSONValue] |dict[str, JSONValue] |None] |dict[str,bool|int|float|str|list[JSONValue] |dict[str, JSONValue] |None] |None]) – reserved for a later phase, an empty list for now.dublin_core (
dict[str,str]) – eachdc.*/dcterms.*<meta>name (lower-cased) mapped to its content.
- json_ld: list[bool | int | float | str | list[bool | int | float | str | list[JSONValue] | dict[str, JSONValue] | None] | dict[str, bool | int | float | str | list[JSONValue] | dict[str, JSONValue] | None] | None]¶
each
<script type="application/ld+json">block decoded withjson.
- microdata: list[MicrodataItem]¶
every top-level
MicrodataItem.
- class turbohtml.MicrodataItem(type, id, properties)¶
One HTML Microdata item: an element carrying
itemscopeand the properties beneath it.- Parameters:
type (
str|None) – theitemtypeattribute verbatim, orNonewhen the element has none.id (
str|None) – theitemidattribute verbatim, orNonewhen the element has none.properties (
dict[str,list[str|MicrodataItem]]) – eachitempropname mapped to its values in document order, a value being the property’s text/URL as astror a nestedMicrodataItemfor a property that is itself anitemscope.
- properties: dict[str, list[str | MicrodataItem]]¶
each
itempropname mapped to its values in document order.
- get(name)¶
Return the property’s first value, or
Nonewhen the item lacks it (microdata.Item.get).- Parameters:
name (
str)- Return type:
str|MicrodataItem|None
- get_all(name)¶
Return the property’s values in document order, an empty list when absent (
microdata.Item.get_all).- Parameters:
name (
str)- Return type:
list[str|MicrodataItem]
- class turbohtml.RdfaItem(vocab, type, resource, properties)¶
One RDFa resource: an element carrying
typeofand thepropertyvalues beneath it.Mirrors
MicrodataItemwith the RDFa vocabulary context added.propertykeys and thetypeIRIs are expanded against the in-scope@vocaband@prefixmappings (the RDFa 1.1 initial context seeds the common prefixes, soschema:,dc:,foaf:resolve without a page-level declaration); a token whose prefix is undeclared, or a bare term with no@vocabin scope, is kept verbatim.- Parameters:
vocab (
str|None) – the in-scope@vocabIRI, orNonewhen no vocabulary is set.type (
list[str]) – the expanded@typeofIRIs in document order, an empty list for a valuelesstypeof.resource (
str|None) – the resource subject (@about/@resource/@href/@src), orNonefor a blank node.properties (
dict[str,list[str|RdfaItem]]) – each expandedpropertyIRI mapped to its values in document order, a value being a literal or IRIstror a nestedRdfaItemfor a property that is itself atypeof.
- properties: dict[str, list[str | RdfaItem]]¶
each expanded
propertyIRI mapped to its values in document order.
- get(name)¶
Return the property’s first value, or
Nonewhen the item lacks it.