html-validate 7.6.0 → 7.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -16
- package/dist/cjs/browser.d.ts +1 -1
- package/dist/cjs/browser.js +2 -2
- package/dist/cjs/cli.js +31 -31
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/core.d.ts +593 -559
- package/dist/cjs/core.js +2423 -2163
- package/dist/cjs/core.js.map +1 -1
- package/dist/cjs/html-validate.js +12 -12
- package/dist/cjs/html-validate.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/jest-lib.js +13 -14
- package/dist/cjs/jest-lib.js.map +1 -1
- package/dist/cjs/jest.d.ts +1 -1
- package/dist/cjs/test-utils.d.ts +1 -1
- package/dist/cjs/test-utils.js +3 -5
- package/dist/cjs/test-utils.js.map +1 -1
- package/dist/es/browser.d.ts +1 -1
- package/dist/es/browser.js +1 -1
- package/dist/es/cli.js +1 -1
- package/dist/es/core.d.ts +593 -559
- package/dist/es/core.js +2425 -2167
- package/dist/es/core.js.map +1 -1
- package/dist/es/html-validate.js +1 -1
- package/dist/es/index.d.ts +2 -2
- package/dist/es/index.js +1 -1
- package/dist/es/jest-lib.js +1 -1
- package/dist/es/jest.d.ts +1 -1
- package/dist/es/test-utils.d.ts +1 -1
- package/dist/schema/elements.json +4 -0
- package/elements/html5.js +208 -2
- package/package.json +29 -20
package/dist/cjs/core.d.ts
CHANGED
|
@@ -1001,739 +1001,773 @@ interface CSSStyleDeclaration {
|
|
|
1001
1001
|
[key: string]: string;
|
|
1002
1002
|
}
|
|
1003
1003
|
|
|
1004
|
-
interface PermittedGroup {
|
|
1005
|
-
exclude?: string | string[];
|
|
1006
|
-
}
|
|
1007
|
-
declare type CategoryOrTag = string;
|
|
1008
|
-
declare type PropertyExpression = string | [string, any];
|
|
1009
|
-
declare type PermittedEntry = CategoryOrTag | PermittedGroup | Array<CategoryOrTag | PermittedGroup>;
|
|
1010
|
-
declare type Permitted = PermittedEntry[];
|
|
1011
|
-
declare type PermittedOrder = string[];
|
|
1012
|
-
declare type RequiredAncestors = string[];
|
|
1013
|
-
declare type RequiredContent = string[];
|
|
1014
|
-
declare enum TextContent {
|
|
1015
|
-
NONE = "none",
|
|
1016
|
-
DEFAULT = "default",
|
|
1017
|
-
REQUIRED = "required",
|
|
1018
|
-
ACCESSIBLE = "accessible"
|
|
1019
|
-
}
|
|
1020
1004
|
/**
|
|
1021
1005
|
* @public
|
|
1022
1006
|
*/
|
|
1023
|
-
interface
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1007
|
+
interface TransformContext {
|
|
1008
|
+
/**
|
|
1009
|
+
* Test if an additional chainable transformer is present.
|
|
1010
|
+
*
|
|
1011
|
+
* Returns true only if there is a transformer configured for the given
|
|
1012
|
+
* filename.
|
|
1013
|
+
*
|
|
1014
|
+
* @param filename - Filename to use to match next transformer.
|
|
1015
|
+
*/
|
|
1016
|
+
hasChain(filename: string): boolean;
|
|
1017
|
+
/**
|
|
1018
|
+
* Chain transformations.
|
|
1019
|
+
*
|
|
1020
|
+
* Sometimes multiple transformers must be applied. For instance, a Markdown
|
|
1021
|
+
* file with JSX in a code-block.
|
|
1022
|
+
*
|
|
1023
|
+
* @param source - Source to chain transformations on.
|
|
1024
|
+
* @param filename - Filename to use to match next transformer (unrelated to
|
|
1025
|
+
* filename set in source)
|
|
1026
|
+
*/
|
|
1027
|
+
chain(source: Source, filename: string): Iterable<Source>;
|
|
1030
1028
|
}
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1029
|
+
|
|
1030
|
+
declare module "estree" {
|
|
1031
|
+
interface TemplateElement {
|
|
1032
|
+
start: number;
|
|
1033
|
+
end: number;
|
|
1034
|
+
}
|
|
1036
1035
|
}
|
|
1037
1036
|
/**
|
|
1038
1037
|
* @public
|
|
1039
1038
|
*/
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
phrasing?: boolean | PropertyExpression;
|
|
1047
|
-
embedded?: boolean | PropertyExpression;
|
|
1048
|
-
interactive?: boolean | PropertyExpression;
|
|
1049
|
-
deprecated?: boolean | string | DeprecatedElement;
|
|
1050
|
-
foreign?: boolean;
|
|
1051
|
-
void?: boolean;
|
|
1052
|
-
transparent?: boolean | string[];
|
|
1053
|
-
implicitClosed?: string[];
|
|
1054
|
-
scriptSupporting?: boolean;
|
|
1055
|
-
form?: boolean;
|
|
1056
|
-
labelable?: boolean | PropertyExpression;
|
|
1057
|
-
deprecatedAttributes?: string[];
|
|
1058
|
-
requiredAttributes?: string[];
|
|
1059
|
-
attributes?: PermittedAttribute;
|
|
1060
|
-
permittedContent?: Permitted;
|
|
1061
|
-
permittedDescendants?: Permitted;
|
|
1062
|
-
permittedOrder?: PermittedOrder;
|
|
1063
|
-
permittedParent?: Permitted;
|
|
1064
|
-
requiredAncestors?: RequiredAncestors;
|
|
1065
|
-
requiredContent?: RequiredContent;
|
|
1066
|
-
textContent?: TextContent;
|
|
1067
|
-
}
|
|
1068
|
-
/**
|
|
1069
|
-
* Properties listed here can be used to reverse search elements with the given
|
|
1070
|
-
* property enabled. See [[MetaTable.getTagsWithProperty]].
|
|
1071
|
-
*/
|
|
1072
|
-
declare type MetaLookupableProperty = "metadata" | "flow" | "sectioning" | "heading" | "phrasing" | "embedded" | "interactive" | "deprecated" | "foreign" | "void" | "transparent" | "scriptSupporting" | "form" | "labelable";
|
|
1073
|
-
/**
|
|
1074
|
-
* Properties listed here can be copied (loaded) onto another element using
|
|
1075
|
-
* [[HtmlElement.loadMeta]].
|
|
1076
|
-
*
|
|
1077
|
-
* @public
|
|
1078
|
-
*/
|
|
1079
|
-
declare const MetaCopyableProperty: Array<keyof MetaElement>;
|
|
1080
|
-
/**
|
|
1081
|
-
* @public
|
|
1082
|
-
*/
|
|
1083
|
-
interface MetaElement extends Omit<MetaData, "deprecatedAttributes" | "requiredAttributes"> {
|
|
1084
|
-
tagName: string;
|
|
1085
|
-
attributes: Record<string, MetaAttribute>;
|
|
1086
|
-
}
|
|
1087
|
-
interface MetaDataTable {
|
|
1088
|
-
[tagName: string]: MetaData;
|
|
1089
|
-
}
|
|
1090
|
-
interface ElementTable {
|
|
1091
|
-
[tagName: string]: MetaElement;
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
|
-
declare enum NodeType {
|
|
1095
|
-
ELEMENT_NODE = 1,
|
|
1096
|
-
TEXT_NODE = 3,
|
|
1097
|
-
DOCUMENT_NODE = 9
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
|
-
interface DOMNodeCache {
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
|
-
declare type DOMInternalID = number;
|
|
1104
|
-
declare const TEXT_CONTENT: unique symbol;
|
|
1105
|
-
declare module "./cache" {
|
|
1106
|
-
interface DOMNodeCache {
|
|
1107
|
-
[TEXT_CONTENT]: string;
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
declare class DOMNode {
|
|
1111
|
-
readonly nodeName: string;
|
|
1112
|
-
readonly nodeType: NodeType;
|
|
1113
|
-
readonly childNodes: DOMNode[];
|
|
1114
|
-
readonly location: Location;
|
|
1115
|
-
readonly unique: DOMInternalID;
|
|
1116
|
-
private cache;
|
|
1039
|
+
declare class TemplateExtractor {
|
|
1040
|
+
private ast;
|
|
1041
|
+
private filename;
|
|
1042
|
+
private data;
|
|
1043
|
+
private constructor();
|
|
1044
|
+
static fromFilename(filename: string): TemplateExtractor;
|
|
1117
1045
|
/**
|
|
1118
|
-
*
|
|
1046
|
+
* Create a new [[TemplateExtractor]] from javascript source code.
|
|
1119
1047
|
*
|
|
1120
|
-
*
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
/**
|
|
1124
|
-
* Create a new DOMNode.
|
|
1048
|
+
* `Source` offsets will be relative to the string, i.e. offset 0 is the first
|
|
1049
|
+
* character of the string. If the string is only a subset of a larger string
|
|
1050
|
+
* the offsets must be adjusted manually.
|
|
1125
1051
|
*
|
|
1126
|
-
* @param
|
|
1127
|
-
* @param
|
|
1128
|
-
*
|
|
1129
|
-
* @param location - Source code location of this node.
|
|
1052
|
+
* @param source - Source code.
|
|
1053
|
+
* @param filename - Optional filename to set in the resulting
|
|
1054
|
+
* `Source`. Defauls to `"inline"`.
|
|
1130
1055
|
*/
|
|
1131
|
-
|
|
1056
|
+
static fromString(source: string, filename?: string): TemplateExtractor;
|
|
1132
1057
|
/**
|
|
1133
|
-
*
|
|
1058
|
+
* Convenience function to create a [[Source]] instance from an existing file.
|
|
1134
1059
|
*
|
|
1135
|
-
*
|
|
1060
|
+
* @param filename - Filename with javascript source code. The file must exist
|
|
1061
|
+
* and be readable by the user.
|
|
1062
|
+
* @returns An array of Source's suitable for passing to [[Engine]] linting
|
|
1063
|
+
* functions.
|
|
1136
1064
|
*/
|
|
1137
|
-
|
|
1065
|
+
static createSource(filename: string): Source[];
|
|
1138
1066
|
/**
|
|
1139
|
-
*
|
|
1067
|
+
* Extract object properties.
|
|
1140
1068
|
*
|
|
1141
|
-
*
|
|
1142
|
-
*
|
|
1069
|
+
* Given a key `"template"` this method finds all objects literals with a
|
|
1070
|
+
* `"template"` property and creates a [[Source]] instance with proper offsets
|
|
1071
|
+
* with the value of the property. For instance:
|
|
1143
1072
|
*
|
|
1144
|
-
*
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
* Store a value in cache.
|
|
1073
|
+
* ```
|
|
1074
|
+
* const myObj = {
|
|
1075
|
+
* foo: 'bar',
|
|
1076
|
+
* };
|
|
1077
|
+
* ```
|
|
1150
1078
|
*
|
|
1151
|
-
*
|
|
1152
|
-
*/
|
|
1153
|
-
cacheSet<K extends keyof DOMNodeCache>(key: K, value: DOMNodeCache[K]): DOMNodeCache[K];
|
|
1154
|
-
cacheSet<T>(key: string | number | symbol, value: T): T;
|
|
1155
|
-
/**
|
|
1156
|
-
* Remove a value by key from cache.
|
|
1079
|
+
* The above snippet would yield a `Source` with the content `bar`.
|
|
1157
1080
|
*
|
|
1158
|
-
* @returns `true` if the entry existed and has been removed.
|
|
1159
|
-
*/
|
|
1160
|
-
cacheRemove<K extends keyof DOMNodeCache>(key: K): boolean;
|
|
1161
|
-
cacheRemove(key: string | number | symbol): boolean;
|
|
1162
|
-
/**
|
|
1163
|
-
* Check if key exists in cache.
|
|
1164
|
-
*/
|
|
1165
|
-
cacheExists<K extends keyof DOMNodeCache>(key: K): boolean;
|
|
1166
|
-
cacheExists(key: string | number | symbol): boolean;
|
|
1167
|
-
/**
|
|
1168
|
-
* Get the text (recursive) from all child nodes.
|
|
1169
|
-
*/
|
|
1170
|
-
get textContent(): string;
|
|
1171
|
-
append(node: DOMNode): void;
|
|
1172
|
-
isRootElement(): boolean;
|
|
1173
|
-
/**
|
|
1174
|
-
* Tests if two nodes are the same (references the same object).
|
|
1175
|
-
*/
|
|
1176
|
-
isSameNode(otherNode: DOMNode): boolean;
|
|
1177
|
-
/**
|
|
1178
|
-
* Returns a DOMNode representing the first direct child node or `null` if the
|
|
1179
|
-
* node has no children.
|
|
1180
1081
|
*/
|
|
1181
|
-
|
|
1182
|
-
/**
|
|
1183
|
-
* Returns a DOMNode representing the last direct child node or `null` if the
|
|
1184
|
-
* node has no children.
|
|
1185
|
-
*/
|
|
1186
|
-
get lastChild(): DOMNode;
|
|
1187
|
-
/**
|
|
1188
|
-
* Disable a rule for this node.
|
|
1189
|
-
*/
|
|
1190
|
-
disableRule(ruleId: string): void;
|
|
1191
|
-
/**
|
|
1192
|
-
* Disables multiple rules.
|
|
1193
|
-
*/
|
|
1194
|
-
disableRules(rules: string[]): void;
|
|
1195
|
-
/**
|
|
1196
|
-
* Enable a previously disabled rule for this node.
|
|
1197
|
-
*/
|
|
1198
|
-
enableRule(ruleId: string): void;
|
|
1199
|
-
/**
|
|
1200
|
-
* Enables multiple rules.
|
|
1201
|
-
*/
|
|
1202
|
-
enableRules(rules: string[]): void;
|
|
1203
|
-
/**
|
|
1204
|
-
* Test if a rule is enabled for this node.
|
|
1205
|
-
*/
|
|
1206
|
-
ruleEnabled(ruleId: string): boolean;
|
|
1207
|
-
generateSelector(): string | null;
|
|
1208
|
-
}
|
|
1209
|
-
|
|
1210
|
-
declare class DOMTokenList extends Array<string> {
|
|
1211
|
-
readonly value: string;
|
|
1212
|
-
private readonly locations;
|
|
1213
|
-
constructor(value: string | DynamicValue | null, location: Location | null);
|
|
1214
|
-
item(n: number): string | undefined;
|
|
1215
|
-
location(n: number): Location | undefined;
|
|
1216
|
-
contains(token: string): boolean;
|
|
1217
|
-
iterator(): Generator<{
|
|
1218
|
-
index: number;
|
|
1219
|
-
item: string;
|
|
1220
|
-
location: Location;
|
|
1221
|
-
}>;
|
|
1082
|
+
extractObjectProperty(key: string): Source[];
|
|
1222
1083
|
}
|
|
1223
1084
|
|
|
1224
1085
|
/**
|
|
1225
1086
|
* @public
|
|
1226
1087
|
*/
|
|
1227
|
-
declare
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
ImplicitClosed = 4
|
|
1088
|
+
declare type Transformer = (this: TransformContext, source: Source) => Iterable<Source>;
|
|
1089
|
+
|
|
1090
|
+
interface SchemaValidationPatch {
|
|
1091
|
+
properties?: Record<string, unknown>;
|
|
1092
|
+
definitions?: Record<string, unknown>;
|
|
1233
1093
|
}
|
|
1234
1094
|
/**
|
|
1235
1095
|
* @public
|
|
1236
1096
|
*/
|
|
1237
|
-
|
|
1238
|
-
readonly tagName: string;
|
|
1239
|
-
readonly parent: HtmlElement | null;
|
|
1240
|
-
readonly voidElement: boolean;
|
|
1241
|
-
readonly depth: number;
|
|
1242
|
-
closed: NodeClosed;
|
|
1243
|
-
protected readonly attr: {
|
|
1244
|
-
[key: string]: Attribute[];
|
|
1245
|
-
};
|
|
1246
|
-
private metaElement;
|
|
1247
|
-
private annotation;
|
|
1248
|
-
constructor(tagName: string | undefined, parent: HtmlElement | null, closed: NodeClosed, meta: MetaElement | null, location: Location);
|
|
1097
|
+
interface Plugin {
|
|
1249
1098
|
/**
|
|
1250
|
-
*
|
|
1099
|
+
* Name of the plugin.
|
|
1100
|
+
*
|
|
1101
|
+
* If specified this is the name used when referring to the plugin. Default is
|
|
1102
|
+
* to use the name/path the user used when loading the plugin. To be less
|
|
1103
|
+
* confusing for users you should use the same name as your package.
|
|
1104
|
+
*
|
|
1105
|
+
* The name must be a valid package name according to NPM (basically lowercase
|
|
1106
|
+
* characters, must not begin with dot, slash or non-url safe characters).
|
|
1107
|
+
*
|
|
1108
|
+
* Hint: import and use the name from `package.json`.
|
|
1251
1109
|
*/
|
|
1252
|
-
|
|
1110
|
+
name?: string | null;
|
|
1253
1111
|
/**
|
|
1254
|
-
*
|
|
1112
|
+
* Initialization callback.
|
|
1255
1113
|
*
|
|
1256
|
-
*
|
|
1114
|
+
* Called once per plugin during initialization.
|
|
1257
1115
|
*/
|
|
1258
|
-
|
|
1116
|
+
init?: () => void | null;
|
|
1259
1117
|
/**
|
|
1260
|
-
*
|
|
1118
|
+
* Setup callback.
|
|
1261
1119
|
*
|
|
1262
|
-
*
|
|
1120
|
+
* Called once per source after engine is initialized.
|
|
1121
|
+
*
|
|
1122
|
+
* @param source - The source about to be validated. Readonly.
|
|
1123
|
+
* @param eventhandler - Eventhandler from parser. Can be used to listen for
|
|
1124
|
+
* parser events.
|
|
1263
1125
|
*/
|
|
1264
|
-
|
|
1126
|
+
setup?: (source: Source, eventhandler: EventHandler) => void | null;
|
|
1265
1127
|
/**
|
|
1266
|
-
*
|
|
1128
|
+
* Configuration presets.
|
|
1267
1129
|
*
|
|
1268
|
-
*
|
|
1269
|
-
*
|
|
1130
|
+
* Each key should be the unprefixed name which a configuration later can
|
|
1131
|
+
* access using `${plugin}:${key}`, e.g. if a plugin named "my-plugin" exposes
|
|
1132
|
+
* a preset named "foobar" it can be accessed using:
|
|
1270
1133
|
*
|
|
1271
|
-
*
|
|
1134
|
+
* "extends": ["my-plugin:foobar"]
|
|
1272
1135
|
*/
|
|
1273
|
-
|
|
1136
|
+
configs?: Record<string, ConfigData | null> | null;
|
|
1274
1137
|
/**
|
|
1275
|
-
*
|
|
1138
|
+
* List of new rules present.
|
|
1276
1139
|
*/
|
|
1277
|
-
|
|
1140
|
+
rules?: Record<string, RuleConstructor<any, any> | null> | null;
|
|
1141
|
+
/**
|
|
1142
|
+
* Transformer available in this plugin.
|
|
1143
|
+
*
|
|
1144
|
+
* Can be given either as a single unnamed transformer or an object with
|
|
1145
|
+
* multiple named.
|
|
1146
|
+
*
|
|
1147
|
+
* Unnamed transformers use the plugin name similar to how a standalone
|
|
1148
|
+
* transformer would work:
|
|
1149
|
+
*
|
|
1150
|
+
* ```
|
|
1151
|
+
* "transform": {
|
|
1152
|
+
* "^.*\\.foo$": "my-plugin"
|
|
1153
|
+
* }
|
|
1154
|
+
* ```
|
|
1155
|
+
*
|
|
1156
|
+
* For named transformers each key should be the unprefixed name which a
|
|
1157
|
+
* configuration later can access using `${plugin}:${key}`, e.g. if a plugin
|
|
1158
|
+
* named "my-plugin" exposes a transformer named "foobar" it can be accessed
|
|
1159
|
+
* using:
|
|
1160
|
+
*
|
|
1161
|
+
* ```
|
|
1162
|
+
* "transform": {
|
|
1163
|
+
* "^.*\\.foo$": "my-plugin:foobar"
|
|
1164
|
+
* }
|
|
1165
|
+
* ```
|
|
1166
|
+
*/
|
|
1167
|
+
transformer?: Transformer | Record<string, Transformer | null> | null;
|
|
1168
|
+
/**
|
|
1169
|
+
* Extend metadata validation schema.
|
|
1170
|
+
*/
|
|
1171
|
+
elementSchema?: SchemaValidationPatch | null;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
/**
|
|
1175
|
+
* @public
|
|
1176
|
+
*/
|
|
1177
|
+
declare class MetaTable {
|
|
1178
|
+
readonly elements: ElementTable;
|
|
1179
|
+
private schema;
|
|
1278
1180
|
/**
|
|
1279
|
-
*
|
|
1280
|
-
*
|
|
1281
|
-
* Implementation of DOM specification of Element.closest(selectors).
|
|
1181
|
+
* @internal
|
|
1282
1182
|
*/
|
|
1283
|
-
|
|
1183
|
+
constructor();
|
|
1284
1184
|
/**
|
|
1285
|
-
*
|
|
1286
|
-
* unique inside the current document.
|
|
1185
|
+
* @internal
|
|
1287
1186
|
*/
|
|
1288
|
-
|
|
1187
|
+
init(): void;
|
|
1289
1188
|
/**
|
|
1290
|
-
*
|
|
1189
|
+
* Extend validation schema.
|
|
1291
1190
|
*
|
|
1292
|
-
*
|
|
1191
|
+
* @internal
|
|
1293
1192
|
*/
|
|
1294
|
-
|
|
1193
|
+
extendValidationSchema(patch: SchemaValidationPatch): void;
|
|
1295
1194
|
/**
|
|
1296
|
-
* Load
|
|
1297
|
-
*
|
|
1298
|
-
* Do note that semantics such as `void` cannot be changed (as the element has
|
|
1299
|
-
* already been created). In addition the element will still "be" the same
|
|
1300
|
-
* element, i.e. even if loading meta for a `<p>` tag upon a `<div>` tag it
|
|
1301
|
-
* will still be a `<div>` as far as the rest of the validator is concerned.
|
|
1302
|
-
*
|
|
1303
|
-
* In fact only certain properties will be copied onto the element:
|
|
1304
|
-
*
|
|
1305
|
-
* - content categories (flow, phrasing, etc)
|
|
1306
|
-
* - required attributes
|
|
1307
|
-
* - attribute allowed values
|
|
1308
|
-
* - permitted/required elements
|
|
1309
|
-
*
|
|
1310
|
-
* Properties *not* loaded:
|
|
1311
|
-
*
|
|
1312
|
-
* - inherit
|
|
1313
|
-
* - deprecated
|
|
1314
|
-
* - foreign
|
|
1315
|
-
* - void
|
|
1316
|
-
* - implicitClosed
|
|
1317
|
-
* - scriptSupporting
|
|
1318
|
-
* - deprecatedAttributes
|
|
1195
|
+
* Load metadata table from object.
|
|
1319
1196
|
*
|
|
1320
|
-
*
|
|
1321
|
-
*
|
|
1197
|
+
* @internal
|
|
1198
|
+
* @param obj - Object with metadata to load
|
|
1199
|
+
* @param filename - Optional filename used when presenting validation error
|
|
1322
1200
|
*/
|
|
1323
|
-
|
|
1201
|
+
loadFromObject(obj: unknown, filename?: string | null): void;
|
|
1324
1202
|
/**
|
|
1325
|
-
*
|
|
1326
|
-
* matches.
|
|
1203
|
+
* Load metadata table from filename
|
|
1327
1204
|
*
|
|
1328
|
-
*
|
|
1329
|
-
|
|
1330
|
-
matches(selector: string): boolean;
|
|
1331
|
-
get meta(): MetaElement | null;
|
|
1332
|
-
/**
|
|
1333
|
-
* Set annotation for this element.
|
|
1205
|
+
* @internal
|
|
1206
|
+
* @param filename - Filename to load
|
|
1334
1207
|
*/
|
|
1335
|
-
|
|
1208
|
+
loadFromFile(filename: string): void;
|
|
1336
1209
|
/**
|
|
1337
|
-
*
|
|
1210
|
+
* Get [[MetaElement]] for the given tag. If no specific metadata is present
|
|
1211
|
+
* the global metadata is returned or null if no global is present.
|
|
1338
1212
|
*
|
|
1339
|
-
* @
|
|
1340
|
-
* @
|
|
1341
|
-
* @param keyLocation - Location of the attribute name.
|
|
1342
|
-
* @param valueLocation - Location of the attribute value (excluding quotation)
|
|
1343
|
-
* @param originalAttribute - If attribute is an alias for another attribute
|
|
1344
|
-
* (dynamic attributes) set this to the original attribute name.
|
|
1345
|
-
*/
|
|
1346
|
-
setAttribute(key: string, value: string | DynamicValue | null, keyLocation: Location, valueLocation: Location | null, originalAttribute?: string): void;
|
|
1347
|
-
/**
|
|
1348
|
-
* Get a list of all attributes on this node.
|
|
1213
|
+
* @public
|
|
1214
|
+
* @returns A shallow copy of metadata.
|
|
1349
1215
|
*/
|
|
1350
|
-
|
|
1351
|
-
hasAttribute(key: string): boolean;
|
|
1216
|
+
getMetaFor(tagName: string): MetaElement | null;
|
|
1352
1217
|
/**
|
|
1353
|
-
*
|
|
1354
|
-
*
|
|
1355
|
-
* By default only the first attribute is returned but if the code needs to
|
|
1356
|
-
* handle duplicate attributes the `all` parameter can be set to get all
|
|
1357
|
-
* attributes with given key.
|
|
1358
|
-
*
|
|
1359
|
-
* This usually only happens when code contains duplicate attributes (which
|
|
1360
|
-
* `no-dup-attr` will complain about) or when a static attribute is combined
|
|
1361
|
-
* with a dynamic, consider:
|
|
1362
|
-
*
|
|
1363
|
-
* <p class="foo" dynamic-class="bar">
|
|
1218
|
+
* Find all tags which has enabled given property.
|
|
1364
1219
|
*
|
|
1365
|
-
* @
|
|
1366
|
-
* @param all - Return single or all attributes.
|
|
1220
|
+
* @public
|
|
1367
1221
|
*/
|
|
1368
|
-
|
|
1369
|
-
getAttribute(key: string, all: true): Attribute[];
|
|
1222
|
+
getTagsWithProperty(propName: MetaLookupableProperty): string[];
|
|
1370
1223
|
/**
|
|
1371
|
-
*
|
|
1372
|
-
*
|
|
1373
|
-
* Returns the attribute value if present.
|
|
1374
|
-
*
|
|
1375
|
-
* - Missing attributes return `null`.
|
|
1376
|
-
* - Boolean attributes return `null`.
|
|
1377
|
-
* - `DynamicValue` returns attribute expression.
|
|
1224
|
+
* Find tag matching tagName or inheriting from it.
|
|
1378
1225
|
*
|
|
1379
|
-
* @
|
|
1380
|
-
* @returns Attribute value or null.
|
|
1226
|
+
* @public
|
|
1381
1227
|
*/
|
|
1382
|
-
|
|
1228
|
+
getTagsDerivedFrom(tagName: string): string[];
|
|
1229
|
+
private addEntry;
|
|
1383
1230
|
/**
|
|
1384
|
-
*
|
|
1385
|
-
*
|
|
1386
|
-
* @param text - Text to add.
|
|
1387
|
-
* @param location - Source code location of this text.
|
|
1231
|
+
* Construct a new AJV schema validator.
|
|
1388
1232
|
*/
|
|
1389
|
-
|
|
1233
|
+
private getSchemaValidator;
|
|
1390
1234
|
/**
|
|
1391
|
-
*
|
|
1392
|
-
* ignored.
|
|
1235
|
+
* @public
|
|
1393
1236
|
*/
|
|
1394
|
-
|
|
1237
|
+
getJSONSchema(): SchemaObject;
|
|
1395
1238
|
/**
|
|
1396
|
-
*
|
|
1239
|
+
* Finds the global element definition and merges each known element with the
|
|
1240
|
+
* global, e.g. to assign global attributes.
|
|
1397
1241
|
*/
|
|
1398
|
-
|
|
1399
|
-
|
|
1242
|
+
private resolveGlobal;
|
|
1243
|
+
private mergeElement;
|
|
1400
1244
|
/**
|
|
1401
|
-
*
|
|
1245
|
+
* @internal
|
|
1402
1246
|
*/
|
|
1403
|
-
|
|
1247
|
+
resolve(node: HtmlElement): void;
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
declare enum NodeType {
|
|
1251
|
+
ELEMENT_NODE = 1,
|
|
1252
|
+
TEXT_NODE = 3,
|
|
1253
|
+
DOCUMENT_NODE = 9
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
interface DOMNodeCache {
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
declare type DOMInternalID = number;
|
|
1260
|
+
declare const TEXT_CONTENT: unique symbol;
|
|
1261
|
+
declare module "./cache" {
|
|
1262
|
+
interface DOMNodeCache {
|
|
1263
|
+
[TEXT_CONTENT]: string;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
declare class DOMNode {
|
|
1267
|
+
readonly nodeName: string;
|
|
1268
|
+
readonly nodeType: NodeType;
|
|
1269
|
+
readonly childNodes: DOMNode[];
|
|
1270
|
+
readonly location: Location;
|
|
1271
|
+
readonly unique: DOMInternalID;
|
|
1272
|
+
private cache;
|
|
1404
1273
|
/**
|
|
1405
|
-
*
|
|
1274
|
+
* Set of disabled rules for this node.
|
|
1275
|
+
*
|
|
1276
|
+
* Rules disabled by using directives are added here.
|
|
1406
1277
|
*/
|
|
1407
|
-
|
|
1408
|
-
get siblings(): HtmlElement[];
|
|
1409
|
-
get previousSibling(): HtmlElement | null;
|
|
1410
|
-
get nextSibling(): HtmlElement | null;
|
|
1411
|
-
getElementsByTagName(tagName: string): HtmlElement[];
|
|
1412
|
-
querySelector(selector: string): HtmlElement;
|
|
1413
|
-
querySelectorAll(selector: string): HtmlElement[];
|
|
1414
|
-
private querySelectorImpl;
|
|
1278
|
+
private disabledRules;
|
|
1415
1279
|
/**
|
|
1416
|
-
*
|
|
1280
|
+
* Create a new DOMNode.
|
|
1417
1281
|
*
|
|
1418
|
-
* @
|
|
1282
|
+
* @param nodeType - What node type to create.
|
|
1283
|
+
* @param nodeName - What node name to use. For `HtmlElement` this corresponds
|
|
1284
|
+
* to the tagName but other node types have specific predefined values.
|
|
1285
|
+
* @param location - Source code location of this node.
|
|
1419
1286
|
*/
|
|
1420
|
-
|
|
1287
|
+
constructor(nodeType: NodeType, nodeName: string | undefined, location: Location);
|
|
1421
1288
|
/**
|
|
1422
|
-
*
|
|
1289
|
+
* Enable cache for this node.
|
|
1423
1290
|
*
|
|
1424
|
-
*
|
|
1291
|
+
* Should not be called before the node and all children are fully constructed.
|
|
1425
1292
|
*/
|
|
1426
|
-
|
|
1293
|
+
cacheEnable(): void;
|
|
1427
1294
|
/**
|
|
1428
|
-
*
|
|
1295
|
+
* Fetch cached value from this DOM node.
|
|
1429
1296
|
*
|
|
1430
|
-
*
|
|
1297
|
+
* Cache is not enabled until `cacheEnable()` is called by [[Parser]] (when
|
|
1298
|
+
* the element is fully constructed).
|
|
1299
|
+
*
|
|
1300
|
+
* @returns value or `undefined` if the value doesn't exist.
|
|
1431
1301
|
*/
|
|
1432
|
-
|
|
1302
|
+
cacheGet<K extends keyof DOMNodeCache>(key: K): DOMNodeCache[K] | undefined;
|
|
1303
|
+
cacheGet(key: string | number | symbol): any | undefined;
|
|
1433
1304
|
/**
|
|
1434
|
-
*
|
|
1305
|
+
* Store a value in cache.
|
|
1435
1306
|
*
|
|
1436
|
-
*
|
|
1307
|
+
* @returns the value itself is returned.
|
|
1308
|
+
*/
|
|
1309
|
+
cacheSet<K extends keyof DOMNodeCache>(key: K, value: DOMNodeCache[K]): DOMNodeCache[K];
|
|
1310
|
+
cacheSet<T>(key: string | number | symbol, value: T): T;
|
|
1311
|
+
/**
|
|
1312
|
+
* Remove a value by key from cache.
|
|
1437
1313
|
*
|
|
1438
|
-
* @
|
|
1314
|
+
* @returns `true` if the entry existed and has been removed.
|
|
1439
1315
|
*/
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
declare class DOMTree {
|
|
1444
|
-
readonly root: HtmlElement;
|
|
1445
|
-
private active;
|
|
1446
|
-
doctype: string | null;
|
|
1447
|
-
constructor(location: Location);
|
|
1448
|
-
pushActive(node: HtmlElement): void;
|
|
1449
|
-
popActive(): void;
|
|
1450
|
-
getActive(): HtmlElement;
|
|
1316
|
+
cacheRemove<K extends keyof DOMNodeCache>(key: K): boolean;
|
|
1317
|
+
cacheRemove(key: string | number | symbol): boolean;
|
|
1451
1318
|
/**
|
|
1452
|
-
*
|
|
1319
|
+
* Check if key exists in cache.
|
|
1453
1320
|
*/
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
/**
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
private readonly text;
|
|
1321
|
+
cacheExists<K extends keyof DOMNodeCache>(key: K): boolean;
|
|
1322
|
+
cacheExists(key: string | number | symbol): boolean;
|
|
1323
|
+
/**
|
|
1324
|
+
* Get the text (recursive) from all child nodes.
|
|
1325
|
+
*/
|
|
1326
|
+
get textContent(): string;
|
|
1327
|
+
append(node: DOMNode): void;
|
|
1328
|
+
isRootElement(): boolean;
|
|
1329
|
+
/**
|
|
1330
|
+
* Tests if two nodes are the same (references the same object).
|
|
1331
|
+
*/
|
|
1332
|
+
isSameNode(otherNode: DOMNode): boolean;
|
|
1333
|
+
/**
|
|
1334
|
+
* Returns a DOMNode representing the first direct child node or `null` if the
|
|
1335
|
+
* node has no children.
|
|
1336
|
+
*/
|
|
1337
|
+
get firstChild(): DOMNode;
|
|
1472
1338
|
/**
|
|
1473
|
-
*
|
|
1474
|
-
*
|
|
1475
|
-
* @param location - Source code location of this node.
|
|
1339
|
+
* Returns a DOMNode representing the last direct child node or `null` if the
|
|
1340
|
+
* node has no children.
|
|
1476
1341
|
*/
|
|
1477
|
-
|
|
1342
|
+
get lastChild(): DOMNode;
|
|
1478
1343
|
/**
|
|
1479
|
-
*
|
|
1344
|
+
* Disable a rule for this node.
|
|
1480
1345
|
*/
|
|
1481
|
-
|
|
1346
|
+
disableRule(ruleId: string): void;
|
|
1482
1347
|
/**
|
|
1483
|
-
*
|
|
1348
|
+
* Disables multiple rules.
|
|
1484
1349
|
*/
|
|
1485
|
-
|
|
1350
|
+
disableRules(rules: string[]): void;
|
|
1486
1351
|
/**
|
|
1487
|
-
*
|
|
1352
|
+
* Enable a previously disabled rule for this node.
|
|
1488
1353
|
*/
|
|
1489
|
-
|
|
1490
|
-
}
|
|
1491
|
-
|
|
1492
|
-
/**
|
|
1493
|
-
* @public
|
|
1494
|
-
*/
|
|
1495
|
-
interface TransformContext {
|
|
1354
|
+
enableRule(ruleId: string): void;
|
|
1496
1355
|
/**
|
|
1497
|
-
*
|
|
1498
|
-
*
|
|
1499
|
-
* Returns true only if there is a transformer configured for the given
|
|
1500
|
-
* filename.
|
|
1501
|
-
*
|
|
1502
|
-
* @param filename - Filename to use to match next transformer.
|
|
1356
|
+
* Enables multiple rules.
|
|
1503
1357
|
*/
|
|
1504
|
-
|
|
1358
|
+
enableRules(rules: string[]): void;
|
|
1505
1359
|
/**
|
|
1506
|
-
*
|
|
1507
|
-
*
|
|
1508
|
-
* Sometimes multiple transformers must be applied. For instance, a Markdown
|
|
1509
|
-
* file with JSX in a code-block.
|
|
1510
|
-
*
|
|
1511
|
-
* @param source - Source to chain transformations on.
|
|
1512
|
-
* @param filename - Filename to use to match next transformer (unrelated to
|
|
1513
|
-
* filename set in source)
|
|
1360
|
+
* Test if a rule is enabled for this node.
|
|
1514
1361
|
*/
|
|
1515
|
-
|
|
1362
|
+
ruleEnabled(ruleId: string): boolean;
|
|
1363
|
+
generateSelector(): string | null;
|
|
1516
1364
|
}
|
|
1517
1365
|
|
|
1518
|
-
declare
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1366
|
+
declare class DOMTokenList extends Array<string> {
|
|
1367
|
+
readonly value: string;
|
|
1368
|
+
private readonly locations;
|
|
1369
|
+
constructor(value: string | DynamicValue | null, location: Location | null);
|
|
1370
|
+
item(n: number): string | undefined;
|
|
1371
|
+
location(n: number): Location | undefined;
|
|
1372
|
+
contains(token: string): boolean;
|
|
1373
|
+
iterator(): Generator<{
|
|
1374
|
+
index: number;
|
|
1375
|
+
item: string;
|
|
1376
|
+
location: Location;
|
|
1377
|
+
}>;
|
|
1523
1378
|
}
|
|
1379
|
+
|
|
1524
1380
|
/**
|
|
1525
1381
|
* @public
|
|
1526
1382
|
*/
|
|
1527
|
-
declare
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1383
|
+
declare enum NodeClosed {
|
|
1384
|
+
Open = 0,
|
|
1385
|
+
EndTag = 1,
|
|
1386
|
+
VoidOmitted = 2,
|
|
1387
|
+
VoidSelfClosed = 3,
|
|
1388
|
+
ImplicitClosed = 4
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* @public
|
|
1392
|
+
*/
|
|
1393
|
+
declare class HtmlElement extends DOMNode {
|
|
1394
|
+
readonly tagName: string;
|
|
1395
|
+
readonly parent: HtmlElement | null;
|
|
1396
|
+
readonly voidElement: boolean;
|
|
1397
|
+
readonly depth: number;
|
|
1398
|
+
closed: NodeClosed;
|
|
1399
|
+
protected readonly attr: {
|
|
1400
|
+
[key: string]: Attribute[];
|
|
1401
|
+
};
|
|
1402
|
+
private metaElement;
|
|
1403
|
+
private annotation;
|
|
1404
|
+
constructor(tagName: string | undefined, parent: HtmlElement | null, closed: NodeClosed, meta: MetaElement | null, location: Location);
|
|
1533
1405
|
/**
|
|
1534
|
-
*
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
*
|
|
1406
|
+
* @internal
|
|
1407
|
+
*/
|
|
1408
|
+
static rootNode(location: Location): HtmlElement;
|
|
1409
|
+
/**
|
|
1410
|
+
* @internal
|
|
1539
1411
|
*
|
|
1540
|
-
* @param
|
|
1541
|
-
* @param filename - Optional filename to set in the resulting
|
|
1542
|
-
* `Source`. Defauls to `"inline"`.
|
|
1412
|
+
* @param namespace - If given it is appended to the tagName.
|
|
1543
1413
|
*/
|
|
1544
|
-
static
|
|
1414
|
+
static fromTokens(startToken: TagOpenToken, endToken: TagCloseToken, parent: HtmlElement | null, metaTable: MetaTable | null, namespace?: string): HtmlElement;
|
|
1545
1415
|
/**
|
|
1546
|
-
*
|
|
1416
|
+
* Returns annotated name if set or defaults to `<tagName>`.
|
|
1547
1417
|
*
|
|
1548
|
-
*
|
|
1549
|
-
* and be readable by the user.
|
|
1550
|
-
* @returns An array of Source's suitable for passing to [[Engine]] linting
|
|
1551
|
-
* functions.
|
|
1418
|
+
* E.g. `my-annotation` or `<div>`.
|
|
1552
1419
|
*/
|
|
1553
|
-
|
|
1420
|
+
get annotatedName(): string;
|
|
1554
1421
|
/**
|
|
1555
|
-
*
|
|
1422
|
+
* Get list of IDs referenced by `aria-labelledby`.
|
|
1556
1423
|
*
|
|
1557
|
-
*
|
|
1558
|
-
*
|
|
1559
|
-
* with the value of the property. For instance:
|
|
1424
|
+
* If the attribute is unset or empty this getter returns null.
|
|
1425
|
+
* If the attribute is dynamic the original {@link DynamicValue} is returned.
|
|
1560
1426
|
*
|
|
1561
|
-
*
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
*
|
|
1427
|
+
* @public
|
|
1428
|
+
*/
|
|
1429
|
+
get ariaLabelledby(): string[] | DynamicValue | null;
|
|
1430
|
+
/**
|
|
1431
|
+
* Similar to childNodes but only elements.
|
|
1432
|
+
*/
|
|
1433
|
+
get childElements(): HtmlElement[];
|
|
1434
|
+
/**
|
|
1435
|
+
* Find the first ancestor matching a selector.
|
|
1566
1436
|
*
|
|
1567
|
-
*
|
|
1437
|
+
* Implementation of DOM specification of Element.closest(selectors).
|
|
1438
|
+
*/
|
|
1439
|
+
closest(selectors: string): HtmlElement | null;
|
|
1440
|
+
/**
|
|
1441
|
+
* Generate a DOM selector for this element. The returned selector will be
|
|
1442
|
+
* unique inside the current document.
|
|
1443
|
+
*/
|
|
1444
|
+
generateSelector(): string | null;
|
|
1445
|
+
/**
|
|
1446
|
+
* Tests if this element has given tagname.
|
|
1568
1447
|
*
|
|
1448
|
+
* If passing "*" this test will pass if any tagname is set.
|
|
1569
1449
|
*/
|
|
1570
|
-
|
|
1571
|
-
}
|
|
1572
|
-
|
|
1573
|
-
/**
|
|
1574
|
-
* @public
|
|
1575
|
-
*/
|
|
1576
|
-
declare type Transformer = (this: TransformContext, source: Source) => Iterable<Source>;
|
|
1577
|
-
|
|
1578
|
-
interface SchemaValidationPatch {
|
|
1579
|
-
properties?: Record<string, unknown>;
|
|
1580
|
-
definitions?: Record<string, unknown>;
|
|
1581
|
-
}
|
|
1582
|
-
/**
|
|
1583
|
-
* @public
|
|
1584
|
-
*/
|
|
1585
|
-
interface Plugin {
|
|
1450
|
+
is(tagName: string): boolean;
|
|
1586
1451
|
/**
|
|
1587
|
-
*
|
|
1452
|
+
* Load new element metadata onto this element.
|
|
1588
1453
|
*
|
|
1589
|
-
*
|
|
1590
|
-
*
|
|
1591
|
-
*
|
|
1454
|
+
* Do note that semantics such as `void` cannot be changed (as the element has
|
|
1455
|
+
* already been created). In addition the element will still "be" the same
|
|
1456
|
+
* element, i.e. even if loading meta for a `<p>` tag upon a `<div>` tag it
|
|
1457
|
+
* will still be a `<div>` as far as the rest of the validator is concerned.
|
|
1592
1458
|
*
|
|
1593
|
-
*
|
|
1594
|
-
* characters, must not begin with dot, slash or non-url safe characters).
|
|
1459
|
+
* In fact only certain properties will be copied onto the element:
|
|
1595
1460
|
*
|
|
1596
|
-
*
|
|
1461
|
+
* - content categories (flow, phrasing, etc)
|
|
1462
|
+
* - required attributes
|
|
1463
|
+
* - attribute allowed values
|
|
1464
|
+
* - permitted/required elements
|
|
1465
|
+
*
|
|
1466
|
+
* Properties *not* loaded:
|
|
1467
|
+
*
|
|
1468
|
+
* - inherit
|
|
1469
|
+
* - deprecated
|
|
1470
|
+
* - foreign
|
|
1471
|
+
* - void
|
|
1472
|
+
* - implicitClosed
|
|
1473
|
+
* - scriptSupporting
|
|
1474
|
+
* - deprecatedAttributes
|
|
1475
|
+
*
|
|
1476
|
+
* Changes to element metadata will only be visible after `element:ready` (and
|
|
1477
|
+
* the subsequent `dom:ready` event).
|
|
1597
1478
|
*/
|
|
1598
|
-
|
|
1479
|
+
loadMeta(meta: MetaElement): void;
|
|
1599
1480
|
/**
|
|
1600
|
-
*
|
|
1481
|
+
* Match this element against given selectors. Returns true if any selector
|
|
1482
|
+
* matches.
|
|
1601
1483
|
*
|
|
1602
|
-
*
|
|
1484
|
+
* Implementation of DOM specification of Element.matches(selectors).
|
|
1603
1485
|
*/
|
|
1604
|
-
|
|
1486
|
+
matches(selector: string): boolean;
|
|
1487
|
+
get meta(): MetaElement | null;
|
|
1605
1488
|
/**
|
|
1606
|
-
*
|
|
1607
|
-
*
|
|
1608
|
-
* Called once per source after engine is initialized.
|
|
1609
|
-
*
|
|
1610
|
-
* @param source - The source about to be validated. Readonly.
|
|
1611
|
-
* @param eventhandler - Eventhandler from parser. Can be used to listen for
|
|
1612
|
-
* parser events.
|
|
1489
|
+
* Set annotation for this element.
|
|
1613
1490
|
*/
|
|
1614
|
-
|
|
1491
|
+
setAnnotation(text: string): void;
|
|
1615
1492
|
/**
|
|
1616
|
-
*
|
|
1617
|
-
*
|
|
1618
|
-
* Each key should be the unprefixed name which a configuration later can
|
|
1619
|
-
* access using `${plugin}:${key}`, e.g. if a plugin named "my-plugin" exposes
|
|
1620
|
-
* a preset named "foobar" it can be accessed using:
|
|
1493
|
+
* Set attribute. Stores all attributes set even with the same name.
|
|
1621
1494
|
*
|
|
1622
|
-
*
|
|
1495
|
+
* @param key - Attribute name
|
|
1496
|
+
* @param value - Attribute value. Use `null` if no value is present.
|
|
1497
|
+
* @param keyLocation - Location of the attribute name.
|
|
1498
|
+
* @param valueLocation - Location of the attribute value (excluding quotation)
|
|
1499
|
+
* @param originalAttribute - If attribute is an alias for another attribute
|
|
1500
|
+
* (dynamic attributes) set this to the original attribute name.
|
|
1623
1501
|
*/
|
|
1624
|
-
|
|
1502
|
+
setAttribute(key: string, value: string | DynamicValue | null, keyLocation: Location, valueLocation: Location | null, originalAttribute?: string): void;
|
|
1625
1503
|
/**
|
|
1626
|
-
*
|
|
1504
|
+
* Get a list of all attributes on this node.
|
|
1627
1505
|
*/
|
|
1628
|
-
|
|
1506
|
+
get attributes(): Attribute[];
|
|
1507
|
+
hasAttribute(key: string): boolean;
|
|
1508
|
+
/**
|
|
1509
|
+
* Get attribute.
|
|
1510
|
+
*
|
|
1511
|
+
* By default only the first attribute is returned but if the code needs to
|
|
1512
|
+
* handle duplicate attributes the `all` parameter can be set to get all
|
|
1513
|
+
* attributes with given key.
|
|
1514
|
+
*
|
|
1515
|
+
* This usually only happens when code contains duplicate attributes (which
|
|
1516
|
+
* `no-dup-attr` will complain about) or when a static attribute is combined
|
|
1517
|
+
* with a dynamic, consider:
|
|
1518
|
+
*
|
|
1519
|
+
* <p class="foo" dynamic-class="bar">
|
|
1520
|
+
*
|
|
1521
|
+
* @param key - Attribute name
|
|
1522
|
+
* @param all - Return single or all attributes.
|
|
1523
|
+
*/
|
|
1524
|
+
getAttribute(key: string): Attribute | null;
|
|
1525
|
+
getAttribute(key: string, all: true): Attribute[];
|
|
1629
1526
|
/**
|
|
1630
|
-
*
|
|
1631
|
-
*
|
|
1632
|
-
* Can be given either as a single unnamed transformer or an object with
|
|
1633
|
-
* multiple named.
|
|
1527
|
+
* Get attribute value.
|
|
1634
1528
|
*
|
|
1635
|
-
*
|
|
1636
|
-
* transformer would work:
|
|
1529
|
+
* Returns the attribute value if present.
|
|
1637
1530
|
*
|
|
1638
|
-
*
|
|
1639
|
-
*
|
|
1640
|
-
*
|
|
1641
|
-
* }
|
|
1642
|
-
* ```
|
|
1531
|
+
* - Missing attributes return `null`.
|
|
1532
|
+
* - Boolean attributes return `null`.
|
|
1533
|
+
* - `DynamicValue` returns attribute expression.
|
|
1643
1534
|
*
|
|
1644
|
-
*
|
|
1645
|
-
*
|
|
1646
|
-
|
|
1647
|
-
|
|
1535
|
+
* @param key - Attribute name
|
|
1536
|
+
* @returns Attribute value or null.
|
|
1537
|
+
*/
|
|
1538
|
+
getAttributeValue(key: string): string | null;
|
|
1539
|
+
/**
|
|
1540
|
+
* Add text as a child node to this element.
|
|
1648
1541
|
*
|
|
1649
|
-
*
|
|
1650
|
-
*
|
|
1651
|
-
* "^.*\\.foo$": "my-plugin:foobar"
|
|
1652
|
-
* }
|
|
1653
|
-
* ```
|
|
1542
|
+
* @param text - Text to add.
|
|
1543
|
+
* @param location - Source code location of this text.
|
|
1654
1544
|
*/
|
|
1655
|
-
|
|
1545
|
+
appendText(text: string | DynamicValue, location: Location): void;
|
|
1656
1546
|
/**
|
|
1657
|
-
*
|
|
1547
|
+
* Return a list of all known classes on the element. Dynamic values are
|
|
1548
|
+
* ignored.
|
|
1658
1549
|
*/
|
|
1659
|
-
|
|
1660
|
-
}
|
|
1661
|
-
|
|
1662
|
-
/**
|
|
1663
|
-
* @public
|
|
1664
|
-
*/
|
|
1665
|
-
declare class MetaTable {
|
|
1666
|
-
readonly elements: ElementTable;
|
|
1667
|
-
private schema;
|
|
1550
|
+
get classList(): DOMTokenList;
|
|
1668
1551
|
/**
|
|
1669
|
-
*
|
|
1552
|
+
* Get element ID if present.
|
|
1670
1553
|
*/
|
|
1671
|
-
|
|
1554
|
+
get id(): string | null;
|
|
1555
|
+
get style(): CSSStyleDeclaration;
|
|
1672
1556
|
/**
|
|
1673
|
-
*
|
|
1557
|
+
* Returns the first child element or null if there are no child elements.
|
|
1674
1558
|
*/
|
|
1675
|
-
|
|
1559
|
+
get firstElementChild(): HtmlElement | null;
|
|
1676
1560
|
/**
|
|
1677
|
-
*
|
|
1678
|
-
*
|
|
1679
|
-
* @internal
|
|
1561
|
+
* Returns the last child element or null if there are no child elements.
|
|
1680
1562
|
*/
|
|
1681
|
-
|
|
1563
|
+
get lastElementChild(): HtmlElement | null;
|
|
1564
|
+
get siblings(): HtmlElement[];
|
|
1565
|
+
get previousSibling(): HtmlElement | null;
|
|
1566
|
+
get nextSibling(): HtmlElement | null;
|
|
1567
|
+
getElementsByTagName(tagName: string): HtmlElement[];
|
|
1568
|
+
querySelector(selector: string): HtmlElement;
|
|
1569
|
+
querySelectorAll(selector: string): HtmlElement[];
|
|
1570
|
+
private querySelectorImpl;
|
|
1682
1571
|
/**
|
|
1683
|
-
*
|
|
1572
|
+
* Visit all nodes from this node and down. Depth first.
|
|
1684
1573
|
*
|
|
1685
1574
|
* @internal
|
|
1686
|
-
* @param obj - Object with metadata to load
|
|
1687
|
-
* @param filename - Optional filename used when presenting validation error
|
|
1688
1575
|
*/
|
|
1689
|
-
|
|
1576
|
+
visitDepthFirst(callback: (node: HtmlElement) => void): void;
|
|
1690
1577
|
/**
|
|
1691
|
-
*
|
|
1578
|
+
* Evaluates callbackk on all descendants, returning true if any are true.
|
|
1692
1579
|
*
|
|
1693
1580
|
* @internal
|
|
1694
|
-
* @param filename - Filename to load
|
|
1695
1581
|
*/
|
|
1696
|
-
|
|
1582
|
+
someChildren(callback: (node: HtmlElement) => boolean): boolean;
|
|
1697
1583
|
/**
|
|
1698
|
-
*
|
|
1699
|
-
* the global metadata is returned or null if no global is present.
|
|
1584
|
+
* Evaluates callbackk on all descendants, returning true if all are true.
|
|
1700
1585
|
*
|
|
1701
|
-
* @
|
|
1702
|
-
* @returns A shallow copy of metadata.
|
|
1586
|
+
* @internal
|
|
1703
1587
|
*/
|
|
1704
|
-
|
|
1588
|
+
everyChildren(callback: (node: HtmlElement) => boolean): boolean;
|
|
1705
1589
|
/**
|
|
1706
|
-
*
|
|
1590
|
+
* Visit all nodes from this node and down. Breadth first.
|
|
1707
1591
|
*
|
|
1708
|
-
*
|
|
1592
|
+
* The first node for which the callback evaluates to true is returned.
|
|
1593
|
+
*
|
|
1594
|
+
* @internal
|
|
1709
1595
|
*/
|
|
1710
|
-
|
|
1596
|
+
find(callback: (node: HtmlElement) => boolean): HtmlElement | null;
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
declare class DOMTree {
|
|
1600
|
+
readonly root: HtmlElement;
|
|
1601
|
+
private active;
|
|
1602
|
+
doctype: string | null;
|
|
1603
|
+
constructor(location: Location);
|
|
1604
|
+
pushActive(node: HtmlElement): void;
|
|
1605
|
+
popActive(): void;
|
|
1606
|
+
getActive(): HtmlElement;
|
|
1711
1607
|
/**
|
|
1712
|
-
*
|
|
1713
|
-
*
|
|
1714
|
-
* @public
|
|
1608
|
+
* Resolve dynamic meta expressions.
|
|
1715
1609
|
*/
|
|
1716
|
-
|
|
1717
|
-
|
|
1610
|
+
resolveMeta(table: MetaTable): void;
|
|
1611
|
+
getElementsByTagName(tagName: string): HtmlElement[];
|
|
1612
|
+
visitDepthFirst(callback: (node: HtmlElement) => void): void;
|
|
1613
|
+
find(callback: (node: HtmlElement) => boolean): HtmlElement | null;
|
|
1614
|
+
querySelector(selector: string): HtmlElement;
|
|
1615
|
+
querySelectorAll(selector: string): HtmlElement[];
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
/**
|
|
1619
|
+
* Represents a text in the HTML document.
|
|
1620
|
+
*
|
|
1621
|
+
* Text nodes are appended as children of `HtmlElement` and cannot have childen
|
|
1622
|
+
* of its own.
|
|
1623
|
+
*
|
|
1624
|
+
* @public
|
|
1625
|
+
*/
|
|
1626
|
+
declare class TextNode extends DOMNode {
|
|
1627
|
+
private readonly text;
|
|
1718
1628
|
/**
|
|
1719
|
-
*
|
|
1629
|
+
* @param text - Text to add. When a `DynamicValue` is used the expression is
|
|
1630
|
+
* used as "text".
|
|
1631
|
+
* @param location - Source code location of this node.
|
|
1720
1632
|
*/
|
|
1721
|
-
|
|
1633
|
+
constructor(text: string | DynamicValue, location: Location);
|
|
1722
1634
|
/**
|
|
1723
|
-
*
|
|
1635
|
+
* Get the text from node.
|
|
1724
1636
|
*/
|
|
1725
|
-
|
|
1637
|
+
get textContent(): string;
|
|
1726
1638
|
/**
|
|
1727
|
-
*
|
|
1728
|
-
* global, e.g. to assign global attributes.
|
|
1639
|
+
* Flag set to true if the attribute value is static.
|
|
1729
1640
|
*/
|
|
1730
|
-
|
|
1731
|
-
private mergeElement;
|
|
1641
|
+
get isStatic(): boolean;
|
|
1732
1642
|
/**
|
|
1733
|
-
*
|
|
1643
|
+
* Flag set to true if the attribute value is dynamic.
|
|
1734
1644
|
*/
|
|
1735
|
-
|
|
1645
|
+
get isDynamic(): boolean;
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1648
|
+
interface PermittedGroup {
|
|
1649
|
+
exclude?: string | string[];
|
|
1650
|
+
}
|
|
1651
|
+
declare type CategoryOrTag = string;
|
|
1652
|
+
declare type PropertyExpression = string | [string, any];
|
|
1653
|
+
declare type PermittedEntry = CategoryOrTag | PermittedGroup | Array<CategoryOrTag | PermittedGroup>;
|
|
1654
|
+
declare type Permitted = PermittedEntry[];
|
|
1655
|
+
declare type PermittedOrder = string[];
|
|
1656
|
+
declare type RequiredAncestors = string[];
|
|
1657
|
+
declare type RequiredContent = string[];
|
|
1658
|
+
declare enum TextContent {
|
|
1659
|
+
NONE = "none",
|
|
1660
|
+
DEFAULT = "default",
|
|
1661
|
+
REQUIRED = "required",
|
|
1662
|
+
ACCESSIBLE = "accessible"
|
|
1663
|
+
}
|
|
1664
|
+
/**
|
|
1665
|
+
* Callback for the `allowed` property of `MetaAttribute`. It takes a node and
|
|
1666
|
+
* should return `null` if there is no errors and a string with an error
|
|
1667
|
+
* description if there is an error.
|
|
1668
|
+
*
|
|
1669
|
+
* @public
|
|
1670
|
+
*/
|
|
1671
|
+
declare type MetaAttributeAllowedCallback = (node: HtmlElement) => string | null | undefined;
|
|
1672
|
+
/**
|
|
1673
|
+
* @public
|
|
1674
|
+
*/
|
|
1675
|
+
interface MetaAttribute {
|
|
1676
|
+
allowed?: MetaAttributeAllowedCallback;
|
|
1677
|
+
boolean?: boolean;
|
|
1678
|
+
deprecated?: boolean | string;
|
|
1679
|
+
enum?: Array<string | RegExp>;
|
|
1680
|
+
list?: boolean;
|
|
1681
|
+
omit?: boolean;
|
|
1682
|
+
required?: boolean;
|
|
1683
|
+
}
|
|
1684
|
+
declare type PermittedAttribute = Record<string, MetaAttribute | Array<string | RegExp> | null>;
|
|
1685
|
+
interface DeprecatedElement {
|
|
1686
|
+
message?: string;
|
|
1687
|
+
documentation?: string;
|
|
1688
|
+
source?: string;
|
|
1689
|
+
}
|
|
1690
|
+
/**
|
|
1691
|
+
* @public
|
|
1692
|
+
*/
|
|
1693
|
+
interface MetaData {
|
|
1694
|
+
inherit?: string;
|
|
1695
|
+
metadata?: boolean | PropertyExpression;
|
|
1696
|
+
flow?: boolean | PropertyExpression;
|
|
1697
|
+
sectioning?: boolean | PropertyExpression;
|
|
1698
|
+
heading?: boolean | PropertyExpression;
|
|
1699
|
+
phrasing?: boolean | PropertyExpression;
|
|
1700
|
+
embedded?: boolean | PropertyExpression;
|
|
1701
|
+
interactive?: boolean | PropertyExpression;
|
|
1702
|
+
deprecated?: boolean | string | DeprecatedElement;
|
|
1703
|
+
foreign?: boolean;
|
|
1704
|
+
void?: boolean;
|
|
1705
|
+
transparent?: boolean | string[];
|
|
1706
|
+
implicitClosed?: string[];
|
|
1707
|
+
scriptSupporting?: boolean;
|
|
1708
|
+
form?: boolean;
|
|
1709
|
+
labelable?: boolean | PropertyExpression;
|
|
1710
|
+
deprecatedAttributes?: string[];
|
|
1711
|
+
requiredAttributes?: string[];
|
|
1712
|
+
attributes?: PermittedAttribute;
|
|
1713
|
+
permittedContent?: Permitted;
|
|
1714
|
+
permittedDescendants?: Permitted;
|
|
1715
|
+
permittedOrder?: PermittedOrder;
|
|
1716
|
+
permittedParent?: Permitted;
|
|
1717
|
+
requiredAncestors?: RequiredAncestors;
|
|
1718
|
+
requiredContent?: RequiredContent;
|
|
1719
|
+
textContent?: TextContent | `${TextContent}`;
|
|
1720
|
+
}
|
|
1721
|
+
/**
|
|
1722
|
+
* Properties listed here can be used to reverse search elements with the given
|
|
1723
|
+
* property enabled. See [[MetaTable.getTagsWithProperty]].
|
|
1724
|
+
*/
|
|
1725
|
+
declare type MetaLookupableProperty = "metadata" | "flow" | "sectioning" | "heading" | "phrasing" | "embedded" | "interactive" | "deprecated" | "foreign" | "void" | "transparent" | "scriptSupporting" | "form" | "labelable";
|
|
1726
|
+
/**
|
|
1727
|
+
* Properties listed here can be copied (loaded) onto another element using
|
|
1728
|
+
* [[HtmlElement.loadMeta]].
|
|
1729
|
+
*
|
|
1730
|
+
* @public
|
|
1731
|
+
*/
|
|
1732
|
+
declare const MetaCopyableProperty: Array<keyof MetaElement>;
|
|
1733
|
+
/**
|
|
1734
|
+
* @public
|
|
1735
|
+
*/
|
|
1736
|
+
interface MetaElement extends Omit<MetaData, "deprecatedAttributes" | "requiredAttributes"> {
|
|
1737
|
+
tagName: string;
|
|
1738
|
+
attributes: Record<string, MetaAttribute>;
|
|
1739
|
+
textContent?: TextContent;
|
|
1736
1740
|
}
|
|
1741
|
+
interface MetaDataTable {
|
|
1742
|
+
[tagName: string]: MetaData;
|
|
1743
|
+
}
|
|
1744
|
+
interface ElementTable {
|
|
1745
|
+
[tagName: string]: MetaElement;
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
/**
|
|
1749
|
+
* Helper function to assist IDE with completion and type-checking.
|
|
1750
|
+
*
|
|
1751
|
+
* @public
|
|
1752
|
+
*/
|
|
1753
|
+
declare function defineMetadata(metatable: MetaDataTable): MetaDataTable;
|
|
1754
|
+
|
|
1755
|
+
/**
|
|
1756
|
+
* Helpers when writing element metadata.
|
|
1757
|
+
*
|
|
1758
|
+
* @public
|
|
1759
|
+
*/
|
|
1760
|
+
interface MetadataHelper {
|
|
1761
|
+
/** Returns an error if another attribute is omitted, i.e. it requires another attribute to be present to pass. */
|
|
1762
|
+
allowedIfAttributeIsPresent(...attr: string[]): MetaAttributeAllowedCallback;
|
|
1763
|
+
/** Returns an error if another attribute is present, i.e. it requires another attribute to be omitted to pass. */
|
|
1764
|
+
allowedIfAttributeIsAbsent(...attr: string[]): MetaAttributeAllowedCallback;
|
|
1765
|
+
/** Returns an error if another attribute does not have one of the listed values */
|
|
1766
|
+
allowedIfAttributeHasValue(attr: string, value: string[], options?: {
|
|
1767
|
+
defaultValue?: string | null;
|
|
1768
|
+
}): MetaAttributeAllowedCallback;
|
|
1769
|
+
}
|
|
1770
|
+
declare const metadataHelper: MetadataHelper;
|
|
1737
1771
|
|
|
1738
1772
|
/**
|
|
1739
1773
|
* @public
|
|
@@ -2396,4 +2430,4 @@ declare type Formatter = (results: Result[]) => string;
|
|
|
2396
2430
|
*/
|
|
2397
2431
|
declare function getFormatter(name: string): Formatter | null;
|
|
2398
2432
|
|
|
2399
|
-
export {
|
|
2433
|
+
export { TokenEvent as $, AttributeData as A, Result as B, Config as C, DynamicValue as D, EventDump as E, DeferredMessage as F, TransformContext as G, HtmlValidate as H, Transformer as I, TemplateExtractor as J, Plugin as K, Location as L, MetaData as M, NodeClosed as N, Parser as O, ProcessElementContext as P, ruleExists as Q, Rule as R, Severity as S, TextNode as T, UserError as U, EventHandler as V, WrappedError as W, EventCallback as X, Event as Y, ConfigReadyEvent as Z, SourceReadyEvent as _, ConfigData as a, TagStartEvent as a0, TagOpenEvent as a1, TagEndEvent as a2, TagCloseEvent as a3, TagReadyEvent as a4, ElementReadyEvent as a5, AttributeEvent as a6, WhitespaceEvent as a7, ConditionalEvent as a8, DirectiveEvent as a9, DoctypeEvent as aa, DOMLoadEvent as ab, DOMReadyEvent as ac, TriggerEventMap as ad, ListenEventMap as ae, FileSystemConfigLoader as af, Formatter as ag, getFormatter as ah, compatibilityCheck as ai, CompatibilityOptions as aj, ConfigError as b, ConfigLoader as c, StaticConfigLoader as d, HtmlElement as e, CSSStyleDeclaration as f, TokenDump as g, SchemaValidationError as h, NestedError as i, MetaDataTable as j, MetaElement as k, MetaAttribute as l, MetaAttributeAllowedCallback as m, MetaTable as n, MetaCopyableProperty as o, presets as p, defineMetadata as q, metadataHelper as r, RuleDocumentation as s, classifyNodeText as t, TextClassification as u, version as v, Source as w, Report as x, Reporter as y, Message as z };
|