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.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
- code,
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,8 +242,15 @@ 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
- optionalAttributes: [],
247
+ optionalAttributes: [
248
+ {
249
+ name: "role",
250
+ values: ["web-link", "figure-note-link", "figsource"],
251
+ defaultValue: ""
252
+ }
253
+ ],
259
254
  allowedChildrenCodes: [
260
255
  ...ATOM_CODES_ALLOWED_CHILDREN,
261
256
  ...INLINE_ELEMENT_CODES_ALLOWED_CHILDREN
@@ -549,6 +544,27 @@ var REFERENCE_MARK_SCHEMA = createSchema({
549
544
  allowedChildrenCodes: [...ATOM_CODES_ALLOWED_CHILDREN]
550
545
  });
551
546
 
547
+ // src/schema/elementSchemas/atoms/abbr.ts
548
+ var ABBR_SCHEMA = createSchema({
549
+ code: "abbreviation",
550
+ kind: "atom",
551
+ tag: ABBR_TAG,
552
+ requiredAttributes: [
553
+ ...ID_ATTRS,
554
+ "title",
555
+ TRACK_CHANGES_ATTR_DATA_TIME,
556
+ TRACK_CHANGES_ATTR_DATA_USERID,
557
+ TRACK_CHANGES_ATTR_DATA_USERNAME,
558
+ {
559
+ name: "data-abbr-action",
560
+ values: ["add", "edit"],
561
+ defaultValue: "add"
562
+ }
563
+ ],
564
+ optionalAttributes: [],
565
+ allowedChildrenCodes: [...ATOM_CODES_ALLOWED_CHILDREN]
566
+ });
567
+
552
568
  // src/schema/elementSchemas/atoms/index.ts
553
569
  var ATOM_SCHEMAS = {
554
570
  indexterm: INDEXTERM_SCHEMA,
@@ -574,7 +590,8 @@ var ATOM_SCHEMAS = {
574
590
  content: CONTENT_SCHEMA,
575
591
  comment: COMMENT_SCHEMA,
576
592
  query: QUERY_SCHEMA,
577
- reply: REPLY_SCHEMA
593
+ reply: REPLY_SCHEMA,
594
+ abbreviation: ABBR_SCHEMA
578
595
  };
579
596
 
580
597
  // src/schema/elementSchemas/elements/elementsTags.ts
@@ -1975,15 +1992,21 @@ var EPIGRAPH_SCHEMA = createSchema({
1975
1992
  });
1976
1993
 
1977
1994
  // src/schema/elementSchemas/elements/footnoteSection.ts
1995
+ var FOOTNOTE_SECTION_ROLES = ["ch", "bk"];
1978
1996
  var FOOTNOTE_SECTION_SCHEMA = createSchema({
1979
1997
  code: "footnoteSection",
1980
1998
  kind: "element",
1981
1999
  tag: SECTION_TAG,
2000
+ matchesElement: (element) => {
2001
+ const role = element.getAttribute("role");
2002
+ if (role && FOOTNOTE_SECTION_ROLES.includes(role)) return true;
2003
+ return element.querySelector(FOOTNOTE_TAG) !== null;
2004
+ },
1982
2005
  requiredAttributes: [
1983
2006
  ...ID_ATTRS,
1984
2007
  {
1985
2008
  name: "role",
1986
- values: ["ch", "bk"],
2009
+ values: FOOTNOTE_SECTION_ROLES,
1987
2010
  defaultValue: "ch"
1988
2011
  }
1989
2012
  ],
@@ -1996,16 +2019,22 @@ var FOOTNOTE_SECTION_SCHEMA = createSchema({
1996
2019
  });
1997
2020
 
1998
2021
  // src/schema/elementSchemas/elements/heading.ts
2022
+ var HEADING_ROLES = ["H1", "H2", "H3", "H4", "H5", "H6", "vignette_group"];
1999
2023
  var HEADING_SCHEMA = createSchema({
2000
2024
  code: "heading",
2001
2025
  kind: "element",
2002
2026
  tag: SECTION_TAG,
2027
+ matchesElement: (element) => {
2028
+ const role = element.getAttribute("role");
2029
+ if (!role) return false;
2030
+ return HEADING_ROLES.includes(role);
2031
+ },
2003
2032
  requiredAttributes: [
2004
2033
  ...ID_ATTRS,
2005
2034
  "xmlid",
2006
2035
  {
2007
2036
  name: "role",
2008
- values: ["H1", "H2", "H3", "H4", "H5", "H6", "vignette_group"],
2037
+ values: HEADING_ROLES,
2009
2038
  defaultValue: "H1"
2010
2039
  }
2011
2040
  ],
@@ -2073,7 +2102,6 @@ var MATHPHRASE_SCHEMA = createSchema({
2073
2102
  requiredAttributes: [ELE_ID_ATTRIBUTE],
2074
2103
  optionalAttributes: [],
2075
2104
  allowedChildrenCodes: [{ code: MATH_SCHEMA.code, required: true }]
2076
- // TODO: Should have flag for insertion and deletion
2077
2105
  });
2078
2106
 
2079
2107
  // src/schema/elementSchemas/elements/reference/bibliodiv.ts
@@ -2277,6 +2305,12 @@ var INLINEEQUATION_SCHEMA = createSchema({
2277
2305
  });
2278
2306
 
2279
2307
  // src/schema/elementSchemas/inlineElements/link.ts
2308
+ var TABLE_LINK_ROLE = "table";
2309
+ var FIGURE_LINK_ROLE = "figure";
2310
+ var EQUATION_LINK_ROLE = "equation";
2311
+ var FOOTNOTE_LINK_ROLE = "footnote";
2312
+ var REFERENCE_LINK_ROLE = "bibr";
2313
+ var CHAPTER_LINK_ROLE = "chapter";
2280
2314
  var LINK_SCHEMA = createSchema({
2281
2315
  code: "link",
2282
2316
  kind: "inline",
@@ -2284,14 +2318,20 @@ var LINK_SCHEMA = createSchema({
2284
2318
  requiredAttributes: [
2285
2319
  ...ID_ATTRS,
2286
2320
  "linkend",
2287
- "data-target-id",
2288
2321
  {
2289
2322
  name: "role",
2290
- values: ["table", "figure", "equation", "footnote", "bibr"],
2291
- defaultValue: ""
2323
+ values: [
2324
+ TABLE_LINK_ROLE,
2325
+ FIGURE_LINK_ROLE,
2326
+ EQUATION_LINK_ROLE,
2327
+ FOOTNOTE_LINK_ROLE,
2328
+ REFERENCE_LINK_ROLE,
2329
+ CHAPTER_LINK_ROLE
2330
+ ],
2331
+ defaultValue: "bibr"
2292
2332
  }
2293
2333
  ],
2294
- optionalAttributes: [],
2334
+ optionalAttributes: ["data-target-id"],
2295
2335
  allowedChildrenCodes: [...ATOM_CODES_ALLOWED_CHILDREN]
2296
2336
  });
2297
2337
 
@@ -2300,8 +2340,8 @@ var URI_SCHEMA = createSchema({
2300
2340
  code: "uri",
2301
2341
  kind: "inline",
2302
2342
  tag: URI_TAG,
2303
- requiredAttributes: [...ID_ATTRS],
2304
- optionalAttributes: ["linkend"],
2343
+ requiredAttributes: [],
2344
+ optionalAttributes: ["xlinkhref"],
2305
2345
  allowedChildrenCodes: [...ATOM_CODES_ALLOWED_CHILDREN]
2306
2346
  });
2307
2347
 
@@ -2371,42 +2411,11 @@ var isIgnoredAttribute = (attribute) => IGNORED_ATTRIBUTES.includes(attribute) |
2371
2411
  var isIgnoredElement = (element) => IGNORED_ELEMENT_SELECTORS.some((selector) => element.matches(selector));
2372
2412
  var isIgnoredValidation = (code) => IGNORED_VALIDATION_ELEMENT_SELECTORS.includes(code);
2373
2413
  var findSchemaByCode = (code) => SCHEMAS[code];
2374
- var findSchemaByTagName = (tagName) => Object.values(SCHEMAS).filter(
2375
- (schema) => schema.tag === tagName.toUpperCase()
2376
- );
2377
2414
  var findSchemaByElement = (element) => {
2378
- const tagName = element.tagName.toUpperCase();
2379
- const isInsertion = element.classList.contains("ins");
2380
- const isDeletion = element.classList.contains("del");
2381
- const isQueryComment = element.classList.contains("cmtQurySection");
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];
2415
+ const schema = Object.values(SCHEMAS).find(
2416
+ (schema2) => schema2.tag == element.tagName && (!schema2.matchesElement || schema2.matchesElement(element))
2417
+ );
2418
+ return schema;
2410
2419
  };
2411
2420
  var isAttributeRestricted = (attr) => typeof attr !== "string";
2412
2421
  var getAttributeName = (attribute) => typeof attribute === "string" ? attribute.toLowerCase() : attribute.name.toLowerCase();
@@ -2420,50 +2429,145 @@ var findAttributeDefinitionByName = (definitions, name) => {
2420
2429
  };
2421
2430
 
2422
2431
  // 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
2432
  var createElement = ({
2449
2433
  schemaCode,
2450
2434
  attributes
2451
2435
  }) => {
2452
2436
  const schema = findSchemaByCode(schemaCode);
2453
- if (!schema) {
2454
- throw new Error(`Schema not found for code: ${schemaCode}`);
2455
- }
2456
- validateAttributes(attributes, schema);
2457
2437
  const element = document.createElement(schema.tag.toLowerCase());
2458
2438
  for (const [name, value] of Object.entries(attributes)) {
2459
- if (value === void 0) {
2460
- continue;
2461
- }
2439
+ if (!value) continue;
2462
2440
  element.setAttribute(name, String(value));
2463
2441
  }
2464
2442
  return element;
2465
2443
  };
2466
2444
 
2445
+ // src/schema/shared/labelElements.ts
2446
+ var ElementLabel = {
2447
+ referenceBibliomixed: "Reference Bibliomixed",
2448
+ referenceBibliography: "Reference Bibliography",
2449
+ bibliodiv: "Bibliodiv",
2450
+ indexterm: "Indexterm",
2451
+ primary: "Primary",
2452
+ secondary: "Secondary",
2453
+ tertiary: "Tertiary",
2454
+ quaternary: "Quaternary",
2455
+ bookmark: "Bookmark",
2456
+ see: "Cross Reference",
2457
+ commentQuerySection: "Comment/Query",
2458
+ comment: "Comment",
2459
+ content: "Content",
2460
+ query: "Query",
2461
+ reply: "Reply",
2462
+ deletion: "Deletion",
2463
+ emphasis: "Emphasis",
2464
+ highlightmark: "Highlightmark",
2465
+ i: "Italic",
2466
+ insertion: "Insertion",
2467
+ sc: "Small Caps",
2468
+ strike: "Strike",
2469
+ sub: "Subscript",
2470
+ sup: "Superscript",
2471
+ u: "Underline",
2472
+ b: "Bold",
2473
+ referenceMark: "Reference Mark",
2474
+ degrees: "Degrees",
2475
+ email: "Email",
2476
+ equation: "Equation",
2477
+ fignote: "Fignote",
2478
+ figsource: "Figsource",
2479
+ firstname: "Firstname",
2480
+ footnote: "Footnote Marker",
2481
+ footnoteno: "Footnote Number",
2482
+ honorific: "Honorific",
2483
+ img: "Image",
2484
+ informalfigure: "Floating Figure",
2485
+ keyword: "Keyword",
2486
+ label1: "Label",
2487
+ li: "List Item",
2488
+ line: "Line",
2489
+ lrh: "Running Head Left",
2490
+ math: "Math",
2491
+ mathphrase: "Math Phrase",
2492
+ merror: "Math Error",
2493
+ mfrac: "Math Fraction",
2494
+ mi: "Math Identifier",
2495
+ mmultiscripts: "Math Multiscripts",
2496
+ mn: "Math Number",
2497
+ mo: "Math Operator",
2498
+ mover: "Math Over",
2499
+ mpadded: "Math Padded",
2500
+ mphantom: "Math Phantom",
2501
+ mprescripts: "Math Prescripts",
2502
+ mroot: "Math Root",
2503
+ mrow: "Math Row",
2504
+ ms: "Math Space",
2505
+ mspace: "Math Space",
2506
+ msqrt: "Math Square Root",
2507
+ mstyle: "Math Style",
2508
+ msub: "Math Subscript",
2509
+ msubsup: "Math Subscript Superscript",
2510
+ msup: "Math Superscript",
2511
+ mtable: "Math Table",
2512
+ mtd: "Math Table Data",
2513
+ mtext: "Math Text",
2514
+ mtr: "Math Table Row",
2515
+ munder: "Math Under",
2516
+ munderover: "Math Under Over",
2517
+ olink: "Online Link",
2518
+ org: "Org",
2519
+ orgname: "Orgname",
2520
+ para: "Paragraph",
2521
+ punc: "Punctuation",
2522
+ rrh: "Running Head Right",
2523
+ source1: "Source",
2524
+ speaker: "Speaker",
2525
+ subtitle1: "Subtitle",
2526
+ surname: "Surname",
2527
+ tag: "Tag",
2528
+ tblfn: "Table Footnote",
2529
+ tblsource: "Table Source",
2530
+ thead: "Thead",
2531
+ title1: "Title",
2532
+ token: "Token",
2533
+ tp: "Table Paragraph",
2534
+ abstract1: "Abstract",
2535
+ affiliation: "Affiliation",
2536
+ alttext: "Alttext",
2537
+ appendix: "Appendix",
2538
+ author: "Author",
2539
+ authorgroup: "Authorgroup",
2540
+ blockquote: "Blockquote",
2541
+ caption1: "Caption",
2542
+ chapter: "Chapter",
2543
+ dialogue: "Dialogue",
2544
+ epigraph: "Epigraph",
2545
+ figure1: "Figure",
2546
+ footnoteSection: "Footnote Section",
2547
+ heading: "Heading",
2548
+ imageobject: "Image Object",
2549
+ info1: "Info",
2550
+ keywordset: "Keyword FGroup",
2551
+ mediaobject: "Mediaobject",
2552
+ ol: "Ordered List",
2553
+ personname: "Person Name",
2554
+ poem: "Poem",
2555
+ sidebar: "Box",
2556
+ table: "Table",
2557
+ table1: "Table",
2558
+ tbody: "Table Body",
2559
+ td: "Table Data",
2560
+ tgroup: "Table Group",
2561
+ tr: "Table Row",
2562
+ ul: "Unordered List",
2563
+ footnote1: "Footnote",
2564
+ inlineequation: "Inline Equation",
2565
+ link: "Link",
2566
+ uri: "URI",
2567
+ phrase: "Phrase",
2568
+ abbreviation: "Abbreviation"
2569
+ };
2570
+
2467
2571
  // src/schema/shared/dependentsForbiddenElements.ts
2468
2572
  var DEPENDENT_FORBIDDEN_ELEMENTS = [
2469
2573
  {
@@ -2503,6 +2607,25 @@ var retrieveTextIgnoringNodesWithSelector = (element, selector = ".del") => {
2503
2607
  return clonedElement.textContent || "";
2504
2608
  };
2505
2609
 
2610
+ // src/validation/utils/getElementsSelector.ts
2611
+ var getElementsSelector = ({
2612
+ element,
2613
+ selector,
2614
+ filterDeletedNodes
2615
+ }) => {
2616
+ const elements = element.querySelectorAll(selector);
2617
+ if (filterDeletedNodes) {
2618
+ return Array.from(elements).filter((element2) => {
2619
+ const hasDeletedParent = element2.closest(".del") !== null;
2620
+ if (hasDeletedParent) {
2621
+ return false;
2622
+ }
2623
+ return true;
2624
+ });
2625
+ }
2626
+ return Array.from(elements);
2627
+ };
2628
+
2506
2629
  // src/validation/validateFootnotes.ts
2507
2630
  var extractFootnoteNumber = (footnote) => {
2508
2631
  if (!footnote) return "no label";
@@ -2545,7 +2668,11 @@ var validateFootnoteCue = (footnoteElement, root) => {
2545
2668
  return errors;
2546
2669
  };
2547
2670
  var validateConsecutiveFootnotes = (root) => {
2548
- const footnotes = Array.from(root.querySelectorAll(FOOTNOTE_SCHEMA.tag));
2671
+ const footnotes = getElementsSelector({
2672
+ element: root,
2673
+ selector: FOOTNOTE_SCHEMA.tag,
2674
+ filterDeletedNodes: true
2675
+ });
2549
2676
  if (footnotes.length === 0) {
2550
2677
  return [];
2551
2678
  }
@@ -2574,9 +2701,11 @@ var validateConsecutiveFootnotes = (root) => {
2574
2701
  return [];
2575
2702
  };
2576
2703
  var validateConsecutiveFootnoteCues = (root) => {
2577
- const footnoteLinks = Array.from(
2578
- root.querySelectorAll(FOOTNOTE_LINK_SCHEMA.tag)
2579
- );
2704
+ const footnoteLinks = getElementsSelector({
2705
+ element: root,
2706
+ selector: FOOTNOTE_LINK_SCHEMA.tag,
2707
+ filterDeletedNodes: true
2708
+ });
2580
2709
  if (footnoteLinks.length === 0) {
2581
2710
  return [];
2582
2711
  }
@@ -2603,6 +2732,13 @@ var validateConsecutiveFootnoteCues = (root) => {
2603
2732
  var findElementLinkedTo = (linkend, elementsToLink) => {
2604
2733
  return elementsToLink.includes(linkend);
2605
2734
  };
2735
+ var LINK_BLOCKER_ROLES = [
2736
+ TABLE_LINK_ROLE,
2737
+ FIGURE_LINK_ROLE,
2738
+ EQUATION_LINK_ROLE,
2739
+ FOOTNOTE_LINK_ROLE,
2740
+ CHAPTER_LINK_ROLE
2741
+ ];
2606
2742
  var validateLinkend = (linkElement, elementsToLink) => {
2607
2743
  const linkend = linkElement.getAttribute("linkend");
2608
2744
  if (!linkend) {
@@ -2623,22 +2759,27 @@ var validateLinkend = (linkElement, elementsToLink) => {
2623
2759
  })
2624
2760
  ];
2625
2761
  }
2762
+ const role = linkElement.getAttribute("role");
2763
+ if (!role) {
2764
+ return [];
2765
+ }
2626
2766
  if (findElementLinkedTo(linkend, elementsToLink)) {
2627
2767
  return [];
2628
2768
  }
2769
+ const isBlocker = LINK_BLOCKER_ROLES.includes(role.toLowerCase());
2629
2770
  return [
2630
2771
  createValidationIssue({
2631
2772
  store: getStore(linkElement),
2632
2773
  title: "Unlinked element",
2633
2774
  kind: "unlinked",
2634
- description: "This link is not referenced to any element in the current chapter or reference chapters. Please link it again manually.",
2635
- level: "blocker"
2775
+ description: "This link is not referenced to any element in the current chapter or any other chapter. Please link it again manually.",
2776
+ level: isBlocker ? "blocker" : "warning"
2636
2777
  })
2637
2778
  ];
2638
2779
  };
2639
2780
 
2640
2781
  // src/validation/validateAttributes.ts
2641
- var validateAttributes2 = (element, schema) => {
2782
+ var validateAttributes = (element, schema) => {
2642
2783
  const errors = [];
2643
2784
  const definitions = [
2644
2785
  ...schema.requiredAttributes,
@@ -2666,8 +2807,8 @@ var validateAttributes2 = (element, schema) => {
2666
2807
  }
2667
2808
  if (!definition.values.includes(value)) {
2668
2809
  addValidationIssue(errors, {
2669
- store: element.id,
2670
- title: `Invalid attribute value "${value}"`,
2810
+ store: getStore(element),
2811
+ title: `Invalid attribute value "${value}" in element ${element.tagName}`,
2671
2812
  level: "warning",
2672
2813
  kind: "forbidden",
2673
2814
  description: `The attribute "${name}" has an invalid value "${value}".`
@@ -2689,7 +2830,7 @@ var validateElementAgainstSchema = (element, schema) => {
2689
2830
  description: `The element is not allowed in this context.`
2690
2831
  });
2691
2832
  }
2692
- errors.push(...validateAttributes2(element, schema));
2833
+ errors.push(...validateAttributes(element, schema));
2693
2834
  errors.push(...validateChildren(element, schema));
2694
2835
  return errors;
2695
2836
  };
@@ -2704,7 +2845,7 @@ var validateRequiredChildren = (element, schema, childElements) => {
2704
2845
  return childSchema?.code === allowedChild.code;
2705
2846
  });
2706
2847
  if (!hasChild) {
2707
- const requiredChildrenTag = findSchemaByCode(allowedChild.code)?.tag || allowedChild.code;
2848
+ const requiredChildrenTag = findSchemaByCode(allowedChild.code).tag;
2708
2849
  addValidationIssue(errors, {
2709
2850
  store: getStore(element),
2710
2851
  title: `Missing required child element ${requiredChildrenTag}`,
@@ -2801,7 +2942,34 @@ var validateReferenceCited = (referenceElement, linkElements) => {
2801
2942
  title: "Unlinked element",
2802
2943
  kind: "unlinked",
2803
2944
  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: "blocker"
2945
+ level: "warning"
2946
+ })
2947
+ ];
2948
+ };
2949
+
2950
+ // src/validation/validateUri.ts
2951
+ 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;
2952
+ var isValidUri = (uri) => {
2953
+ if (!uri || /\s/.test(uri)) {
2954
+ return false;
2955
+ }
2956
+ if (/^[a-z][a-z0-9+.-]*:/i.test(uri) && !/^https?:\/\//i.test(uri)) {
2957
+ return false;
2958
+ }
2959
+ return WEB_URI_REGEX.test(uri);
2960
+ };
2961
+ var validateUri = (uriElement) => {
2962
+ const url = uriElement.textContent.trim();
2963
+ if (isValidUri(url)) {
2964
+ return [];
2965
+ }
2966
+ return [
2967
+ createValidationIssue({
2968
+ store: getStore(uriElement),
2969
+ title: "URL cannot be reached",
2970
+ kind: "unlinked",
2971
+ description: "URL cannot be reached. Please check and adjust.",
2972
+ level: "warning"
2805
2973
  })
2806
2974
  ];
2807
2975
  };
@@ -2828,6 +2996,9 @@ var validateElement = (element, root, elementsToLink, linkElements, schemasToVal
2828
2996
  if (schema.tag === FOOTNOTE_SCHEMA.tag) {
2829
2997
  errors.push(...validateFootnoteCue(element, root));
2830
2998
  }
2999
+ if (schema.tag === URI_SCHEMA.tag) {
3000
+ errors.push(...validateUri(element));
3001
+ }
2831
3002
  if (isIgnoredValidation(schema.code)) {
2832
3003
  return errors;
2833
3004
  }
@@ -2869,6 +3040,7 @@ var validateXml = (xml, elementsToLink, linkElements, schemasToValidateAgainst)
2869
3040
  DEPENDENT_FORBIDDEN_ELEMENTS,
2870
3041
  ELEMENT_SCHEMAS,
2871
3042
  ELE_ID_ATTRIBUTE,
3043
+ ElementLabel,
2872
3044
  FIGURE_PLACEMENT_ATTRIBUTE,
2873
3045
  ID_ATTRS,
2874
3046
  IGNORED_ATTRIBUTES,
@@ -2899,7 +3071,6 @@ var validateXml = (xml, elementsToLink, linkElements, schemasToValidateAgainst)
2899
3071
  findAttributeDefinitionByName,
2900
3072
  findSchemaByCode,
2901
3073
  findSchemaByElement,
2902
- findSchemaByTagName,
2903
3074
  getAttributeName,
2904
3075
  isAttributeRestricted,
2905
3076
  isIgnoredAttribute,