1 | import { Node, Types } from '../types';
|
2 | /**
|
3 | * Get the URL used in Microdata attributes.
|
4 | *
|
5 | * This is used to normalize the versioned URL from the
|
6 | * JSON-LD context.
|
7 | */
|
8 | export declare function microdataUrl(type?: string): string;
|
9 | /**
|
10 | * Attributes for Microdata ["items"](https://www.w3.org/TR/microdata/#items)
|
11 | *
|
12 | * "The itemtype attribute must not be specified on elements that do not have
|
13 | * an itemscope attribute specified."
|
14 | */
|
15 | export interface MicrodataItem {
|
16 | itemscope?: '';
|
17 | itemtype?: string;
|
18 | itemid?: string;
|
19 | }
|
20 | /**
|
21 | * Create `MicrodataItem` attributes for a node.
|
22 | *
|
23 | * Does not create the `itemscope` and `itemtype` attributes for nodes that
|
24 | * are primitive (and therefore which do not represent a "scope" having
|
25 | * `itemprop`s nested within it). Instead, for primitive nodes, other than `Text`
|
26 | * add the `itemtype` attribute, do they can be styled if so desired.
|
27 | *
|
28 | * @param node The node to create Microdata attributes for
|
29 | * @param id Id of the Microdata item. Used to link to this node using the `itemref` property.
|
30 | */
|
31 | export declare function microdataItem(node: Node, id?: string): MicrodataItem;
|
32 | /**
|
33 | * Get the HTML Microdata `itemtype` for a Stencila Schema type
|
34 | *
|
35 | * @see {@link https://www.w3.org/TR/microdata/#dfn-itemtype}
|
36 | */
|
37 | export declare function microdataItemtype(type: keyof Types): string | undefined;
|
38 | /**
|
39 | * Get the Stencila Schema type from a HTML Microdata `itemtype`.
|
40 | *
|
41 | * This is the inverse of `microdataItemtype`.
|
42 | */
|
43 | export declare function microdataType(itemtype: string): keyof Types | undefined;
|
44 | /**
|
45 | * Attributes for Microdata ["properties"](https://www.w3.org/TR/microdata/#names:-the-itemprop-attribute)
|
46 | *
|
47 | * The `data-prop` attribute is not part of the Microdata standard.
|
48 | * It is used for properties that are not defined in schema.org and which validators
|
49 | * like Google Structured Data Testing Tool throw errors about.
|
50 | */
|
51 | export interface MicrodataProperty {
|
52 | itemprop?: string;
|
53 | 'data-prop'?: string;
|
54 | itemref?: string;
|
55 | }
|
56 | declare type Role = 'array' | 'item';
|
57 | /**
|
58 | * Create `MicrodataProperty` attributes for a node property.
|
59 | *
|
60 | * @param property The name of the property
|
61 | * @param isItem Is the node for which attributes are being generated
|
62 | * an item within an array property? e.g. a `Person` in `authors`.
|
63 | * @param id Id of another Microdata item to link to using the `itemref` property.
|
64 | */
|
65 | export declare function microdataProperty(property: string, role?: Role, id?: string): MicrodataProperty;
|
66 | /**
|
67 | * Get the HTML Microdata `itemprop` for a Stencila Schema property.
|
68 | *
|
69 | * The `itemprop` attribute is normally just the name of the property
|
70 | * i.e. it is not prefixed by a base URL. This function returns the
|
71 | * `[prefix, name]` pair e.g. `["schema", "author"]`,
|
72 | * `["codemeta", "maintainer"]` because you may only want to encode
|
73 | * `itemprop`s for well known schemas e.g. schema.org
|
74 | *
|
75 | * @see {@link https://www.w3.org/TR/microdata/#dfn-attr-itemprop}
|
76 | *
|
77 | * @param property The name of the property
|
78 | * @param role Is the node for which attributes are being generated
|
79 | * an item within an array property? e.g. a `Person` in `authors`.
|
80 | */
|
81 | export declare function microdataItemprop(property: string, role?: Role): [string | undefined, string | undefined];
|
82 | export declare type Microdata = MicrodataItem & MicrodataProperty;
|
83 | /**
|
84 | * Create all Microdata attributes for a Stencila `Node`.
|
85 | *
|
86 | * @param node The node e.g. a `Person` node
|
87 | * @param property The name of the property that this node is part of e.g `authors`
|
88 | * @param role Is this an item within an array property e.g a `Person` within `authors`
|
89 | * @param id The id used to link to / from this Microdata item
|
90 | */
|
91 | export declare function microdata(node: Node, property?: string, role?: Role, id?: string): Microdata;
|
92 | /**
|
93 | * Get the HTML attribute for the root element.
|
94 | *
|
95 | * This attribute name / value pair is used to scope CSS variables to
|
96 | * the root Stencila node in an HTML document. It is used by Encoda when
|
97 | * encoding to HTML, it is in Thema to scope CSS variable thereby
|
98 | * avoiding variable name clashes from using the CSS `:root` pseudo-class.
|
99 | *
|
100 | * Although not directly related to Microdata, given it is used in potentially
|
101 | * more than one project, this appears to be the best place for it.
|
102 | */
|
103 | export declare function microdataRoot(): {
|
104 | 'data-root': '';
|
105 | };
|
106 | export {};
|