pro-editor-schema 0.2.2 → 0.2.21
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/dist/index.d.mts +25 -17
- package/dist/index.d.ts +25 -17
- package/dist/index.js +214 -104
- package/dist/index.mjs +213 -103
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
type SchemaKind = "element" | "atom" | "inline";
|
|
2
2
|
type FreeAttribute = string;
|
|
3
|
-
type RestrictedAttribute = {
|
|
3
|
+
type RestrictedAttribute<T = readonly string[]> = {
|
|
4
4
|
name: string;
|
|
5
|
-
values:
|
|
5
|
+
values: T;
|
|
6
6
|
defaultValue: string;
|
|
7
7
|
};
|
|
8
|
-
type AttributeDefinition = FreeAttribute | RestrictedAttribute
|
|
8
|
+
type AttributeDefinition<T = readonly string[]> = FreeAttribute | RestrictedAttribute<T>;
|
|
9
9
|
type AllowedChildren = {
|
|
10
10
|
code: SchemaCode;
|
|
11
11
|
required: boolean;
|
|
12
12
|
};
|
|
13
|
-
type Schema = {
|
|
13
|
+
type Schema<TRequiredAttributes = readonly AttributeDefinition[], TOptionalAttributes = readonly AttributeDefinition[]> = {
|
|
14
14
|
code: SchemaCode;
|
|
15
15
|
kind: SchemaKind;
|
|
16
16
|
tag: string;
|
|
17
|
-
requiredAttributes:
|
|
18
|
-
optionalAttributes:
|
|
17
|
+
requiredAttributes: TRequiredAttributes;
|
|
18
|
+
optionalAttributes: TOptionalAttributes;
|
|
19
19
|
defaultChildCode?: SchemaCode;
|
|
20
20
|
allowedChildrenCodes: AllowedChildren[];
|
|
21
|
+
matchesElement?: (element: Element) => boolean;
|
|
21
22
|
};
|
|
22
23
|
type SchemaCode = ElementSchemaCode | InlineSchemaCode | AtomSchemaCode;
|
|
23
24
|
type ElementSchemaCode = "referenceBibliomixed" | "referenceBibliography" | "bibliodiv" | "degrees" | "email" | "equation" | "fignote" | "figsource" | "firstname" | "footnote" | "footnoteno" | "honorific" | "img" | "informalfigure" | "keyword" | "label1" | "li" | "line" | "lrh" | "math" | "mathphrase" | "merror" | "mfrac" | "mi" | "mmultiscripts" | "mn" | "mo" | "mover" | "mpadded" | "mphantom" | "mprescripts" | "mroot" | "mrow" | "ms" | "mspace" | "msqrt" | "mstyle" | "msub" | "msubsup" | "msup" | "mtable" | "mtd" | "mtext" | "mtr" | "munder" | "munderover" | "olink" | "org" | "orgname" | "para" | "punc" | "rrh" | "source1" | "speaker" | "subtitle1" | "surname" | "tag" | "tblfn" | "tblsource" | "thead" | "title1" | "token" | "tp" | "abstract1" | "affiliation" | "alttext" | "appendix" | "author" | "authorgroup" | "blockquote" | "caption1" | "chapter" | "dialogue" | "epigraph" | "figure1" | "footnoteSection" | "heading" | "imageobject" | "info1" | "keywordset" | "mediaobject" | "ol" | "personname" | "poem" | "sidebar" | "table" | "table1" | "tbody" | "td" | "tgroup" | "tr" | "ul";
|
|
24
|
-
type AtomSchemaCode = "indexterm" | "primary" | "secondary" | "tertiary" | "quaternary" | "bookmark" | "see" | "commentQuerySection" | "comment" | "content" | "query" | "reply" | "deletion" | "emphasis" | "highlightmark" | "i" | "insertion" | "sc" | "strike" | "sub" | "sup" | "u" | "b" | "referenceMark";
|
|
25
|
+
type AtomSchemaCode = "indexterm" | "primary" | "secondary" | "tertiary" | "quaternary" | "bookmark" | "see" | "commentQuerySection" | "comment" | "content" | "query" | "reply" | "deletion" | "emphasis" | "highlightmark" | "i" | "insertion" | "sc" | "strike" | "sub" | "sup" | "u" | "b" | "referenceMark" | "abbreviation";
|
|
25
26
|
type InlineSchemaCode = "footnote1" | "inlineequation" | "link" | "uri" | "phrase";
|
|
26
27
|
|
|
27
28
|
declare const SCHEMAS: Record<SchemaCode, Schema>;
|
|
@@ -30,18 +31,25 @@ declare const isTrackChangesSchema: (schema: Schema) => boolean;
|
|
|
30
31
|
declare const isIgnoredAttribute: (attribute: string) => boolean;
|
|
31
32
|
declare const isIgnoredElement: (element: Element) => boolean;
|
|
32
33
|
declare const isIgnoredValidation: (code: SchemaCode) => boolean;
|
|
33
|
-
declare const findSchemaByCode: (code: SchemaCode) => Schema
|
|
34
|
-
declare const findSchemaByTagName: (tagName: string) => Schema[];
|
|
34
|
+
declare const findSchemaByCode: (code: SchemaCode) => Schema;
|
|
35
35
|
declare const findSchemaByElement: (element: Element) => Schema | undefined;
|
|
36
36
|
declare const isAttributeRestricted: (attr: AttributeDefinition) => attr is RestrictedAttribute;
|
|
37
37
|
declare const getAttributeName: (attribute: AttributeDefinition) => string;
|
|
38
|
-
declare const findAttributeDefinitionByName: (definitions: AttributeDefinition[], name: string) => AttributeDefinition | undefined;
|
|
38
|
+
declare const findAttributeDefinitionByName: (definitions: readonly AttributeDefinition[], name: string) => AttributeDefinition | undefined;
|
|
39
39
|
|
|
40
|
-
type
|
|
40
|
+
type AttributeValue<TAttribute extends AttributeDefinition> = TAttribute extends string ? string : TAttribute extends RestrictedAttribute<infer TValues> ? TValues extends readonly string[] ? TValues[number] : string : never;
|
|
41
|
+
type SchemaAttributes<TSchema extends Schema> = TSchema extends Schema<infer TRequired extends readonly AttributeDefinition[], infer TOptional extends readonly AttributeDefinition[]> ? {
|
|
42
|
+
[TAttribute in TRequired[number] as TAttribute extends string ? TAttribute : TAttribute extends RestrictedAttribute ? TAttribute["name"] : never]: AttributeValue<TAttribute>;
|
|
43
|
+
} & {
|
|
44
|
+
[TAttribute in TOptional[number] as TAttribute extends string ? TAttribute : TAttribute extends RestrictedAttribute ? TAttribute["name"] : never]?: AttributeValue<TAttribute>;
|
|
45
|
+
} : never;
|
|
46
|
+
type CreateElementParams<TSchema extends Schema> = {
|
|
41
47
|
schemaCode: SchemaCode;
|
|
42
|
-
attributes:
|
|
48
|
+
attributes: SchemaAttributes<TSchema>;
|
|
43
49
|
};
|
|
44
|
-
declare const createElement: ({ schemaCode, attributes, }: CreateElementParams) => HTMLElement;
|
|
50
|
+
declare const createElement: <TSchema extends Schema>({ schemaCode, attributes, }: CreateElementParams<TSchema>) => HTMLElement;
|
|
51
|
+
|
|
52
|
+
declare const ElementLabel: Record<SchemaCode, string>;
|
|
45
53
|
|
|
46
54
|
declare const IGNORED_ELEMENT_SELECTORS: string[];
|
|
47
55
|
declare const IGNORED_VALIDATION_ELEMENT_SELECTORS: SchemaCode[];
|
|
@@ -68,15 +76,15 @@ declare const FIGURE_PLACEMENT_ATTRIBUTE = "data-figure-placement";
|
|
|
68
76
|
declare const LAYOUT_CELL_WIDTH_ATTRIBUTE = "data-cell-width";
|
|
69
77
|
declare const LAYOUT_TABLE_ORIENTATION_ATTRIBUTE = "data-table-orientation";
|
|
70
78
|
declare const LAYOUT_TABLE_PLACEMENT_ATTRIBUTE = "data-table-placement";
|
|
71
|
-
declare const LAYOUT_ATTRIBUTES:
|
|
79
|
+
declare const LAYOUT_ATTRIBUTES: readonly ["data-alignment", "data-left-indent", "data-right-indent", "data-special-indent", "data-space-above", "data-space-below", "data-indent-type", "data-layout-user", "data-paragraph-style"];
|
|
72
80
|
declare const TRACK_CHANGES_ATTR_DATA_USERNAME = "data-username";
|
|
73
81
|
declare const TRACK_CHANGES_ATTR_DATA_USERID = "data-userid";
|
|
74
82
|
declare const TRACK_CHANGES_ATTR_DATA_TIME = "data-time";
|
|
75
83
|
declare const TRACK_CHANGES_ATTR_DATA_DATE = "data-date";
|
|
76
|
-
declare const TRACK_CHANGES_ATTRS:
|
|
84
|
+
declare const TRACK_CHANGES_ATTRS: readonly ["data-username", "data-userid", "data-time", "data-date"];
|
|
77
85
|
declare const ELE_ID_ATTRIBUTE = "ele-id";
|
|
78
86
|
declare const STORE_ATTRIBUTE = "store";
|
|
79
|
-
declare const ID_ATTRS:
|
|
87
|
+
declare const ID_ATTRS: readonly ["store", "ele-id"];
|
|
80
88
|
|
|
81
89
|
declare const ELEMENT_SCHEMAS: Record<ElementSchemaCode, Schema>;
|
|
82
90
|
|
|
@@ -107,4 +115,4 @@ type ValidationError = {
|
|
|
107
115
|
*/
|
|
108
116
|
declare const validateXml: (xml: Element, elementsToLink: string[], linkElements: string[], schemasToValidateAgainst: SchemaCode[]) => ValidationError[];
|
|
109
117
|
|
|
110
|
-
export { ALIGNMENT_ATTRIBUTE, ATOM_SCHEMAS, type AllowedChildren, type AtomSchemaCode, type AttributeDefinition, DEPENDENT_FORBIDDEN_ELEMENTS, ELEMENT_SCHEMAS, ELE_ID_ATTRIBUTE, type ElementSchemaCode, FIGURE_PLACEMENT_ATTRIBUTE, type FreeAttribute, ID_ATTRS, IGNORED_ATTRIBUTES, IGNORED_ATTRIBUTES_STARTS_WITH, IGNORED_ELEMENT_SELECTORS, IGNORED_VALIDATION_ELEMENT_SELECTORS, INDENT_TYPE_ATTRIBUTE, INLINE_ELEMENT_SCHEMAS, type InlineSchemaCode, LAYOUT_ATTRIBUTES, LAYOUT_CELL_WIDTH_ATTRIBUTE, LAYOUT_TABLE_ORIENTATION_ATTRIBUTE, LAYOUT_TABLE_PLACEMENT_ATTRIBUTE, LAYOUT_USER_ATTRIBUTE, LEFT_INDENT_ATTRIBUTE, RIGHT_INDENT_ATTRIBUTE, type RestrictedAttribute, SCHEMAS, SPACE_ABOVE_ATTRIBUTE, SPACE_BELOW_ATTRIBUTE, SPECIAL_INDENT_ATTRIBUTE, STORE_ATTRIBUTE, STYLE_NAME_ATTRIBUTE, type Schema, type SchemaCode, type SchemaKind, TRACK_CHANGES_ATTRS, TRACK_CHANGES_ATTR_DATA_DATE, TRACK_CHANGES_ATTR_DATA_TIME, TRACK_CHANGES_ATTR_DATA_USERID, TRACK_CHANGES_ATTR_DATA_USERNAME, type ValidationError, type ValidationErrorKind, type ValidationErrorLevel, createElement, findAttributeDefinitionByName, findSchemaByCode, findSchemaByElement,
|
|
118
|
+
export { ALIGNMENT_ATTRIBUTE, ATOM_SCHEMAS, type AllowedChildren, type AtomSchemaCode, type AttributeDefinition, DEPENDENT_FORBIDDEN_ELEMENTS, ELEMENT_SCHEMAS, ELE_ID_ATTRIBUTE, ElementLabel, type ElementSchemaCode, FIGURE_PLACEMENT_ATTRIBUTE, type FreeAttribute, ID_ATTRS, IGNORED_ATTRIBUTES, IGNORED_ATTRIBUTES_STARTS_WITH, IGNORED_ELEMENT_SELECTORS, IGNORED_VALIDATION_ELEMENT_SELECTORS, INDENT_TYPE_ATTRIBUTE, INLINE_ELEMENT_SCHEMAS, type InlineSchemaCode, LAYOUT_ATTRIBUTES, LAYOUT_CELL_WIDTH_ATTRIBUTE, LAYOUT_TABLE_ORIENTATION_ATTRIBUTE, LAYOUT_TABLE_PLACEMENT_ATTRIBUTE, LAYOUT_USER_ATTRIBUTE, LEFT_INDENT_ATTRIBUTE, RIGHT_INDENT_ATTRIBUTE, type RestrictedAttribute, SCHEMAS, SPACE_ABOVE_ATTRIBUTE, SPACE_BELOW_ATTRIBUTE, SPECIAL_INDENT_ATTRIBUTE, STORE_ATTRIBUTE, STYLE_NAME_ATTRIBUTE, type Schema, type SchemaCode, type SchemaKind, TRACK_CHANGES_ATTRS, TRACK_CHANGES_ATTR_DATA_DATE, TRACK_CHANGES_ATTR_DATA_TIME, TRACK_CHANGES_ATTR_DATA_USERID, TRACK_CHANGES_ATTR_DATA_USERNAME, type ValidationError, type ValidationErrorKind, type ValidationErrorLevel, createElement, findAttributeDefinitionByName, findSchemaByCode, findSchemaByElement, getAttributeName, isAttributeRestricted, isIgnoredAttribute, isIgnoredElement, isIgnoredValidation, isTrackChangesSchema, validateXml };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
type SchemaKind = "element" | "atom" | "inline";
|
|
2
2
|
type FreeAttribute = string;
|
|
3
|
-
type RestrictedAttribute = {
|
|
3
|
+
type RestrictedAttribute<T = readonly string[]> = {
|
|
4
4
|
name: string;
|
|
5
|
-
values:
|
|
5
|
+
values: T;
|
|
6
6
|
defaultValue: string;
|
|
7
7
|
};
|
|
8
|
-
type AttributeDefinition = FreeAttribute | RestrictedAttribute
|
|
8
|
+
type AttributeDefinition<T = readonly string[]> = FreeAttribute | RestrictedAttribute<T>;
|
|
9
9
|
type AllowedChildren = {
|
|
10
10
|
code: SchemaCode;
|
|
11
11
|
required: boolean;
|
|
12
12
|
};
|
|
13
|
-
type Schema = {
|
|
13
|
+
type Schema<TRequiredAttributes = readonly AttributeDefinition[], TOptionalAttributes = readonly AttributeDefinition[]> = {
|
|
14
14
|
code: SchemaCode;
|
|
15
15
|
kind: SchemaKind;
|
|
16
16
|
tag: string;
|
|
17
|
-
requiredAttributes:
|
|
18
|
-
optionalAttributes:
|
|
17
|
+
requiredAttributes: TRequiredAttributes;
|
|
18
|
+
optionalAttributes: TOptionalAttributes;
|
|
19
19
|
defaultChildCode?: SchemaCode;
|
|
20
20
|
allowedChildrenCodes: AllowedChildren[];
|
|
21
|
+
matchesElement?: (element: Element) => boolean;
|
|
21
22
|
};
|
|
22
23
|
type SchemaCode = ElementSchemaCode | InlineSchemaCode | AtomSchemaCode;
|
|
23
24
|
type ElementSchemaCode = "referenceBibliomixed" | "referenceBibliography" | "bibliodiv" | "degrees" | "email" | "equation" | "fignote" | "figsource" | "firstname" | "footnote" | "footnoteno" | "honorific" | "img" | "informalfigure" | "keyword" | "label1" | "li" | "line" | "lrh" | "math" | "mathphrase" | "merror" | "mfrac" | "mi" | "mmultiscripts" | "mn" | "mo" | "mover" | "mpadded" | "mphantom" | "mprescripts" | "mroot" | "mrow" | "ms" | "mspace" | "msqrt" | "mstyle" | "msub" | "msubsup" | "msup" | "mtable" | "mtd" | "mtext" | "mtr" | "munder" | "munderover" | "olink" | "org" | "orgname" | "para" | "punc" | "rrh" | "source1" | "speaker" | "subtitle1" | "surname" | "tag" | "tblfn" | "tblsource" | "thead" | "title1" | "token" | "tp" | "abstract1" | "affiliation" | "alttext" | "appendix" | "author" | "authorgroup" | "blockquote" | "caption1" | "chapter" | "dialogue" | "epigraph" | "figure1" | "footnoteSection" | "heading" | "imageobject" | "info1" | "keywordset" | "mediaobject" | "ol" | "personname" | "poem" | "sidebar" | "table" | "table1" | "tbody" | "td" | "tgroup" | "tr" | "ul";
|
|
24
|
-
type AtomSchemaCode = "indexterm" | "primary" | "secondary" | "tertiary" | "quaternary" | "bookmark" | "see" | "commentQuerySection" | "comment" | "content" | "query" | "reply" | "deletion" | "emphasis" | "highlightmark" | "i" | "insertion" | "sc" | "strike" | "sub" | "sup" | "u" | "b" | "referenceMark";
|
|
25
|
+
type AtomSchemaCode = "indexterm" | "primary" | "secondary" | "tertiary" | "quaternary" | "bookmark" | "see" | "commentQuerySection" | "comment" | "content" | "query" | "reply" | "deletion" | "emphasis" | "highlightmark" | "i" | "insertion" | "sc" | "strike" | "sub" | "sup" | "u" | "b" | "referenceMark" | "abbreviation";
|
|
25
26
|
type InlineSchemaCode = "footnote1" | "inlineequation" | "link" | "uri" | "phrase";
|
|
26
27
|
|
|
27
28
|
declare const SCHEMAS: Record<SchemaCode, Schema>;
|
|
@@ -30,18 +31,25 @@ declare const isTrackChangesSchema: (schema: Schema) => boolean;
|
|
|
30
31
|
declare const isIgnoredAttribute: (attribute: string) => boolean;
|
|
31
32
|
declare const isIgnoredElement: (element: Element) => boolean;
|
|
32
33
|
declare const isIgnoredValidation: (code: SchemaCode) => boolean;
|
|
33
|
-
declare const findSchemaByCode: (code: SchemaCode) => Schema
|
|
34
|
-
declare const findSchemaByTagName: (tagName: string) => Schema[];
|
|
34
|
+
declare const findSchemaByCode: (code: SchemaCode) => Schema;
|
|
35
35
|
declare const findSchemaByElement: (element: Element) => Schema | undefined;
|
|
36
36
|
declare const isAttributeRestricted: (attr: AttributeDefinition) => attr is RestrictedAttribute;
|
|
37
37
|
declare const getAttributeName: (attribute: AttributeDefinition) => string;
|
|
38
|
-
declare const findAttributeDefinitionByName: (definitions: AttributeDefinition[], name: string) => AttributeDefinition | undefined;
|
|
38
|
+
declare const findAttributeDefinitionByName: (definitions: readonly AttributeDefinition[], name: string) => AttributeDefinition | undefined;
|
|
39
39
|
|
|
40
|
-
type
|
|
40
|
+
type AttributeValue<TAttribute extends AttributeDefinition> = TAttribute extends string ? string : TAttribute extends RestrictedAttribute<infer TValues> ? TValues extends readonly string[] ? TValues[number] : string : never;
|
|
41
|
+
type SchemaAttributes<TSchema extends Schema> = TSchema extends Schema<infer TRequired extends readonly AttributeDefinition[], infer TOptional extends readonly AttributeDefinition[]> ? {
|
|
42
|
+
[TAttribute in TRequired[number] as TAttribute extends string ? TAttribute : TAttribute extends RestrictedAttribute ? TAttribute["name"] : never]: AttributeValue<TAttribute>;
|
|
43
|
+
} & {
|
|
44
|
+
[TAttribute in TOptional[number] as TAttribute extends string ? TAttribute : TAttribute extends RestrictedAttribute ? TAttribute["name"] : never]?: AttributeValue<TAttribute>;
|
|
45
|
+
} : never;
|
|
46
|
+
type CreateElementParams<TSchema extends Schema> = {
|
|
41
47
|
schemaCode: SchemaCode;
|
|
42
|
-
attributes:
|
|
48
|
+
attributes: SchemaAttributes<TSchema>;
|
|
43
49
|
};
|
|
44
|
-
declare const createElement: ({ schemaCode, attributes, }: CreateElementParams) => HTMLElement;
|
|
50
|
+
declare const createElement: <TSchema extends Schema>({ schemaCode, attributes, }: CreateElementParams<TSchema>) => HTMLElement;
|
|
51
|
+
|
|
52
|
+
declare const ElementLabel: Record<SchemaCode, string>;
|
|
45
53
|
|
|
46
54
|
declare const IGNORED_ELEMENT_SELECTORS: string[];
|
|
47
55
|
declare const IGNORED_VALIDATION_ELEMENT_SELECTORS: SchemaCode[];
|
|
@@ -68,15 +76,15 @@ declare const FIGURE_PLACEMENT_ATTRIBUTE = "data-figure-placement";
|
|
|
68
76
|
declare const LAYOUT_CELL_WIDTH_ATTRIBUTE = "data-cell-width";
|
|
69
77
|
declare const LAYOUT_TABLE_ORIENTATION_ATTRIBUTE = "data-table-orientation";
|
|
70
78
|
declare const LAYOUT_TABLE_PLACEMENT_ATTRIBUTE = "data-table-placement";
|
|
71
|
-
declare const LAYOUT_ATTRIBUTES:
|
|
79
|
+
declare const LAYOUT_ATTRIBUTES: readonly ["data-alignment", "data-left-indent", "data-right-indent", "data-special-indent", "data-space-above", "data-space-below", "data-indent-type", "data-layout-user", "data-paragraph-style"];
|
|
72
80
|
declare const TRACK_CHANGES_ATTR_DATA_USERNAME = "data-username";
|
|
73
81
|
declare const TRACK_CHANGES_ATTR_DATA_USERID = "data-userid";
|
|
74
82
|
declare const TRACK_CHANGES_ATTR_DATA_TIME = "data-time";
|
|
75
83
|
declare const TRACK_CHANGES_ATTR_DATA_DATE = "data-date";
|
|
76
|
-
declare const TRACK_CHANGES_ATTRS:
|
|
84
|
+
declare const TRACK_CHANGES_ATTRS: readonly ["data-username", "data-userid", "data-time", "data-date"];
|
|
77
85
|
declare const ELE_ID_ATTRIBUTE = "ele-id";
|
|
78
86
|
declare const STORE_ATTRIBUTE = "store";
|
|
79
|
-
declare const ID_ATTRS:
|
|
87
|
+
declare const ID_ATTRS: readonly ["store", "ele-id"];
|
|
80
88
|
|
|
81
89
|
declare const ELEMENT_SCHEMAS: Record<ElementSchemaCode, Schema>;
|
|
82
90
|
|
|
@@ -107,4 +115,4 @@ type ValidationError = {
|
|
|
107
115
|
*/
|
|
108
116
|
declare const validateXml: (xml: Element, elementsToLink: string[], linkElements: string[], schemasToValidateAgainst: SchemaCode[]) => ValidationError[];
|
|
109
117
|
|
|
110
|
-
export { ALIGNMENT_ATTRIBUTE, ATOM_SCHEMAS, type AllowedChildren, type AtomSchemaCode, type AttributeDefinition, DEPENDENT_FORBIDDEN_ELEMENTS, ELEMENT_SCHEMAS, ELE_ID_ATTRIBUTE, type ElementSchemaCode, FIGURE_PLACEMENT_ATTRIBUTE, type FreeAttribute, ID_ATTRS, IGNORED_ATTRIBUTES, IGNORED_ATTRIBUTES_STARTS_WITH, IGNORED_ELEMENT_SELECTORS, IGNORED_VALIDATION_ELEMENT_SELECTORS, INDENT_TYPE_ATTRIBUTE, INLINE_ELEMENT_SCHEMAS, type InlineSchemaCode, LAYOUT_ATTRIBUTES, LAYOUT_CELL_WIDTH_ATTRIBUTE, LAYOUT_TABLE_ORIENTATION_ATTRIBUTE, LAYOUT_TABLE_PLACEMENT_ATTRIBUTE, LAYOUT_USER_ATTRIBUTE, LEFT_INDENT_ATTRIBUTE, RIGHT_INDENT_ATTRIBUTE, type RestrictedAttribute, SCHEMAS, SPACE_ABOVE_ATTRIBUTE, SPACE_BELOW_ATTRIBUTE, SPECIAL_INDENT_ATTRIBUTE, STORE_ATTRIBUTE, STYLE_NAME_ATTRIBUTE, type Schema, type SchemaCode, type SchemaKind, TRACK_CHANGES_ATTRS, TRACK_CHANGES_ATTR_DATA_DATE, TRACK_CHANGES_ATTR_DATA_TIME, TRACK_CHANGES_ATTR_DATA_USERID, TRACK_CHANGES_ATTR_DATA_USERNAME, type ValidationError, type ValidationErrorKind, type ValidationErrorLevel, createElement, findAttributeDefinitionByName, findSchemaByCode, findSchemaByElement,
|
|
118
|
+
export { ALIGNMENT_ATTRIBUTE, ATOM_SCHEMAS, type AllowedChildren, type AtomSchemaCode, type AttributeDefinition, DEPENDENT_FORBIDDEN_ELEMENTS, ELEMENT_SCHEMAS, ELE_ID_ATTRIBUTE, ElementLabel, type ElementSchemaCode, FIGURE_PLACEMENT_ATTRIBUTE, type FreeAttribute, ID_ATTRS, IGNORED_ATTRIBUTES, IGNORED_ATTRIBUTES_STARTS_WITH, IGNORED_ELEMENT_SELECTORS, IGNORED_VALIDATION_ELEMENT_SELECTORS, INDENT_TYPE_ATTRIBUTE, INLINE_ELEMENT_SCHEMAS, type InlineSchemaCode, LAYOUT_ATTRIBUTES, LAYOUT_CELL_WIDTH_ATTRIBUTE, LAYOUT_TABLE_ORIENTATION_ATTRIBUTE, LAYOUT_TABLE_PLACEMENT_ATTRIBUTE, LAYOUT_USER_ATTRIBUTE, LEFT_INDENT_ATTRIBUTE, RIGHT_INDENT_ATTRIBUTE, type RestrictedAttribute, SCHEMAS, SPACE_ABOVE_ATTRIBUTE, SPACE_BELOW_ATTRIBUTE, SPECIAL_INDENT_ATTRIBUTE, STORE_ATTRIBUTE, STYLE_NAME_ATTRIBUTE, type Schema, type SchemaCode, type SchemaKind, TRACK_CHANGES_ATTRS, TRACK_CHANGES_ATTR_DATA_DATE, TRACK_CHANGES_ATTR_DATA_TIME, TRACK_CHANGES_ATTR_DATA_USERID, TRACK_CHANGES_ATTR_DATA_USERNAME, type ValidationError, type ValidationErrorKind, type ValidationErrorLevel, createElement, findAttributeDefinitionByName, findSchemaByCode, findSchemaByElement, getAttributeName, isAttributeRestricted, isIgnoredAttribute, isIgnoredElement, isIgnoredValidation, isTrackChangesSchema, validateXml };
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,7 @@ __export(index_exports, {
|
|
|
25
25
|
DEPENDENT_FORBIDDEN_ELEMENTS: () => DEPENDENT_FORBIDDEN_ELEMENTS,
|
|
26
26
|
ELEMENT_SCHEMAS: () => ELEMENT_SCHEMAS,
|
|
27
27
|
ELE_ID_ATTRIBUTE: () => ELE_ID_ATTRIBUTE,
|
|
28
|
+
ElementLabel: () => ElementLabel,
|
|
28
29
|
FIGURE_PLACEMENT_ATTRIBUTE: () => FIGURE_PLACEMENT_ATTRIBUTE,
|
|
29
30
|
ID_ATTRS: () => ID_ATTRS,
|
|
30
31
|
IGNORED_ATTRIBUTES: () => IGNORED_ATTRIBUTES,
|
|
@@ -55,7 +56,6 @@ __export(index_exports, {
|
|
|
55
56
|
findAttributeDefinitionByName: () => findAttributeDefinitionByName,
|
|
56
57
|
findSchemaByCode: () => findSchemaByCode,
|
|
57
58
|
findSchemaByElement: () => findSchemaByElement,
|
|
58
|
-
findSchemaByTagName: () => findSchemaByTagName,
|
|
59
59
|
getAttributeName: () => getAttributeName,
|
|
60
60
|
isAttributeRestricted: () => isAttributeRestricted,
|
|
61
61
|
isIgnoredAttribute: () => isIgnoredAttribute,
|
|
@@ -67,24 +67,8 @@ __export(index_exports, {
|
|
|
67
67
|
module.exports = __toCommonJS(index_exports);
|
|
68
68
|
|
|
69
69
|
// src/schema/utils/createSchema.ts
|
|
70
|
-
var createSchema = ({
|
|
71
|
-
|
|
72
|
-
kind,
|
|
73
|
-
tag,
|
|
74
|
-
requiredAttributes,
|
|
75
|
-
optionalAttributes,
|
|
76
|
-
defaultChildCode,
|
|
77
|
-
allowedChildrenCodes
|
|
78
|
-
}) => {
|
|
79
|
-
return {
|
|
80
|
-
code,
|
|
81
|
-
kind,
|
|
82
|
-
tag,
|
|
83
|
-
requiredAttributes,
|
|
84
|
-
optionalAttributes,
|
|
85
|
-
defaultChildCode,
|
|
86
|
-
allowedChildrenCodes
|
|
87
|
-
};
|
|
70
|
+
var createSchema = (params) => {
|
|
71
|
+
return params;
|
|
88
72
|
};
|
|
89
73
|
|
|
90
74
|
// src/schema/shared/globalAttributes.ts
|
|
@@ -143,11 +127,13 @@ var ATOM_CODES_ALLOWED_CHILDREN = [
|
|
|
143
127
|
{ code: "commentQuerySection", required: false },
|
|
144
128
|
{ code: "comment", required: false },
|
|
145
129
|
{ code: "query", required: false },
|
|
146
|
-
{ code: "referenceMark", required: false }
|
|
130
|
+
{ code: "referenceMark", required: false },
|
|
131
|
+
{ code: "abbreviation", required: false }
|
|
147
132
|
];
|
|
148
133
|
|
|
149
134
|
// src/schema/elementSchemas/atoms/atomTags.ts
|
|
150
135
|
var B_TAG = "B";
|
|
136
|
+
var ABBR_TAG = "ABBR";
|
|
151
137
|
var I_TAG = "I";
|
|
152
138
|
var U_TAG = "U";
|
|
153
139
|
var SC_TAG = "SC";
|
|
@@ -185,6 +171,7 @@ var COMMENT_QUERY_SECTION_SCHEMA = createSchema({
|
|
|
185
171
|
kind: "atom",
|
|
186
172
|
tag: SPAN_TAG,
|
|
187
173
|
code: "commentQuerySection",
|
|
174
|
+
matchesElement: (element) => element.classList.contains("cmtQurySection"),
|
|
188
175
|
requiredAttributes: [...ID_ATTRS, "id"],
|
|
189
176
|
optionalAttributes: [...TRACK_CHANGES_ATTRS, "title"],
|
|
190
177
|
allowedChildrenCodes: [...ATOM_CODES_ALLOWED_CHILDREN]
|
|
@@ -204,6 +191,7 @@ var DELETION_SCHEMA = createSchema({
|
|
|
204
191
|
code: "deletion",
|
|
205
192
|
kind: "atom",
|
|
206
193
|
tag: SPAN_TAG,
|
|
194
|
+
matchesElement: (element) => element.classList.contains("del"),
|
|
207
195
|
requiredAttributes: [...TRACK_CHANGES_ATTRS, ...ID_ATTRS],
|
|
208
196
|
optionalAttributes: [],
|
|
209
197
|
allowedChildrenCodes: [
|
|
@@ -254,6 +242,7 @@ var INSERTION_SCHEMA = createSchema({
|
|
|
254
242
|
code: "insertion",
|
|
255
243
|
kind: "atom",
|
|
256
244
|
tag: SPAN_TAG,
|
|
245
|
+
matchesElement: (element) => element.classList.contains("ins"),
|
|
257
246
|
requiredAttributes: [...TRACK_CHANGES_ATTRS, ...ID_ATTRS],
|
|
258
247
|
optionalAttributes: [],
|
|
259
248
|
allowedChildrenCodes: [
|
|
@@ -549,6 +538,27 @@ var REFERENCE_MARK_SCHEMA = createSchema({
|
|
|
549
538
|
allowedChildrenCodes: [...ATOM_CODES_ALLOWED_CHILDREN]
|
|
550
539
|
});
|
|
551
540
|
|
|
541
|
+
// src/schema/elementSchemas/atoms/abbr.ts
|
|
542
|
+
var ABBR_SCHEMA = createSchema({
|
|
543
|
+
code: "abbreviation",
|
|
544
|
+
kind: "atom",
|
|
545
|
+
tag: ABBR_TAG,
|
|
546
|
+
requiredAttributes: [
|
|
547
|
+
...ID_ATTRS,
|
|
548
|
+
"title",
|
|
549
|
+
TRACK_CHANGES_ATTR_DATA_TIME,
|
|
550
|
+
TRACK_CHANGES_ATTR_DATA_USERID,
|
|
551
|
+
TRACK_CHANGES_ATTR_DATA_USERNAME,
|
|
552
|
+
{
|
|
553
|
+
name: "data-abbr-action",
|
|
554
|
+
values: ["add", "edit"],
|
|
555
|
+
defaultValue: "add"
|
|
556
|
+
}
|
|
557
|
+
],
|
|
558
|
+
optionalAttributes: [],
|
|
559
|
+
allowedChildrenCodes: [...ATOM_CODES_ALLOWED_CHILDREN]
|
|
560
|
+
});
|
|
561
|
+
|
|
552
562
|
// src/schema/elementSchemas/atoms/index.ts
|
|
553
563
|
var ATOM_SCHEMAS = {
|
|
554
564
|
indexterm: INDEXTERM_SCHEMA,
|
|
@@ -574,7 +584,8 @@ var ATOM_SCHEMAS = {
|
|
|
574
584
|
content: CONTENT_SCHEMA,
|
|
575
585
|
comment: COMMENT_SCHEMA,
|
|
576
586
|
query: QUERY_SCHEMA,
|
|
577
|
-
reply: REPLY_SCHEMA
|
|
587
|
+
reply: REPLY_SCHEMA,
|
|
588
|
+
abbreviation: ABBR_SCHEMA
|
|
578
589
|
};
|
|
579
590
|
|
|
580
591
|
// src/schema/elementSchemas/elements/elementsTags.ts
|
|
@@ -1975,15 +1986,21 @@ var EPIGRAPH_SCHEMA = createSchema({
|
|
|
1975
1986
|
});
|
|
1976
1987
|
|
|
1977
1988
|
// src/schema/elementSchemas/elements/footnoteSection.ts
|
|
1989
|
+
var FOOTNOTE_SECTION_ROLES = ["ch", "bk"];
|
|
1978
1990
|
var FOOTNOTE_SECTION_SCHEMA = createSchema({
|
|
1979
1991
|
code: "footnoteSection",
|
|
1980
1992
|
kind: "element",
|
|
1981
1993
|
tag: SECTION_TAG,
|
|
1994
|
+
matchesElement: (element) => {
|
|
1995
|
+
const role = element.getAttribute("role");
|
|
1996
|
+
if (role && FOOTNOTE_SECTION_ROLES.includes(role)) return true;
|
|
1997
|
+
return element.querySelector(FOOTNOTE_TAG) !== null;
|
|
1998
|
+
},
|
|
1982
1999
|
requiredAttributes: [
|
|
1983
2000
|
...ID_ATTRS,
|
|
1984
2001
|
{
|
|
1985
2002
|
name: "role",
|
|
1986
|
-
values:
|
|
2003
|
+
values: FOOTNOTE_SECTION_ROLES,
|
|
1987
2004
|
defaultValue: "ch"
|
|
1988
2005
|
}
|
|
1989
2006
|
],
|
|
@@ -1996,16 +2013,22 @@ var FOOTNOTE_SECTION_SCHEMA = createSchema({
|
|
|
1996
2013
|
});
|
|
1997
2014
|
|
|
1998
2015
|
// src/schema/elementSchemas/elements/heading.ts
|
|
2016
|
+
var HEADING_ROLES = ["H1", "H2", "H3", "H4", "H5", "H6", "vignette_group"];
|
|
1999
2017
|
var HEADING_SCHEMA = createSchema({
|
|
2000
2018
|
code: "heading",
|
|
2001
2019
|
kind: "element",
|
|
2002
2020
|
tag: SECTION_TAG,
|
|
2021
|
+
matchesElement: (element) => {
|
|
2022
|
+
const role = element.getAttribute("role");
|
|
2023
|
+
if (!role) return false;
|
|
2024
|
+
return HEADING_ROLES.includes(role);
|
|
2025
|
+
},
|
|
2003
2026
|
requiredAttributes: [
|
|
2004
2027
|
...ID_ATTRS,
|
|
2005
2028
|
"xmlid",
|
|
2006
2029
|
{
|
|
2007
2030
|
name: "role",
|
|
2008
|
-
values:
|
|
2031
|
+
values: HEADING_ROLES,
|
|
2009
2032
|
defaultValue: "H1"
|
|
2010
2033
|
}
|
|
2011
2034
|
],
|
|
@@ -2073,7 +2096,6 @@ var MATHPHRASE_SCHEMA = createSchema({
|
|
|
2073
2096
|
requiredAttributes: [ELE_ID_ATTRIBUTE],
|
|
2074
2097
|
optionalAttributes: [],
|
|
2075
2098
|
allowedChildrenCodes: [{ code: MATH_SCHEMA.code, required: true }]
|
|
2076
|
-
// TODO: Should have flag for insertion and deletion
|
|
2077
2099
|
});
|
|
2078
2100
|
|
|
2079
2101
|
// src/schema/elementSchemas/elements/reference/bibliodiv.ts
|
|
@@ -2277,6 +2299,12 @@ var INLINEEQUATION_SCHEMA = createSchema({
|
|
|
2277
2299
|
});
|
|
2278
2300
|
|
|
2279
2301
|
// src/schema/elementSchemas/inlineElements/link.ts
|
|
2302
|
+
var TABLE_LINK_ROLE = "table";
|
|
2303
|
+
var FIGURE_LINK_ROLE = "figure";
|
|
2304
|
+
var EQUATION_LINK_ROLE = "equation";
|
|
2305
|
+
var FOOTNOTE_LINK_ROLE = "footnote";
|
|
2306
|
+
var REFERENCE_LINK_ROLE = "bibr";
|
|
2307
|
+
var CHAPTER_LINK_ROLE = "chapter";
|
|
2280
2308
|
var LINK_SCHEMA = createSchema({
|
|
2281
2309
|
code: "link",
|
|
2282
2310
|
kind: "inline",
|
|
@@ -2284,14 +2312,20 @@ var LINK_SCHEMA = createSchema({
|
|
|
2284
2312
|
requiredAttributes: [
|
|
2285
2313
|
...ID_ATTRS,
|
|
2286
2314
|
"linkend",
|
|
2287
|
-
"data-target-id",
|
|
2288
2315
|
{
|
|
2289
2316
|
name: "role",
|
|
2290
|
-
values: [
|
|
2291
|
-
|
|
2317
|
+
values: [
|
|
2318
|
+
TABLE_LINK_ROLE,
|
|
2319
|
+
FIGURE_LINK_ROLE,
|
|
2320
|
+
EQUATION_LINK_ROLE,
|
|
2321
|
+
FOOTNOTE_LINK_ROLE,
|
|
2322
|
+
REFERENCE_LINK_ROLE,
|
|
2323
|
+
CHAPTER_LINK_ROLE
|
|
2324
|
+
],
|
|
2325
|
+
defaultValue: "bibr"
|
|
2292
2326
|
}
|
|
2293
2327
|
],
|
|
2294
|
-
optionalAttributes: [],
|
|
2328
|
+
optionalAttributes: ["data-target-id"],
|
|
2295
2329
|
allowedChildrenCodes: [...ATOM_CODES_ALLOWED_CHILDREN]
|
|
2296
2330
|
});
|
|
2297
2331
|
|
|
@@ -2371,42 +2405,11 @@ var isIgnoredAttribute = (attribute) => IGNORED_ATTRIBUTES.includes(attribute) |
|
|
|
2371
2405
|
var isIgnoredElement = (element) => IGNORED_ELEMENT_SELECTORS.some((selector) => element.matches(selector));
|
|
2372
2406
|
var isIgnoredValidation = (code) => IGNORED_VALIDATION_ELEMENT_SELECTORS.includes(code);
|
|
2373
2407
|
var findSchemaByCode = (code) => SCHEMAS[code];
|
|
2374
|
-
var findSchemaByTagName = (tagName) => Object.values(SCHEMAS).filter(
|
|
2375
|
-
(schema) => schema.tag === tagName.toUpperCase()
|
|
2376
|
-
);
|
|
2377
2408
|
var findSchemaByElement = (element) => {
|
|
2378
|
-
const
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
const role = element.getAttribute("role");
|
|
2383
|
-
if (tagName === SPAN_TAG) {
|
|
2384
|
-
if (isQueryComment) {
|
|
2385
|
-
return findSchemaByCode("commentQuerySection");
|
|
2386
|
-
}
|
|
2387
|
-
if (isInsertion) {
|
|
2388
|
-
return findSchemaByCode("insertion");
|
|
2389
|
-
}
|
|
2390
|
-
if (isDeletion) {
|
|
2391
|
-
return findSchemaByCode("deletion");
|
|
2392
|
-
}
|
|
2393
|
-
}
|
|
2394
|
-
if (tagName === SECTION_TAG) {
|
|
2395
|
-
if (role) {
|
|
2396
|
-
if (role.startsWith("H")) {
|
|
2397
|
-
return findSchemaByCode("heading");
|
|
2398
|
-
}
|
|
2399
|
-
if (role === "ch" || role === "bk") {
|
|
2400
|
-
return findSchemaByCode("footnoteSection");
|
|
2401
|
-
}
|
|
2402
|
-
}
|
|
2403
|
-
const isFootnoteSectionWithoutRole = element.querySelector(FOOTNOTE_TAG);
|
|
2404
|
-
if (isFootnoteSectionWithoutRole) {
|
|
2405
|
-
return findSchemaByCode("footnoteSection");
|
|
2406
|
-
}
|
|
2407
|
-
}
|
|
2408
|
-
const candidates = findSchemaByTagName(tagName);
|
|
2409
|
-
return candidates[0];
|
|
2409
|
+
const schema = Object.values(SCHEMAS).find(
|
|
2410
|
+
(schema2) => schema2.tag == element.tagName && (!schema2.matchesElement || schema2.matchesElement(element))
|
|
2411
|
+
);
|
|
2412
|
+
return schema;
|
|
2410
2413
|
};
|
|
2411
2414
|
var isAttributeRestricted = (attr) => typeof attr !== "string";
|
|
2412
2415
|
var getAttributeName = (attribute) => typeof attribute === "string" ? attribute.toLowerCase() : attribute.name.toLowerCase();
|
|
@@ -2420,50 +2423,145 @@ var findAttributeDefinitionByName = (definitions, name) => {
|
|
|
2420
2423
|
};
|
|
2421
2424
|
|
|
2422
2425
|
// src/schema/utils/createElement.ts
|
|
2423
|
-
var validateAttributes = (attributes, schema) => {
|
|
2424
|
-
const definitions = [
|
|
2425
|
-
...schema.requiredAttributes,
|
|
2426
|
-
...schema.optionalAttributes
|
|
2427
|
-
];
|
|
2428
|
-
for (const [name, value] of Object.entries(attributes)) {
|
|
2429
|
-
if (value === void 0) {
|
|
2430
|
-
continue;
|
|
2431
|
-
}
|
|
2432
|
-
const definition = findAttributeDefinitionByName(definitions, name);
|
|
2433
|
-
if (!definition) {
|
|
2434
|
-
throw new Error(
|
|
2435
|
-
`Invalid attribute "${name}" for schema "${schema.code}".`
|
|
2436
|
-
);
|
|
2437
|
-
}
|
|
2438
|
-
if (!isAttributeRestricted(definition)) {
|
|
2439
|
-
continue;
|
|
2440
|
-
}
|
|
2441
|
-
if (!definition.values.includes(value)) {
|
|
2442
|
-
throw new Error(
|
|
2443
|
-
`Invalid value "${value}" for attribute "${name}" on schema "${schema.code}". Allowed values: ${definition.values.join(", ")}.`
|
|
2444
|
-
);
|
|
2445
|
-
}
|
|
2446
|
-
}
|
|
2447
|
-
};
|
|
2448
2426
|
var createElement = ({
|
|
2449
2427
|
schemaCode,
|
|
2450
2428
|
attributes
|
|
2451
2429
|
}) => {
|
|
2452
2430
|
const schema = findSchemaByCode(schemaCode);
|
|
2453
|
-
if (!schema) {
|
|
2454
|
-
throw new Error(`Schema not found for code: ${schemaCode}`);
|
|
2455
|
-
}
|
|
2456
|
-
validateAttributes(attributes, schema);
|
|
2457
2431
|
const element = document.createElement(schema.tag.toLowerCase());
|
|
2458
2432
|
for (const [name, value] of Object.entries(attributes)) {
|
|
2459
|
-
if (value
|
|
2460
|
-
continue;
|
|
2461
|
-
}
|
|
2433
|
+
if (!value) continue;
|
|
2462
2434
|
element.setAttribute(name, String(value));
|
|
2463
2435
|
}
|
|
2464
2436
|
return element;
|
|
2465
2437
|
};
|
|
2466
2438
|
|
|
2439
|
+
// src/schema/shared/labelElements.ts
|
|
2440
|
+
var ElementLabel = {
|
|
2441
|
+
referenceBibliomixed: "Reference Bibliomixed",
|
|
2442
|
+
referenceBibliography: "Reference Bibliography",
|
|
2443
|
+
bibliodiv: "Bibliodiv",
|
|
2444
|
+
indexterm: "Indexterm",
|
|
2445
|
+
primary: "Primary",
|
|
2446
|
+
secondary: "Secondary",
|
|
2447
|
+
tertiary: "Tertiary",
|
|
2448
|
+
quaternary: "Quaternary",
|
|
2449
|
+
bookmark: "Bookmark",
|
|
2450
|
+
see: "Cross Reference",
|
|
2451
|
+
commentQuerySection: "Comment/Query",
|
|
2452
|
+
comment: "Comment",
|
|
2453
|
+
content: "Content",
|
|
2454
|
+
query: "Query",
|
|
2455
|
+
reply: "Reply",
|
|
2456
|
+
deletion: "Deletion",
|
|
2457
|
+
emphasis: "Emphasis",
|
|
2458
|
+
highlightmark: "Highlightmark",
|
|
2459
|
+
i: "Italic",
|
|
2460
|
+
insertion: "Insertion",
|
|
2461
|
+
sc: "Small Caps",
|
|
2462
|
+
strike: "Strike",
|
|
2463
|
+
sub: "Subscript",
|
|
2464
|
+
sup: "Superscript",
|
|
2465
|
+
u: "Underline",
|
|
2466
|
+
b: "Bold",
|
|
2467
|
+
referenceMark: "Reference Mark",
|
|
2468
|
+
degrees: "Degrees",
|
|
2469
|
+
email: "Email",
|
|
2470
|
+
equation: "Equation",
|
|
2471
|
+
fignote: "Fignote",
|
|
2472
|
+
figsource: "Figsource",
|
|
2473
|
+
firstname: "Firstname",
|
|
2474
|
+
footnote: "Footnote Marker",
|
|
2475
|
+
footnoteno: "Footnote Number",
|
|
2476
|
+
honorific: "Honorific",
|
|
2477
|
+
img: "Image",
|
|
2478
|
+
informalfigure: "Floating Figure",
|
|
2479
|
+
keyword: "Keyword",
|
|
2480
|
+
label1: "Label",
|
|
2481
|
+
li: "List Item",
|
|
2482
|
+
line: "Line",
|
|
2483
|
+
lrh: "Running Head Left",
|
|
2484
|
+
math: "Math",
|
|
2485
|
+
mathphrase: "Math Phrase",
|
|
2486
|
+
merror: "Math Error",
|
|
2487
|
+
mfrac: "Math Fraction",
|
|
2488
|
+
mi: "Math Identifier",
|
|
2489
|
+
mmultiscripts: "Math Multiscripts",
|
|
2490
|
+
mn: "Math Number",
|
|
2491
|
+
mo: "Math Operator",
|
|
2492
|
+
mover: "Math Over",
|
|
2493
|
+
mpadded: "Math Padded",
|
|
2494
|
+
mphantom: "Math Phantom",
|
|
2495
|
+
mprescripts: "Math Prescripts",
|
|
2496
|
+
mroot: "Math Root",
|
|
2497
|
+
mrow: "Math Row",
|
|
2498
|
+
ms: "Math Space",
|
|
2499
|
+
mspace: "Math Space",
|
|
2500
|
+
msqrt: "Math Square Root",
|
|
2501
|
+
mstyle: "Math Style",
|
|
2502
|
+
msub: "Math Subscript",
|
|
2503
|
+
msubsup: "Math Subscript Superscript",
|
|
2504
|
+
msup: "Math Superscript",
|
|
2505
|
+
mtable: "Math Table",
|
|
2506
|
+
mtd: "Math Table Data",
|
|
2507
|
+
mtext: "Math Text",
|
|
2508
|
+
mtr: "Math Table Row",
|
|
2509
|
+
munder: "Math Under",
|
|
2510
|
+
munderover: "Math Under Over",
|
|
2511
|
+
olink: "Online Link",
|
|
2512
|
+
org: "Org",
|
|
2513
|
+
orgname: "Orgname",
|
|
2514
|
+
para: "Paragraph",
|
|
2515
|
+
punc: "Punctuation",
|
|
2516
|
+
rrh: "Running Head Right",
|
|
2517
|
+
source1: "Source",
|
|
2518
|
+
speaker: "Speaker",
|
|
2519
|
+
subtitle1: "Subtitle",
|
|
2520
|
+
surname: "Surname",
|
|
2521
|
+
tag: "Tag",
|
|
2522
|
+
tblfn: "Table Footnote",
|
|
2523
|
+
tblsource: "Table Source",
|
|
2524
|
+
thead: "Thead",
|
|
2525
|
+
title1: "Title",
|
|
2526
|
+
token: "Token",
|
|
2527
|
+
tp: "Table Paragraph",
|
|
2528
|
+
abstract1: "Abstract",
|
|
2529
|
+
affiliation: "Affiliation",
|
|
2530
|
+
alttext: "Alttext",
|
|
2531
|
+
appendix: "Appendix",
|
|
2532
|
+
author: "Author",
|
|
2533
|
+
authorgroup: "Authorgroup",
|
|
2534
|
+
blockquote: "Blockquote",
|
|
2535
|
+
caption1: "Caption",
|
|
2536
|
+
chapter: "Chapter",
|
|
2537
|
+
dialogue: "Dialogue",
|
|
2538
|
+
epigraph: "Epigraph",
|
|
2539
|
+
figure1: "Figure",
|
|
2540
|
+
footnoteSection: "Footnote Section",
|
|
2541
|
+
heading: "Heading",
|
|
2542
|
+
imageobject: "Image Object",
|
|
2543
|
+
info1: "Info",
|
|
2544
|
+
keywordset: "Keyword FGroup",
|
|
2545
|
+
mediaobject: "Mediaobject",
|
|
2546
|
+
ol: "Ordered List",
|
|
2547
|
+
personname: "Person Name",
|
|
2548
|
+
poem: "Poem",
|
|
2549
|
+
sidebar: "Box",
|
|
2550
|
+
table: "Table",
|
|
2551
|
+
table1: "Table",
|
|
2552
|
+
tbody: "Table Body",
|
|
2553
|
+
td: "Table Data",
|
|
2554
|
+
tgroup: "Table Group",
|
|
2555
|
+
tr: "Table Row",
|
|
2556
|
+
ul: "Unordered List",
|
|
2557
|
+
footnote1: "Footnote",
|
|
2558
|
+
inlineequation: "Inline Equation",
|
|
2559
|
+
link: "Link",
|
|
2560
|
+
uri: "URI",
|
|
2561
|
+
phrase: "Phrase",
|
|
2562
|
+
abbreviation: "Abbreviation"
|
|
2563
|
+
};
|
|
2564
|
+
|
|
2467
2565
|
// src/schema/shared/dependentsForbiddenElements.ts
|
|
2468
2566
|
var DEPENDENT_FORBIDDEN_ELEMENTS = [
|
|
2469
2567
|
{
|
|
@@ -2603,6 +2701,13 @@ var validateConsecutiveFootnoteCues = (root) => {
|
|
|
2603
2701
|
var findElementLinkedTo = (linkend, elementsToLink) => {
|
|
2604
2702
|
return elementsToLink.includes(linkend);
|
|
2605
2703
|
};
|
|
2704
|
+
var LINK_BLOCKER_ROLES = [
|
|
2705
|
+
TABLE_LINK_ROLE,
|
|
2706
|
+
FIGURE_LINK_ROLE,
|
|
2707
|
+
EQUATION_LINK_ROLE,
|
|
2708
|
+
FOOTNOTE_LINK_ROLE,
|
|
2709
|
+
CHAPTER_LINK_ROLE
|
|
2710
|
+
];
|
|
2606
2711
|
var validateLinkend = (linkElement, elementsToLink) => {
|
|
2607
2712
|
const linkend = linkElement.getAttribute("linkend");
|
|
2608
2713
|
if (!linkend) {
|
|
@@ -2623,22 +2728,27 @@ var validateLinkend = (linkElement, elementsToLink) => {
|
|
|
2623
2728
|
})
|
|
2624
2729
|
];
|
|
2625
2730
|
}
|
|
2731
|
+
const role = linkElement.getAttribute("role");
|
|
2732
|
+
if (!role) {
|
|
2733
|
+
return [];
|
|
2734
|
+
}
|
|
2626
2735
|
if (findElementLinkedTo(linkend, elementsToLink)) {
|
|
2627
2736
|
return [];
|
|
2628
2737
|
}
|
|
2738
|
+
const isBlocker = LINK_BLOCKER_ROLES.includes(role.toLowerCase());
|
|
2629
2739
|
return [
|
|
2630
2740
|
createValidationIssue({
|
|
2631
2741
|
store: getStore(linkElement),
|
|
2632
2742
|
title: "Unlinked element",
|
|
2633
2743
|
kind: "unlinked",
|
|
2634
|
-
description: "This link is not referenced to any element in the current chapter or
|
|
2635
|
-
level: "blocker"
|
|
2744
|
+
description: "This link is not referenced to any element in the current chapter or any other chapter. Please link it again manually.",
|
|
2745
|
+
level: isBlocker ? "blocker" : "warning"
|
|
2636
2746
|
})
|
|
2637
2747
|
];
|
|
2638
2748
|
};
|
|
2639
2749
|
|
|
2640
2750
|
// src/validation/validateAttributes.ts
|
|
2641
|
-
var
|
|
2751
|
+
var validateAttributes = (element, schema) => {
|
|
2642
2752
|
const errors = [];
|
|
2643
2753
|
const definitions = [
|
|
2644
2754
|
...schema.requiredAttributes,
|
|
@@ -2666,8 +2776,8 @@ var validateAttributes2 = (element, schema) => {
|
|
|
2666
2776
|
}
|
|
2667
2777
|
if (!definition.values.includes(value)) {
|
|
2668
2778
|
addValidationIssue(errors, {
|
|
2669
|
-
store: element
|
|
2670
|
-
title: `Invalid attribute value "${value}"`,
|
|
2779
|
+
store: getStore(element),
|
|
2780
|
+
title: `Invalid attribute value "${value}" in element ${element.tagName}`,
|
|
2671
2781
|
level: "warning",
|
|
2672
2782
|
kind: "forbidden",
|
|
2673
2783
|
description: `The attribute "${name}" has an invalid value "${value}".`
|
|
@@ -2689,7 +2799,7 @@ var validateElementAgainstSchema = (element, schema) => {
|
|
|
2689
2799
|
description: `The element is not allowed in this context.`
|
|
2690
2800
|
});
|
|
2691
2801
|
}
|
|
2692
|
-
errors.push(...
|
|
2802
|
+
errors.push(...validateAttributes(element, schema));
|
|
2693
2803
|
errors.push(...validateChildren(element, schema));
|
|
2694
2804
|
return errors;
|
|
2695
2805
|
};
|
|
@@ -2704,7 +2814,7 @@ var validateRequiredChildren = (element, schema, childElements) => {
|
|
|
2704
2814
|
return childSchema?.code === allowedChild.code;
|
|
2705
2815
|
});
|
|
2706
2816
|
if (!hasChild) {
|
|
2707
|
-
const requiredChildrenTag = findSchemaByCode(allowedChild.code)
|
|
2817
|
+
const requiredChildrenTag = findSchemaByCode(allowedChild.code).tag;
|
|
2708
2818
|
addValidationIssue(errors, {
|
|
2709
2819
|
store: getStore(element),
|
|
2710
2820
|
title: `Missing required child element ${requiredChildrenTag}`,
|
|
@@ -2801,7 +2911,7 @@ var validateReferenceCited = (referenceElement, linkElements) => {
|
|
|
2801
2911
|
title: "Unlinked element",
|
|
2802
2912
|
kind: "unlinked",
|
|
2803
2913
|
description: "This reference is not cited in this chapter or any other chapter. Please add a link to this reference or delete the reference.",
|
|
2804
|
-
level: "
|
|
2914
|
+
level: "warning"
|
|
2805
2915
|
})
|
|
2806
2916
|
];
|
|
2807
2917
|
};
|
|
@@ -2869,6 +2979,7 @@ var validateXml = (xml, elementsToLink, linkElements, schemasToValidateAgainst)
|
|
|
2869
2979
|
DEPENDENT_FORBIDDEN_ELEMENTS,
|
|
2870
2980
|
ELEMENT_SCHEMAS,
|
|
2871
2981
|
ELE_ID_ATTRIBUTE,
|
|
2982
|
+
ElementLabel,
|
|
2872
2983
|
FIGURE_PLACEMENT_ATTRIBUTE,
|
|
2873
2984
|
ID_ATTRS,
|
|
2874
2985
|
IGNORED_ATTRIBUTES,
|
|
@@ -2899,7 +3010,6 @@ var validateXml = (xml, elementsToLink, linkElements, schemasToValidateAgainst)
|
|
|
2899
3010
|
findAttributeDefinitionByName,
|
|
2900
3011
|
findSchemaByCode,
|
|
2901
3012
|
findSchemaByElement,
|
|
2902
|
-
findSchemaByTagName,
|
|
2903
3013
|
getAttributeName,
|
|
2904
3014
|
isAttributeRestricted,
|
|
2905
3015
|
isIgnoredAttribute,
|
package/dist/index.mjs
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
// src/schema/utils/createSchema.ts
|
|
2
|
-
var createSchema = ({
|
|
3
|
-
|
|
4
|
-
kind,
|
|
5
|
-
tag,
|
|
6
|
-
requiredAttributes,
|
|
7
|
-
optionalAttributes,
|
|
8
|
-
defaultChildCode,
|
|
9
|
-
allowedChildrenCodes
|
|
10
|
-
}) => {
|
|
11
|
-
return {
|
|
12
|
-
code,
|
|
13
|
-
kind,
|
|
14
|
-
tag,
|
|
15
|
-
requiredAttributes,
|
|
16
|
-
optionalAttributes,
|
|
17
|
-
defaultChildCode,
|
|
18
|
-
allowedChildrenCodes
|
|
19
|
-
};
|
|
2
|
+
var createSchema = (params) => {
|
|
3
|
+
return params;
|
|
20
4
|
};
|
|
21
5
|
|
|
22
6
|
// src/schema/shared/globalAttributes.ts
|
|
@@ -75,11 +59,13 @@ var ATOM_CODES_ALLOWED_CHILDREN = [
|
|
|
75
59
|
{ code: "commentQuerySection", required: false },
|
|
76
60
|
{ code: "comment", required: false },
|
|
77
61
|
{ code: "query", required: false },
|
|
78
|
-
{ code: "referenceMark", required: false }
|
|
62
|
+
{ code: "referenceMark", required: false },
|
|
63
|
+
{ code: "abbreviation", required: false }
|
|
79
64
|
];
|
|
80
65
|
|
|
81
66
|
// src/schema/elementSchemas/atoms/atomTags.ts
|
|
82
67
|
var B_TAG = "B";
|
|
68
|
+
var ABBR_TAG = "ABBR";
|
|
83
69
|
var I_TAG = "I";
|
|
84
70
|
var U_TAG = "U";
|
|
85
71
|
var SC_TAG = "SC";
|
|
@@ -117,6 +103,7 @@ var COMMENT_QUERY_SECTION_SCHEMA = createSchema({
|
|
|
117
103
|
kind: "atom",
|
|
118
104
|
tag: SPAN_TAG,
|
|
119
105
|
code: "commentQuerySection",
|
|
106
|
+
matchesElement: (element) => element.classList.contains("cmtQurySection"),
|
|
120
107
|
requiredAttributes: [...ID_ATTRS, "id"],
|
|
121
108
|
optionalAttributes: [...TRACK_CHANGES_ATTRS, "title"],
|
|
122
109
|
allowedChildrenCodes: [...ATOM_CODES_ALLOWED_CHILDREN]
|
|
@@ -136,6 +123,7 @@ var DELETION_SCHEMA = createSchema({
|
|
|
136
123
|
code: "deletion",
|
|
137
124
|
kind: "atom",
|
|
138
125
|
tag: SPAN_TAG,
|
|
126
|
+
matchesElement: (element) => element.classList.contains("del"),
|
|
139
127
|
requiredAttributes: [...TRACK_CHANGES_ATTRS, ...ID_ATTRS],
|
|
140
128
|
optionalAttributes: [],
|
|
141
129
|
allowedChildrenCodes: [
|
|
@@ -186,6 +174,7 @@ var INSERTION_SCHEMA = createSchema({
|
|
|
186
174
|
code: "insertion",
|
|
187
175
|
kind: "atom",
|
|
188
176
|
tag: SPAN_TAG,
|
|
177
|
+
matchesElement: (element) => element.classList.contains("ins"),
|
|
189
178
|
requiredAttributes: [...TRACK_CHANGES_ATTRS, ...ID_ATTRS],
|
|
190
179
|
optionalAttributes: [],
|
|
191
180
|
allowedChildrenCodes: [
|
|
@@ -481,6 +470,27 @@ var REFERENCE_MARK_SCHEMA = createSchema({
|
|
|
481
470
|
allowedChildrenCodes: [...ATOM_CODES_ALLOWED_CHILDREN]
|
|
482
471
|
});
|
|
483
472
|
|
|
473
|
+
// src/schema/elementSchemas/atoms/abbr.ts
|
|
474
|
+
var ABBR_SCHEMA = createSchema({
|
|
475
|
+
code: "abbreviation",
|
|
476
|
+
kind: "atom",
|
|
477
|
+
tag: ABBR_TAG,
|
|
478
|
+
requiredAttributes: [
|
|
479
|
+
...ID_ATTRS,
|
|
480
|
+
"title",
|
|
481
|
+
TRACK_CHANGES_ATTR_DATA_TIME,
|
|
482
|
+
TRACK_CHANGES_ATTR_DATA_USERID,
|
|
483
|
+
TRACK_CHANGES_ATTR_DATA_USERNAME,
|
|
484
|
+
{
|
|
485
|
+
name: "data-abbr-action",
|
|
486
|
+
values: ["add", "edit"],
|
|
487
|
+
defaultValue: "add"
|
|
488
|
+
}
|
|
489
|
+
],
|
|
490
|
+
optionalAttributes: [],
|
|
491
|
+
allowedChildrenCodes: [...ATOM_CODES_ALLOWED_CHILDREN]
|
|
492
|
+
});
|
|
493
|
+
|
|
484
494
|
// src/schema/elementSchemas/atoms/index.ts
|
|
485
495
|
var ATOM_SCHEMAS = {
|
|
486
496
|
indexterm: INDEXTERM_SCHEMA,
|
|
@@ -506,7 +516,8 @@ var ATOM_SCHEMAS = {
|
|
|
506
516
|
content: CONTENT_SCHEMA,
|
|
507
517
|
comment: COMMENT_SCHEMA,
|
|
508
518
|
query: QUERY_SCHEMA,
|
|
509
|
-
reply: REPLY_SCHEMA
|
|
519
|
+
reply: REPLY_SCHEMA,
|
|
520
|
+
abbreviation: ABBR_SCHEMA
|
|
510
521
|
};
|
|
511
522
|
|
|
512
523
|
// src/schema/elementSchemas/elements/elementsTags.ts
|
|
@@ -1907,15 +1918,21 @@ var EPIGRAPH_SCHEMA = createSchema({
|
|
|
1907
1918
|
});
|
|
1908
1919
|
|
|
1909
1920
|
// src/schema/elementSchemas/elements/footnoteSection.ts
|
|
1921
|
+
var FOOTNOTE_SECTION_ROLES = ["ch", "bk"];
|
|
1910
1922
|
var FOOTNOTE_SECTION_SCHEMA = createSchema({
|
|
1911
1923
|
code: "footnoteSection",
|
|
1912
1924
|
kind: "element",
|
|
1913
1925
|
tag: SECTION_TAG,
|
|
1926
|
+
matchesElement: (element) => {
|
|
1927
|
+
const role = element.getAttribute("role");
|
|
1928
|
+
if (role && FOOTNOTE_SECTION_ROLES.includes(role)) return true;
|
|
1929
|
+
return element.querySelector(FOOTNOTE_TAG) !== null;
|
|
1930
|
+
},
|
|
1914
1931
|
requiredAttributes: [
|
|
1915
1932
|
...ID_ATTRS,
|
|
1916
1933
|
{
|
|
1917
1934
|
name: "role",
|
|
1918
|
-
values:
|
|
1935
|
+
values: FOOTNOTE_SECTION_ROLES,
|
|
1919
1936
|
defaultValue: "ch"
|
|
1920
1937
|
}
|
|
1921
1938
|
],
|
|
@@ -1928,16 +1945,22 @@ var FOOTNOTE_SECTION_SCHEMA = createSchema({
|
|
|
1928
1945
|
});
|
|
1929
1946
|
|
|
1930
1947
|
// src/schema/elementSchemas/elements/heading.ts
|
|
1948
|
+
var HEADING_ROLES = ["H1", "H2", "H3", "H4", "H5", "H6", "vignette_group"];
|
|
1931
1949
|
var HEADING_SCHEMA = createSchema({
|
|
1932
1950
|
code: "heading",
|
|
1933
1951
|
kind: "element",
|
|
1934
1952
|
tag: SECTION_TAG,
|
|
1953
|
+
matchesElement: (element) => {
|
|
1954
|
+
const role = element.getAttribute("role");
|
|
1955
|
+
if (!role) return false;
|
|
1956
|
+
return HEADING_ROLES.includes(role);
|
|
1957
|
+
},
|
|
1935
1958
|
requiredAttributes: [
|
|
1936
1959
|
...ID_ATTRS,
|
|
1937
1960
|
"xmlid",
|
|
1938
1961
|
{
|
|
1939
1962
|
name: "role",
|
|
1940
|
-
values:
|
|
1963
|
+
values: HEADING_ROLES,
|
|
1941
1964
|
defaultValue: "H1"
|
|
1942
1965
|
}
|
|
1943
1966
|
],
|
|
@@ -2005,7 +2028,6 @@ var MATHPHRASE_SCHEMA = createSchema({
|
|
|
2005
2028
|
requiredAttributes: [ELE_ID_ATTRIBUTE],
|
|
2006
2029
|
optionalAttributes: [],
|
|
2007
2030
|
allowedChildrenCodes: [{ code: MATH_SCHEMA.code, required: true }]
|
|
2008
|
-
// TODO: Should have flag for insertion and deletion
|
|
2009
2031
|
});
|
|
2010
2032
|
|
|
2011
2033
|
// src/schema/elementSchemas/elements/reference/bibliodiv.ts
|
|
@@ -2209,6 +2231,12 @@ var INLINEEQUATION_SCHEMA = createSchema({
|
|
|
2209
2231
|
});
|
|
2210
2232
|
|
|
2211
2233
|
// src/schema/elementSchemas/inlineElements/link.ts
|
|
2234
|
+
var TABLE_LINK_ROLE = "table";
|
|
2235
|
+
var FIGURE_LINK_ROLE = "figure";
|
|
2236
|
+
var EQUATION_LINK_ROLE = "equation";
|
|
2237
|
+
var FOOTNOTE_LINK_ROLE = "footnote";
|
|
2238
|
+
var REFERENCE_LINK_ROLE = "bibr";
|
|
2239
|
+
var CHAPTER_LINK_ROLE = "chapter";
|
|
2212
2240
|
var LINK_SCHEMA = createSchema({
|
|
2213
2241
|
code: "link",
|
|
2214
2242
|
kind: "inline",
|
|
@@ -2216,14 +2244,20 @@ var LINK_SCHEMA = createSchema({
|
|
|
2216
2244
|
requiredAttributes: [
|
|
2217
2245
|
...ID_ATTRS,
|
|
2218
2246
|
"linkend",
|
|
2219
|
-
"data-target-id",
|
|
2220
2247
|
{
|
|
2221
2248
|
name: "role",
|
|
2222
|
-
values: [
|
|
2223
|
-
|
|
2249
|
+
values: [
|
|
2250
|
+
TABLE_LINK_ROLE,
|
|
2251
|
+
FIGURE_LINK_ROLE,
|
|
2252
|
+
EQUATION_LINK_ROLE,
|
|
2253
|
+
FOOTNOTE_LINK_ROLE,
|
|
2254
|
+
REFERENCE_LINK_ROLE,
|
|
2255
|
+
CHAPTER_LINK_ROLE
|
|
2256
|
+
],
|
|
2257
|
+
defaultValue: "bibr"
|
|
2224
2258
|
}
|
|
2225
2259
|
],
|
|
2226
|
-
optionalAttributes: [],
|
|
2260
|
+
optionalAttributes: ["data-target-id"],
|
|
2227
2261
|
allowedChildrenCodes: [...ATOM_CODES_ALLOWED_CHILDREN]
|
|
2228
2262
|
});
|
|
2229
2263
|
|
|
@@ -2303,42 +2337,11 @@ var isIgnoredAttribute = (attribute) => IGNORED_ATTRIBUTES.includes(attribute) |
|
|
|
2303
2337
|
var isIgnoredElement = (element) => IGNORED_ELEMENT_SELECTORS.some((selector) => element.matches(selector));
|
|
2304
2338
|
var isIgnoredValidation = (code) => IGNORED_VALIDATION_ELEMENT_SELECTORS.includes(code);
|
|
2305
2339
|
var findSchemaByCode = (code) => SCHEMAS[code];
|
|
2306
|
-
var findSchemaByTagName = (tagName) => Object.values(SCHEMAS).filter(
|
|
2307
|
-
(schema) => schema.tag === tagName.toUpperCase()
|
|
2308
|
-
);
|
|
2309
2340
|
var findSchemaByElement = (element) => {
|
|
2310
|
-
const
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
const role = element.getAttribute("role");
|
|
2315
|
-
if (tagName === SPAN_TAG) {
|
|
2316
|
-
if (isQueryComment) {
|
|
2317
|
-
return findSchemaByCode("commentQuerySection");
|
|
2318
|
-
}
|
|
2319
|
-
if (isInsertion) {
|
|
2320
|
-
return findSchemaByCode("insertion");
|
|
2321
|
-
}
|
|
2322
|
-
if (isDeletion) {
|
|
2323
|
-
return findSchemaByCode("deletion");
|
|
2324
|
-
}
|
|
2325
|
-
}
|
|
2326
|
-
if (tagName === SECTION_TAG) {
|
|
2327
|
-
if (role) {
|
|
2328
|
-
if (role.startsWith("H")) {
|
|
2329
|
-
return findSchemaByCode("heading");
|
|
2330
|
-
}
|
|
2331
|
-
if (role === "ch" || role === "bk") {
|
|
2332
|
-
return findSchemaByCode("footnoteSection");
|
|
2333
|
-
}
|
|
2334
|
-
}
|
|
2335
|
-
const isFootnoteSectionWithoutRole = element.querySelector(FOOTNOTE_TAG);
|
|
2336
|
-
if (isFootnoteSectionWithoutRole) {
|
|
2337
|
-
return findSchemaByCode("footnoteSection");
|
|
2338
|
-
}
|
|
2339
|
-
}
|
|
2340
|
-
const candidates = findSchemaByTagName(tagName);
|
|
2341
|
-
return candidates[0];
|
|
2341
|
+
const schema = Object.values(SCHEMAS).find(
|
|
2342
|
+
(schema2) => schema2.tag == element.tagName && (!schema2.matchesElement || schema2.matchesElement(element))
|
|
2343
|
+
);
|
|
2344
|
+
return schema;
|
|
2342
2345
|
};
|
|
2343
2346
|
var isAttributeRestricted = (attr) => typeof attr !== "string";
|
|
2344
2347
|
var getAttributeName = (attribute) => typeof attribute === "string" ? attribute.toLowerCase() : attribute.name.toLowerCase();
|
|
@@ -2352,50 +2355,145 @@ var findAttributeDefinitionByName = (definitions, name) => {
|
|
|
2352
2355
|
};
|
|
2353
2356
|
|
|
2354
2357
|
// src/schema/utils/createElement.ts
|
|
2355
|
-
var validateAttributes = (attributes, schema) => {
|
|
2356
|
-
const definitions = [
|
|
2357
|
-
...schema.requiredAttributes,
|
|
2358
|
-
...schema.optionalAttributes
|
|
2359
|
-
];
|
|
2360
|
-
for (const [name, value] of Object.entries(attributes)) {
|
|
2361
|
-
if (value === void 0) {
|
|
2362
|
-
continue;
|
|
2363
|
-
}
|
|
2364
|
-
const definition = findAttributeDefinitionByName(definitions, name);
|
|
2365
|
-
if (!definition) {
|
|
2366
|
-
throw new Error(
|
|
2367
|
-
`Invalid attribute "${name}" for schema "${schema.code}".`
|
|
2368
|
-
);
|
|
2369
|
-
}
|
|
2370
|
-
if (!isAttributeRestricted(definition)) {
|
|
2371
|
-
continue;
|
|
2372
|
-
}
|
|
2373
|
-
if (!definition.values.includes(value)) {
|
|
2374
|
-
throw new Error(
|
|
2375
|
-
`Invalid value "${value}" for attribute "${name}" on schema "${schema.code}". Allowed values: ${definition.values.join(", ")}.`
|
|
2376
|
-
);
|
|
2377
|
-
}
|
|
2378
|
-
}
|
|
2379
|
-
};
|
|
2380
2358
|
var createElement = ({
|
|
2381
2359
|
schemaCode,
|
|
2382
2360
|
attributes
|
|
2383
2361
|
}) => {
|
|
2384
2362
|
const schema = findSchemaByCode(schemaCode);
|
|
2385
|
-
if (!schema) {
|
|
2386
|
-
throw new Error(`Schema not found for code: ${schemaCode}`);
|
|
2387
|
-
}
|
|
2388
|
-
validateAttributes(attributes, schema);
|
|
2389
2363
|
const element = document.createElement(schema.tag.toLowerCase());
|
|
2390
2364
|
for (const [name, value] of Object.entries(attributes)) {
|
|
2391
|
-
if (value
|
|
2392
|
-
continue;
|
|
2393
|
-
}
|
|
2365
|
+
if (!value) continue;
|
|
2394
2366
|
element.setAttribute(name, String(value));
|
|
2395
2367
|
}
|
|
2396
2368
|
return element;
|
|
2397
2369
|
};
|
|
2398
2370
|
|
|
2371
|
+
// src/schema/shared/labelElements.ts
|
|
2372
|
+
var ElementLabel = {
|
|
2373
|
+
referenceBibliomixed: "Reference Bibliomixed",
|
|
2374
|
+
referenceBibliography: "Reference Bibliography",
|
|
2375
|
+
bibliodiv: "Bibliodiv",
|
|
2376
|
+
indexterm: "Indexterm",
|
|
2377
|
+
primary: "Primary",
|
|
2378
|
+
secondary: "Secondary",
|
|
2379
|
+
tertiary: "Tertiary",
|
|
2380
|
+
quaternary: "Quaternary",
|
|
2381
|
+
bookmark: "Bookmark",
|
|
2382
|
+
see: "Cross Reference",
|
|
2383
|
+
commentQuerySection: "Comment/Query",
|
|
2384
|
+
comment: "Comment",
|
|
2385
|
+
content: "Content",
|
|
2386
|
+
query: "Query",
|
|
2387
|
+
reply: "Reply",
|
|
2388
|
+
deletion: "Deletion",
|
|
2389
|
+
emphasis: "Emphasis",
|
|
2390
|
+
highlightmark: "Highlightmark",
|
|
2391
|
+
i: "Italic",
|
|
2392
|
+
insertion: "Insertion",
|
|
2393
|
+
sc: "Small Caps",
|
|
2394
|
+
strike: "Strike",
|
|
2395
|
+
sub: "Subscript",
|
|
2396
|
+
sup: "Superscript",
|
|
2397
|
+
u: "Underline",
|
|
2398
|
+
b: "Bold",
|
|
2399
|
+
referenceMark: "Reference Mark",
|
|
2400
|
+
degrees: "Degrees",
|
|
2401
|
+
email: "Email",
|
|
2402
|
+
equation: "Equation",
|
|
2403
|
+
fignote: "Fignote",
|
|
2404
|
+
figsource: "Figsource",
|
|
2405
|
+
firstname: "Firstname",
|
|
2406
|
+
footnote: "Footnote Marker",
|
|
2407
|
+
footnoteno: "Footnote Number",
|
|
2408
|
+
honorific: "Honorific",
|
|
2409
|
+
img: "Image",
|
|
2410
|
+
informalfigure: "Floating Figure",
|
|
2411
|
+
keyword: "Keyword",
|
|
2412
|
+
label1: "Label",
|
|
2413
|
+
li: "List Item",
|
|
2414
|
+
line: "Line",
|
|
2415
|
+
lrh: "Running Head Left",
|
|
2416
|
+
math: "Math",
|
|
2417
|
+
mathphrase: "Math Phrase",
|
|
2418
|
+
merror: "Math Error",
|
|
2419
|
+
mfrac: "Math Fraction",
|
|
2420
|
+
mi: "Math Identifier",
|
|
2421
|
+
mmultiscripts: "Math Multiscripts",
|
|
2422
|
+
mn: "Math Number",
|
|
2423
|
+
mo: "Math Operator",
|
|
2424
|
+
mover: "Math Over",
|
|
2425
|
+
mpadded: "Math Padded",
|
|
2426
|
+
mphantom: "Math Phantom",
|
|
2427
|
+
mprescripts: "Math Prescripts",
|
|
2428
|
+
mroot: "Math Root",
|
|
2429
|
+
mrow: "Math Row",
|
|
2430
|
+
ms: "Math Space",
|
|
2431
|
+
mspace: "Math Space",
|
|
2432
|
+
msqrt: "Math Square Root",
|
|
2433
|
+
mstyle: "Math Style",
|
|
2434
|
+
msub: "Math Subscript",
|
|
2435
|
+
msubsup: "Math Subscript Superscript",
|
|
2436
|
+
msup: "Math Superscript",
|
|
2437
|
+
mtable: "Math Table",
|
|
2438
|
+
mtd: "Math Table Data",
|
|
2439
|
+
mtext: "Math Text",
|
|
2440
|
+
mtr: "Math Table Row",
|
|
2441
|
+
munder: "Math Under",
|
|
2442
|
+
munderover: "Math Under Over",
|
|
2443
|
+
olink: "Online Link",
|
|
2444
|
+
org: "Org",
|
|
2445
|
+
orgname: "Orgname",
|
|
2446
|
+
para: "Paragraph",
|
|
2447
|
+
punc: "Punctuation",
|
|
2448
|
+
rrh: "Running Head Right",
|
|
2449
|
+
source1: "Source",
|
|
2450
|
+
speaker: "Speaker",
|
|
2451
|
+
subtitle1: "Subtitle",
|
|
2452
|
+
surname: "Surname",
|
|
2453
|
+
tag: "Tag",
|
|
2454
|
+
tblfn: "Table Footnote",
|
|
2455
|
+
tblsource: "Table Source",
|
|
2456
|
+
thead: "Thead",
|
|
2457
|
+
title1: "Title",
|
|
2458
|
+
token: "Token",
|
|
2459
|
+
tp: "Table Paragraph",
|
|
2460
|
+
abstract1: "Abstract",
|
|
2461
|
+
affiliation: "Affiliation",
|
|
2462
|
+
alttext: "Alttext",
|
|
2463
|
+
appendix: "Appendix",
|
|
2464
|
+
author: "Author",
|
|
2465
|
+
authorgroup: "Authorgroup",
|
|
2466
|
+
blockquote: "Blockquote",
|
|
2467
|
+
caption1: "Caption",
|
|
2468
|
+
chapter: "Chapter",
|
|
2469
|
+
dialogue: "Dialogue",
|
|
2470
|
+
epigraph: "Epigraph",
|
|
2471
|
+
figure1: "Figure",
|
|
2472
|
+
footnoteSection: "Footnote Section",
|
|
2473
|
+
heading: "Heading",
|
|
2474
|
+
imageobject: "Image Object",
|
|
2475
|
+
info1: "Info",
|
|
2476
|
+
keywordset: "Keyword FGroup",
|
|
2477
|
+
mediaobject: "Mediaobject",
|
|
2478
|
+
ol: "Ordered List",
|
|
2479
|
+
personname: "Person Name",
|
|
2480
|
+
poem: "Poem",
|
|
2481
|
+
sidebar: "Box",
|
|
2482
|
+
table: "Table",
|
|
2483
|
+
table1: "Table",
|
|
2484
|
+
tbody: "Table Body",
|
|
2485
|
+
td: "Table Data",
|
|
2486
|
+
tgroup: "Table Group",
|
|
2487
|
+
tr: "Table Row",
|
|
2488
|
+
ul: "Unordered List",
|
|
2489
|
+
footnote1: "Footnote",
|
|
2490
|
+
inlineequation: "Inline Equation",
|
|
2491
|
+
link: "Link",
|
|
2492
|
+
uri: "URI",
|
|
2493
|
+
phrase: "Phrase",
|
|
2494
|
+
abbreviation: "Abbreviation"
|
|
2495
|
+
};
|
|
2496
|
+
|
|
2399
2497
|
// src/schema/shared/dependentsForbiddenElements.ts
|
|
2400
2498
|
var DEPENDENT_FORBIDDEN_ELEMENTS = [
|
|
2401
2499
|
{
|
|
@@ -2535,6 +2633,13 @@ var validateConsecutiveFootnoteCues = (root) => {
|
|
|
2535
2633
|
var findElementLinkedTo = (linkend, elementsToLink) => {
|
|
2536
2634
|
return elementsToLink.includes(linkend);
|
|
2537
2635
|
};
|
|
2636
|
+
var LINK_BLOCKER_ROLES = [
|
|
2637
|
+
TABLE_LINK_ROLE,
|
|
2638
|
+
FIGURE_LINK_ROLE,
|
|
2639
|
+
EQUATION_LINK_ROLE,
|
|
2640
|
+
FOOTNOTE_LINK_ROLE,
|
|
2641
|
+
CHAPTER_LINK_ROLE
|
|
2642
|
+
];
|
|
2538
2643
|
var validateLinkend = (linkElement, elementsToLink) => {
|
|
2539
2644
|
const linkend = linkElement.getAttribute("linkend");
|
|
2540
2645
|
if (!linkend) {
|
|
@@ -2555,22 +2660,27 @@ var validateLinkend = (linkElement, elementsToLink) => {
|
|
|
2555
2660
|
})
|
|
2556
2661
|
];
|
|
2557
2662
|
}
|
|
2663
|
+
const role = linkElement.getAttribute("role");
|
|
2664
|
+
if (!role) {
|
|
2665
|
+
return [];
|
|
2666
|
+
}
|
|
2558
2667
|
if (findElementLinkedTo(linkend, elementsToLink)) {
|
|
2559
2668
|
return [];
|
|
2560
2669
|
}
|
|
2670
|
+
const isBlocker = LINK_BLOCKER_ROLES.includes(role.toLowerCase());
|
|
2561
2671
|
return [
|
|
2562
2672
|
createValidationIssue({
|
|
2563
2673
|
store: getStore(linkElement),
|
|
2564
2674
|
title: "Unlinked element",
|
|
2565
2675
|
kind: "unlinked",
|
|
2566
|
-
description: "This link is not referenced to any element in the current chapter or
|
|
2567
|
-
level: "blocker"
|
|
2676
|
+
description: "This link is not referenced to any element in the current chapter or any other chapter. Please link it again manually.",
|
|
2677
|
+
level: isBlocker ? "blocker" : "warning"
|
|
2568
2678
|
})
|
|
2569
2679
|
];
|
|
2570
2680
|
};
|
|
2571
2681
|
|
|
2572
2682
|
// src/validation/validateAttributes.ts
|
|
2573
|
-
var
|
|
2683
|
+
var validateAttributes = (element, schema) => {
|
|
2574
2684
|
const errors = [];
|
|
2575
2685
|
const definitions = [
|
|
2576
2686
|
...schema.requiredAttributes,
|
|
@@ -2598,8 +2708,8 @@ var validateAttributes2 = (element, schema) => {
|
|
|
2598
2708
|
}
|
|
2599
2709
|
if (!definition.values.includes(value)) {
|
|
2600
2710
|
addValidationIssue(errors, {
|
|
2601
|
-
store: element
|
|
2602
|
-
title: `Invalid attribute value "${value}"`,
|
|
2711
|
+
store: getStore(element),
|
|
2712
|
+
title: `Invalid attribute value "${value}" in element ${element.tagName}`,
|
|
2603
2713
|
level: "warning",
|
|
2604
2714
|
kind: "forbidden",
|
|
2605
2715
|
description: `The attribute "${name}" has an invalid value "${value}".`
|
|
@@ -2621,7 +2731,7 @@ var validateElementAgainstSchema = (element, schema) => {
|
|
|
2621
2731
|
description: `The element is not allowed in this context.`
|
|
2622
2732
|
});
|
|
2623
2733
|
}
|
|
2624
|
-
errors.push(...
|
|
2734
|
+
errors.push(...validateAttributes(element, schema));
|
|
2625
2735
|
errors.push(...validateChildren(element, schema));
|
|
2626
2736
|
return errors;
|
|
2627
2737
|
};
|
|
@@ -2636,7 +2746,7 @@ var validateRequiredChildren = (element, schema, childElements) => {
|
|
|
2636
2746
|
return childSchema?.code === allowedChild.code;
|
|
2637
2747
|
});
|
|
2638
2748
|
if (!hasChild) {
|
|
2639
|
-
const requiredChildrenTag = findSchemaByCode(allowedChild.code)
|
|
2749
|
+
const requiredChildrenTag = findSchemaByCode(allowedChild.code).tag;
|
|
2640
2750
|
addValidationIssue(errors, {
|
|
2641
2751
|
store: getStore(element),
|
|
2642
2752
|
title: `Missing required child element ${requiredChildrenTag}`,
|
|
@@ -2733,7 +2843,7 @@ var validateReferenceCited = (referenceElement, linkElements) => {
|
|
|
2733
2843
|
title: "Unlinked element",
|
|
2734
2844
|
kind: "unlinked",
|
|
2735
2845
|
description: "This reference is not cited in this chapter or any other chapter. Please add a link to this reference or delete the reference.",
|
|
2736
|
-
level: "
|
|
2846
|
+
level: "warning"
|
|
2737
2847
|
})
|
|
2738
2848
|
];
|
|
2739
2849
|
};
|
|
@@ -2800,6 +2910,7 @@ export {
|
|
|
2800
2910
|
DEPENDENT_FORBIDDEN_ELEMENTS,
|
|
2801
2911
|
ELEMENT_SCHEMAS,
|
|
2802
2912
|
ELE_ID_ATTRIBUTE,
|
|
2913
|
+
ElementLabel,
|
|
2803
2914
|
FIGURE_PLACEMENT_ATTRIBUTE,
|
|
2804
2915
|
ID_ATTRS,
|
|
2805
2916
|
IGNORED_ATTRIBUTES,
|
|
@@ -2830,7 +2941,6 @@ export {
|
|
|
2830
2941
|
findAttributeDefinitionByName,
|
|
2831
2942
|
findSchemaByCode,
|
|
2832
2943
|
findSchemaByElement,
|
|
2833
|
-
findSchemaByTagName,
|
|
2834
2944
|
getAttributeName,
|
|
2835
2945
|
isAttributeRestricted,
|
|
2836
2946
|
isIgnoredAttribute,
|