pro-editor-schema 0.2.2 → 0.2.22
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 +282 -111
- package/dist/index.mjs +281 -110
- package/package.json +1 -1
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,8 +174,15 @@ 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
|
-
optionalAttributes: [
|
|
179
|
+
optionalAttributes: [
|
|
180
|
+
{
|
|
181
|
+
name: "role",
|
|
182
|
+
values: ["web-link", "figure-note-link", "figsource"],
|
|
183
|
+
defaultValue: ""
|
|
184
|
+
}
|
|
185
|
+
],
|
|
191
186
|
allowedChildrenCodes: [
|
|
192
187
|
...ATOM_CODES_ALLOWED_CHILDREN,
|
|
193
188
|
...INLINE_ELEMENT_CODES_ALLOWED_CHILDREN
|
|
@@ -481,6 +476,27 @@ var REFERENCE_MARK_SCHEMA = createSchema({
|
|
|
481
476
|
allowedChildrenCodes: [...ATOM_CODES_ALLOWED_CHILDREN]
|
|
482
477
|
});
|
|
483
478
|
|
|
479
|
+
// src/schema/elementSchemas/atoms/abbr.ts
|
|
480
|
+
var ABBR_SCHEMA = createSchema({
|
|
481
|
+
code: "abbreviation",
|
|
482
|
+
kind: "atom",
|
|
483
|
+
tag: ABBR_TAG,
|
|
484
|
+
requiredAttributes: [
|
|
485
|
+
...ID_ATTRS,
|
|
486
|
+
"title",
|
|
487
|
+
TRACK_CHANGES_ATTR_DATA_TIME,
|
|
488
|
+
TRACK_CHANGES_ATTR_DATA_USERID,
|
|
489
|
+
TRACK_CHANGES_ATTR_DATA_USERNAME,
|
|
490
|
+
{
|
|
491
|
+
name: "data-abbr-action",
|
|
492
|
+
values: ["add", "edit"],
|
|
493
|
+
defaultValue: "add"
|
|
494
|
+
}
|
|
495
|
+
],
|
|
496
|
+
optionalAttributes: [],
|
|
497
|
+
allowedChildrenCodes: [...ATOM_CODES_ALLOWED_CHILDREN]
|
|
498
|
+
});
|
|
499
|
+
|
|
484
500
|
// src/schema/elementSchemas/atoms/index.ts
|
|
485
501
|
var ATOM_SCHEMAS = {
|
|
486
502
|
indexterm: INDEXTERM_SCHEMA,
|
|
@@ -506,7 +522,8 @@ var ATOM_SCHEMAS = {
|
|
|
506
522
|
content: CONTENT_SCHEMA,
|
|
507
523
|
comment: COMMENT_SCHEMA,
|
|
508
524
|
query: QUERY_SCHEMA,
|
|
509
|
-
reply: REPLY_SCHEMA
|
|
525
|
+
reply: REPLY_SCHEMA,
|
|
526
|
+
abbreviation: ABBR_SCHEMA
|
|
510
527
|
};
|
|
511
528
|
|
|
512
529
|
// src/schema/elementSchemas/elements/elementsTags.ts
|
|
@@ -1907,15 +1924,21 @@ var EPIGRAPH_SCHEMA = createSchema({
|
|
|
1907
1924
|
});
|
|
1908
1925
|
|
|
1909
1926
|
// src/schema/elementSchemas/elements/footnoteSection.ts
|
|
1927
|
+
var FOOTNOTE_SECTION_ROLES = ["ch", "bk"];
|
|
1910
1928
|
var FOOTNOTE_SECTION_SCHEMA = createSchema({
|
|
1911
1929
|
code: "footnoteSection",
|
|
1912
1930
|
kind: "element",
|
|
1913
1931
|
tag: SECTION_TAG,
|
|
1932
|
+
matchesElement: (element) => {
|
|
1933
|
+
const role = element.getAttribute("role");
|
|
1934
|
+
if (role && FOOTNOTE_SECTION_ROLES.includes(role)) return true;
|
|
1935
|
+
return element.querySelector(FOOTNOTE_TAG) !== null;
|
|
1936
|
+
},
|
|
1914
1937
|
requiredAttributes: [
|
|
1915
1938
|
...ID_ATTRS,
|
|
1916
1939
|
{
|
|
1917
1940
|
name: "role",
|
|
1918
|
-
values:
|
|
1941
|
+
values: FOOTNOTE_SECTION_ROLES,
|
|
1919
1942
|
defaultValue: "ch"
|
|
1920
1943
|
}
|
|
1921
1944
|
],
|
|
@@ -1928,16 +1951,22 @@ var FOOTNOTE_SECTION_SCHEMA = createSchema({
|
|
|
1928
1951
|
});
|
|
1929
1952
|
|
|
1930
1953
|
// src/schema/elementSchemas/elements/heading.ts
|
|
1954
|
+
var HEADING_ROLES = ["H1", "H2", "H3", "H4", "H5", "H6", "vignette_group"];
|
|
1931
1955
|
var HEADING_SCHEMA = createSchema({
|
|
1932
1956
|
code: "heading",
|
|
1933
1957
|
kind: "element",
|
|
1934
1958
|
tag: SECTION_TAG,
|
|
1959
|
+
matchesElement: (element) => {
|
|
1960
|
+
const role = element.getAttribute("role");
|
|
1961
|
+
if (!role) return false;
|
|
1962
|
+
return HEADING_ROLES.includes(role);
|
|
1963
|
+
},
|
|
1935
1964
|
requiredAttributes: [
|
|
1936
1965
|
...ID_ATTRS,
|
|
1937
1966
|
"xmlid",
|
|
1938
1967
|
{
|
|
1939
1968
|
name: "role",
|
|
1940
|
-
values:
|
|
1969
|
+
values: HEADING_ROLES,
|
|
1941
1970
|
defaultValue: "H1"
|
|
1942
1971
|
}
|
|
1943
1972
|
],
|
|
@@ -2005,7 +2034,6 @@ var MATHPHRASE_SCHEMA = createSchema({
|
|
|
2005
2034
|
requiredAttributes: [ELE_ID_ATTRIBUTE],
|
|
2006
2035
|
optionalAttributes: [],
|
|
2007
2036
|
allowedChildrenCodes: [{ code: MATH_SCHEMA.code, required: true }]
|
|
2008
|
-
// TODO: Should have flag for insertion and deletion
|
|
2009
2037
|
});
|
|
2010
2038
|
|
|
2011
2039
|
// src/schema/elementSchemas/elements/reference/bibliodiv.ts
|
|
@@ -2209,6 +2237,12 @@ var INLINEEQUATION_SCHEMA = createSchema({
|
|
|
2209
2237
|
});
|
|
2210
2238
|
|
|
2211
2239
|
// src/schema/elementSchemas/inlineElements/link.ts
|
|
2240
|
+
var TABLE_LINK_ROLE = "table";
|
|
2241
|
+
var FIGURE_LINK_ROLE = "figure";
|
|
2242
|
+
var EQUATION_LINK_ROLE = "equation";
|
|
2243
|
+
var FOOTNOTE_LINK_ROLE = "footnote";
|
|
2244
|
+
var REFERENCE_LINK_ROLE = "bibr";
|
|
2245
|
+
var CHAPTER_LINK_ROLE = "chapter";
|
|
2212
2246
|
var LINK_SCHEMA = createSchema({
|
|
2213
2247
|
code: "link",
|
|
2214
2248
|
kind: "inline",
|
|
@@ -2216,14 +2250,20 @@ var LINK_SCHEMA = createSchema({
|
|
|
2216
2250
|
requiredAttributes: [
|
|
2217
2251
|
...ID_ATTRS,
|
|
2218
2252
|
"linkend",
|
|
2219
|
-
"data-target-id",
|
|
2220
2253
|
{
|
|
2221
2254
|
name: "role",
|
|
2222
|
-
values: [
|
|
2223
|
-
|
|
2255
|
+
values: [
|
|
2256
|
+
TABLE_LINK_ROLE,
|
|
2257
|
+
FIGURE_LINK_ROLE,
|
|
2258
|
+
EQUATION_LINK_ROLE,
|
|
2259
|
+
FOOTNOTE_LINK_ROLE,
|
|
2260
|
+
REFERENCE_LINK_ROLE,
|
|
2261
|
+
CHAPTER_LINK_ROLE
|
|
2262
|
+
],
|
|
2263
|
+
defaultValue: "bibr"
|
|
2224
2264
|
}
|
|
2225
2265
|
],
|
|
2226
|
-
optionalAttributes: [],
|
|
2266
|
+
optionalAttributes: ["data-target-id"],
|
|
2227
2267
|
allowedChildrenCodes: [...ATOM_CODES_ALLOWED_CHILDREN]
|
|
2228
2268
|
});
|
|
2229
2269
|
|
|
@@ -2232,8 +2272,8 @@ var URI_SCHEMA = createSchema({
|
|
|
2232
2272
|
code: "uri",
|
|
2233
2273
|
kind: "inline",
|
|
2234
2274
|
tag: URI_TAG,
|
|
2235
|
-
requiredAttributes: [
|
|
2236
|
-
optionalAttributes: ["
|
|
2275
|
+
requiredAttributes: [],
|
|
2276
|
+
optionalAttributes: ["xlinkhref"],
|
|
2237
2277
|
allowedChildrenCodes: [...ATOM_CODES_ALLOWED_CHILDREN]
|
|
2238
2278
|
});
|
|
2239
2279
|
|
|
@@ -2303,42 +2343,11 @@ var isIgnoredAttribute = (attribute) => IGNORED_ATTRIBUTES.includes(attribute) |
|
|
|
2303
2343
|
var isIgnoredElement = (element) => IGNORED_ELEMENT_SELECTORS.some((selector) => element.matches(selector));
|
|
2304
2344
|
var isIgnoredValidation = (code) => IGNORED_VALIDATION_ELEMENT_SELECTORS.includes(code);
|
|
2305
2345
|
var findSchemaByCode = (code) => SCHEMAS[code];
|
|
2306
|
-
var findSchemaByTagName = (tagName) => Object.values(SCHEMAS).filter(
|
|
2307
|
-
(schema) => schema.tag === tagName.toUpperCase()
|
|
2308
|
-
);
|
|
2309
2346
|
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];
|
|
2347
|
+
const schema = Object.values(SCHEMAS).find(
|
|
2348
|
+
(schema2) => schema2.tag == element.tagName && (!schema2.matchesElement || schema2.matchesElement(element))
|
|
2349
|
+
);
|
|
2350
|
+
return schema;
|
|
2342
2351
|
};
|
|
2343
2352
|
var isAttributeRestricted = (attr) => typeof attr !== "string";
|
|
2344
2353
|
var getAttributeName = (attribute) => typeof attribute === "string" ? attribute.toLowerCase() : attribute.name.toLowerCase();
|
|
@@ -2352,50 +2361,145 @@ var findAttributeDefinitionByName = (definitions, name) => {
|
|
|
2352
2361
|
};
|
|
2353
2362
|
|
|
2354
2363
|
// 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
2364
|
var createElement = ({
|
|
2381
2365
|
schemaCode,
|
|
2382
2366
|
attributes
|
|
2383
2367
|
}) => {
|
|
2384
2368
|
const schema = findSchemaByCode(schemaCode);
|
|
2385
|
-
if (!schema) {
|
|
2386
|
-
throw new Error(`Schema not found for code: ${schemaCode}`);
|
|
2387
|
-
}
|
|
2388
|
-
validateAttributes(attributes, schema);
|
|
2389
2369
|
const element = document.createElement(schema.tag.toLowerCase());
|
|
2390
2370
|
for (const [name, value] of Object.entries(attributes)) {
|
|
2391
|
-
if (value
|
|
2392
|
-
continue;
|
|
2393
|
-
}
|
|
2371
|
+
if (!value) continue;
|
|
2394
2372
|
element.setAttribute(name, String(value));
|
|
2395
2373
|
}
|
|
2396
2374
|
return element;
|
|
2397
2375
|
};
|
|
2398
2376
|
|
|
2377
|
+
// src/schema/shared/labelElements.ts
|
|
2378
|
+
var ElementLabel = {
|
|
2379
|
+
referenceBibliomixed: "Reference Bibliomixed",
|
|
2380
|
+
referenceBibliography: "Reference Bibliography",
|
|
2381
|
+
bibliodiv: "Bibliodiv",
|
|
2382
|
+
indexterm: "Indexterm",
|
|
2383
|
+
primary: "Primary",
|
|
2384
|
+
secondary: "Secondary",
|
|
2385
|
+
tertiary: "Tertiary",
|
|
2386
|
+
quaternary: "Quaternary",
|
|
2387
|
+
bookmark: "Bookmark",
|
|
2388
|
+
see: "Cross Reference",
|
|
2389
|
+
commentQuerySection: "Comment/Query",
|
|
2390
|
+
comment: "Comment",
|
|
2391
|
+
content: "Content",
|
|
2392
|
+
query: "Query",
|
|
2393
|
+
reply: "Reply",
|
|
2394
|
+
deletion: "Deletion",
|
|
2395
|
+
emphasis: "Emphasis",
|
|
2396
|
+
highlightmark: "Highlightmark",
|
|
2397
|
+
i: "Italic",
|
|
2398
|
+
insertion: "Insertion",
|
|
2399
|
+
sc: "Small Caps",
|
|
2400
|
+
strike: "Strike",
|
|
2401
|
+
sub: "Subscript",
|
|
2402
|
+
sup: "Superscript",
|
|
2403
|
+
u: "Underline",
|
|
2404
|
+
b: "Bold",
|
|
2405
|
+
referenceMark: "Reference Mark",
|
|
2406
|
+
degrees: "Degrees",
|
|
2407
|
+
email: "Email",
|
|
2408
|
+
equation: "Equation",
|
|
2409
|
+
fignote: "Fignote",
|
|
2410
|
+
figsource: "Figsource",
|
|
2411
|
+
firstname: "Firstname",
|
|
2412
|
+
footnote: "Footnote Marker",
|
|
2413
|
+
footnoteno: "Footnote Number",
|
|
2414
|
+
honorific: "Honorific",
|
|
2415
|
+
img: "Image",
|
|
2416
|
+
informalfigure: "Floating Figure",
|
|
2417
|
+
keyword: "Keyword",
|
|
2418
|
+
label1: "Label",
|
|
2419
|
+
li: "List Item",
|
|
2420
|
+
line: "Line",
|
|
2421
|
+
lrh: "Running Head Left",
|
|
2422
|
+
math: "Math",
|
|
2423
|
+
mathphrase: "Math Phrase",
|
|
2424
|
+
merror: "Math Error",
|
|
2425
|
+
mfrac: "Math Fraction",
|
|
2426
|
+
mi: "Math Identifier",
|
|
2427
|
+
mmultiscripts: "Math Multiscripts",
|
|
2428
|
+
mn: "Math Number",
|
|
2429
|
+
mo: "Math Operator",
|
|
2430
|
+
mover: "Math Over",
|
|
2431
|
+
mpadded: "Math Padded",
|
|
2432
|
+
mphantom: "Math Phantom",
|
|
2433
|
+
mprescripts: "Math Prescripts",
|
|
2434
|
+
mroot: "Math Root",
|
|
2435
|
+
mrow: "Math Row",
|
|
2436
|
+
ms: "Math Space",
|
|
2437
|
+
mspace: "Math Space",
|
|
2438
|
+
msqrt: "Math Square Root",
|
|
2439
|
+
mstyle: "Math Style",
|
|
2440
|
+
msub: "Math Subscript",
|
|
2441
|
+
msubsup: "Math Subscript Superscript",
|
|
2442
|
+
msup: "Math Superscript",
|
|
2443
|
+
mtable: "Math Table",
|
|
2444
|
+
mtd: "Math Table Data",
|
|
2445
|
+
mtext: "Math Text",
|
|
2446
|
+
mtr: "Math Table Row",
|
|
2447
|
+
munder: "Math Under",
|
|
2448
|
+
munderover: "Math Under Over",
|
|
2449
|
+
olink: "Online Link",
|
|
2450
|
+
org: "Org",
|
|
2451
|
+
orgname: "Orgname",
|
|
2452
|
+
para: "Paragraph",
|
|
2453
|
+
punc: "Punctuation",
|
|
2454
|
+
rrh: "Running Head Right",
|
|
2455
|
+
source1: "Source",
|
|
2456
|
+
speaker: "Speaker",
|
|
2457
|
+
subtitle1: "Subtitle",
|
|
2458
|
+
surname: "Surname",
|
|
2459
|
+
tag: "Tag",
|
|
2460
|
+
tblfn: "Table Footnote",
|
|
2461
|
+
tblsource: "Table Source",
|
|
2462
|
+
thead: "Thead",
|
|
2463
|
+
title1: "Title",
|
|
2464
|
+
token: "Token",
|
|
2465
|
+
tp: "Table Paragraph",
|
|
2466
|
+
abstract1: "Abstract",
|
|
2467
|
+
affiliation: "Affiliation",
|
|
2468
|
+
alttext: "Alttext",
|
|
2469
|
+
appendix: "Appendix",
|
|
2470
|
+
author: "Author",
|
|
2471
|
+
authorgroup: "Authorgroup",
|
|
2472
|
+
blockquote: "Blockquote",
|
|
2473
|
+
caption1: "Caption",
|
|
2474
|
+
chapter: "Chapter",
|
|
2475
|
+
dialogue: "Dialogue",
|
|
2476
|
+
epigraph: "Epigraph",
|
|
2477
|
+
figure1: "Figure",
|
|
2478
|
+
footnoteSection: "Footnote Section",
|
|
2479
|
+
heading: "Heading",
|
|
2480
|
+
imageobject: "Image Object",
|
|
2481
|
+
info1: "Info",
|
|
2482
|
+
keywordset: "Keyword FGroup",
|
|
2483
|
+
mediaobject: "Mediaobject",
|
|
2484
|
+
ol: "Ordered List",
|
|
2485
|
+
personname: "Person Name",
|
|
2486
|
+
poem: "Poem",
|
|
2487
|
+
sidebar: "Box",
|
|
2488
|
+
table: "Table",
|
|
2489
|
+
table1: "Table",
|
|
2490
|
+
tbody: "Table Body",
|
|
2491
|
+
td: "Table Data",
|
|
2492
|
+
tgroup: "Table Group",
|
|
2493
|
+
tr: "Table Row",
|
|
2494
|
+
ul: "Unordered List",
|
|
2495
|
+
footnote1: "Footnote",
|
|
2496
|
+
inlineequation: "Inline Equation",
|
|
2497
|
+
link: "Link",
|
|
2498
|
+
uri: "URI",
|
|
2499
|
+
phrase: "Phrase",
|
|
2500
|
+
abbreviation: "Abbreviation"
|
|
2501
|
+
};
|
|
2502
|
+
|
|
2399
2503
|
// src/schema/shared/dependentsForbiddenElements.ts
|
|
2400
2504
|
var DEPENDENT_FORBIDDEN_ELEMENTS = [
|
|
2401
2505
|
{
|
|
@@ -2435,6 +2539,25 @@ var retrieveTextIgnoringNodesWithSelector = (element, selector = ".del") => {
|
|
|
2435
2539
|
return clonedElement.textContent || "";
|
|
2436
2540
|
};
|
|
2437
2541
|
|
|
2542
|
+
// src/validation/utils/getElementsSelector.ts
|
|
2543
|
+
var getElementsSelector = ({
|
|
2544
|
+
element,
|
|
2545
|
+
selector,
|
|
2546
|
+
filterDeletedNodes
|
|
2547
|
+
}) => {
|
|
2548
|
+
const elements = element.querySelectorAll(selector);
|
|
2549
|
+
if (filterDeletedNodes) {
|
|
2550
|
+
return Array.from(elements).filter((element2) => {
|
|
2551
|
+
const hasDeletedParent = element2.closest(".del") !== null;
|
|
2552
|
+
if (hasDeletedParent) {
|
|
2553
|
+
return false;
|
|
2554
|
+
}
|
|
2555
|
+
return true;
|
|
2556
|
+
});
|
|
2557
|
+
}
|
|
2558
|
+
return Array.from(elements);
|
|
2559
|
+
};
|
|
2560
|
+
|
|
2438
2561
|
// src/validation/validateFootnotes.ts
|
|
2439
2562
|
var extractFootnoteNumber = (footnote) => {
|
|
2440
2563
|
if (!footnote) return "no label";
|
|
@@ -2477,7 +2600,11 @@ var validateFootnoteCue = (footnoteElement, root) => {
|
|
|
2477
2600
|
return errors;
|
|
2478
2601
|
};
|
|
2479
2602
|
var validateConsecutiveFootnotes = (root) => {
|
|
2480
|
-
const footnotes =
|
|
2603
|
+
const footnotes = getElementsSelector({
|
|
2604
|
+
element: root,
|
|
2605
|
+
selector: FOOTNOTE_SCHEMA.tag,
|
|
2606
|
+
filterDeletedNodes: true
|
|
2607
|
+
});
|
|
2481
2608
|
if (footnotes.length === 0) {
|
|
2482
2609
|
return [];
|
|
2483
2610
|
}
|
|
@@ -2506,9 +2633,11 @@ var validateConsecutiveFootnotes = (root) => {
|
|
|
2506
2633
|
return [];
|
|
2507
2634
|
};
|
|
2508
2635
|
var validateConsecutiveFootnoteCues = (root) => {
|
|
2509
|
-
const footnoteLinks =
|
|
2510
|
-
root
|
|
2511
|
-
|
|
2636
|
+
const footnoteLinks = getElementsSelector({
|
|
2637
|
+
element: root,
|
|
2638
|
+
selector: FOOTNOTE_LINK_SCHEMA.tag,
|
|
2639
|
+
filterDeletedNodes: true
|
|
2640
|
+
});
|
|
2512
2641
|
if (footnoteLinks.length === 0) {
|
|
2513
2642
|
return [];
|
|
2514
2643
|
}
|
|
@@ -2535,6 +2664,13 @@ var validateConsecutiveFootnoteCues = (root) => {
|
|
|
2535
2664
|
var findElementLinkedTo = (linkend, elementsToLink) => {
|
|
2536
2665
|
return elementsToLink.includes(linkend);
|
|
2537
2666
|
};
|
|
2667
|
+
var LINK_BLOCKER_ROLES = [
|
|
2668
|
+
TABLE_LINK_ROLE,
|
|
2669
|
+
FIGURE_LINK_ROLE,
|
|
2670
|
+
EQUATION_LINK_ROLE,
|
|
2671
|
+
FOOTNOTE_LINK_ROLE,
|
|
2672
|
+
CHAPTER_LINK_ROLE
|
|
2673
|
+
];
|
|
2538
2674
|
var validateLinkend = (linkElement, elementsToLink) => {
|
|
2539
2675
|
const linkend = linkElement.getAttribute("linkend");
|
|
2540
2676
|
if (!linkend) {
|
|
@@ -2555,22 +2691,27 @@ var validateLinkend = (linkElement, elementsToLink) => {
|
|
|
2555
2691
|
})
|
|
2556
2692
|
];
|
|
2557
2693
|
}
|
|
2694
|
+
const role = linkElement.getAttribute("role");
|
|
2695
|
+
if (!role) {
|
|
2696
|
+
return [];
|
|
2697
|
+
}
|
|
2558
2698
|
if (findElementLinkedTo(linkend, elementsToLink)) {
|
|
2559
2699
|
return [];
|
|
2560
2700
|
}
|
|
2701
|
+
const isBlocker = LINK_BLOCKER_ROLES.includes(role.toLowerCase());
|
|
2561
2702
|
return [
|
|
2562
2703
|
createValidationIssue({
|
|
2563
2704
|
store: getStore(linkElement),
|
|
2564
2705
|
title: "Unlinked element",
|
|
2565
2706
|
kind: "unlinked",
|
|
2566
|
-
description: "This link is not referenced to any element in the current chapter or
|
|
2567
|
-
level: "blocker"
|
|
2707
|
+
description: "This link is not referenced to any element in the current chapter or any other chapter. Please link it again manually.",
|
|
2708
|
+
level: isBlocker ? "blocker" : "warning"
|
|
2568
2709
|
})
|
|
2569
2710
|
];
|
|
2570
2711
|
};
|
|
2571
2712
|
|
|
2572
2713
|
// src/validation/validateAttributes.ts
|
|
2573
|
-
var
|
|
2714
|
+
var validateAttributes = (element, schema) => {
|
|
2574
2715
|
const errors = [];
|
|
2575
2716
|
const definitions = [
|
|
2576
2717
|
...schema.requiredAttributes,
|
|
@@ -2598,8 +2739,8 @@ var validateAttributes2 = (element, schema) => {
|
|
|
2598
2739
|
}
|
|
2599
2740
|
if (!definition.values.includes(value)) {
|
|
2600
2741
|
addValidationIssue(errors, {
|
|
2601
|
-
store: element
|
|
2602
|
-
title: `Invalid attribute value "${value}"`,
|
|
2742
|
+
store: getStore(element),
|
|
2743
|
+
title: `Invalid attribute value "${value}" in element ${element.tagName}`,
|
|
2603
2744
|
level: "warning",
|
|
2604
2745
|
kind: "forbidden",
|
|
2605
2746
|
description: `The attribute "${name}" has an invalid value "${value}".`
|
|
@@ -2621,7 +2762,7 @@ var validateElementAgainstSchema = (element, schema) => {
|
|
|
2621
2762
|
description: `The element is not allowed in this context.`
|
|
2622
2763
|
});
|
|
2623
2764
|
}
|
|
2624
|
-
errors.push(...
|
|
2765
|
+
errors.push(...validateAttributes(element, schema));
|
|
2625
2766
|
errors.push(...validateChildren(element, schema));
|
|
2626
2767
|
return errors;
|
|
2627
2768
|
};
|
|
@@ -2636,7 +2777,7 @@ var validateRequiredChildren = (element, schema, childElements) => {
|
|
|
2636
2777
|
return childSchema?.code === allowedChild.code;
|
|
2637
2778
|
});
|
|
2638
2779
|
if (!hasChild) {
|
|
2639
|
-
const requiredChildrenTag = findSchemaByCode(allowedChild.code)
|
|
2780
|
+
const requiredChildrenTag = findSchemaByCode(allowedChild.code).tag;
|
|
2640
2781
|
addValidationIssue(errors, {
|
|
2641
2782
|
store: getStore(element),
|
|
2642
2783
|
title: `Missing required child element ${requiredChildrenTag}`,
|
|
@@ -2733,7 +2874,34 @@ var validateReferenceCited = (referenceElement, linkElements) => {
|
|
|
2733
2874
|
title: "Unlinked element",
|
|
2734
2875
|
kind: "unlinked",
|
|
2735
2876
|
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: "
|
|
2877
|
+
level: "warning"
|
|
2878
|
+
})
|
|
2879
|
+
];
|
|
2880
|
+
};
|
|
2881
|
+
|
|
2882
|
+
// src/validation/validateUri.ts
|
|
2883
|
+
var WEB_URI_REGEX = /^(?:(?:https?):\/\/)?(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(?::\d{1,5})?(?:\/[^\s]*)?$/i;
|
|
2884
|
+
var isValidUri = (uri) => {
|
|
2885
|
+
if (!uri || /\s/.test(uri)) {
|
|
2886
|
+
return false;
|
|
2887
|
+
}
|
|
2888
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(uri) && !/^https?:\/\//i.test(uri)) {
|
|
2889
|
+
return false;
|
|
2890
|
+
}
|
|
2891
|
+
return WEB_URI_REGEX.test(uri);
|
|
2892
|
+
};
|
|
2893
|
+
var validateUri = (uriElement) => {
|
|
2894
|
+
const url = uriElement.textContent.trim();
|
|
2895
|
+
if (isValidUri(url)) {
|
|
2896
|
+
return [];
|
|
2897
|
+
}
|
|
2898
|
+
return [
|
|
2899
|
+
createValidationIssue({
|
|
2900
|
+
store: getStore(uriElement),
|
|
2901
|
+
title: "URL cannot be reached",
|
|
2902
|
+
kind: "unlinked",
|
|
2903
|
+
description: "URL cannot be reached. Please check and adjust.",
|
|
2904
|
+
level: "warning"
|
|
2737
2905
|
})
|
|
2738
2906
|
];
|
|
2739
2907
|
};
|
|
@@ -2760,6 +2928,9 @@ var validateElement = (element, root, elementsToLink, linkElements, schemasToVal
|
|
|
2760
2928
|
if (schema.tag === FOOTNOTE_SCHEMA.tag) {
|
|
2761
2929
|
errors.push(...validateFootnoteCue(element, root));
|
|
2762
2930
|
}
|
|
2931
|
+
if (schema.tag === URI_SCHEMA.tag) {
|
|
2932
|
+
errors.push(...validateUri(element));
|
|
2933
|
+
}
|
|
2763
2934
|
if (isIgnoredValidation(schema.code)) {
|
|
2764
2935
|
return errors;
|
|
2765
2936
|
}
|
|
@@ -2800,6 +2971,7 @@ export {
|
|
|
2800
2971
|
DEPENDENT_FORBIDDEN_ELEMENTS,
|
|
2801
2972
|
ELEMENT_SCHEMAS,
|
|
2802
2973
|
ELE_ID_ATTRIBUTE,
|
|
2974
|
+
ElementLabel,
|
|
2803
2975
|
FIGURE_PLACEMENT_ATTRIBUTE,
|
|
2804
2976
|
ID_ATTRS,
|
|
2805
2977
|
IGNORED_ATTRIBUTES,
|
|
@@ -2830,7 +3002,6 @@ export {
|
|
|
2830
3002
|
findAttributeDefinitionByName,
|
|
2831
3003
|
findSchemaByCode,
|
|
2832
3004
|
findSchemaByElement,
|
|
2833
|
-
findSchemaByTagName,
|
|
2834
3005
|
getAttributeName,
|
|
2835
3006
|
isAttributeRestricted,
|
|
2836
3007
|
isIgnoredAttribute,
|