pro-editor-schema 1.1.2 → 1.1.3

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 CHANGED
@@ -93,7 +93,7 @@ declare const INLINE_ELEMENT_SCHEMAS: Record<InlineSchemaCode, Schema>;
93
93
  declare const ATOM_SCHEMAS: Record<AtomSchemaCode, Schema>;
94
94
 
95
95
  type ValidationErrorLevel = "blocker" | "warning" | "info";
96
- type ValidationErrorKind = "unlinked" | "forbidden" | "missing" | "converted";
96
+ type ValidationErrorKind = "unlinked" | "forbidden" | "missing" | "converted" | "possible-url" | "unreachable-url";
97
97
  type ValidationError = {
98
98
  id: string;
99
99
  store: string;
package/dist/index.d.ts CHANGED
@@ -93,7 +93,7 @@ declare const INLINE_ELEMENT_SCHEMAS: Record<InlineSchemaCode, Schema>;
93
93
  declare const ATOM_SCHEMAS: Record<AtomSchemaCode, Schema>;
94
94
 
95
95
  type ValidationErrorLevel = "blocker" | "warning" | "info";
96
- type ValidationErrorKind = "unlinked" | "forbidden" | "missing" | "converted";
96
+ type ValidationErrorKind = "unlinked" | "forbidden" | "missing" | "converted" | "possible-url" | "unreachable-url";
97
97
  type ValidationError = {
98
98
  id: string;
99
99
  store: string;
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
@@ -2970,6 +2980,54 @@ var validateReferenceCited = (referenceElement, linkElements) => {
2970
2980
  ];
2971
2981
  };
2972
2982
 
2983
+ // src/validation/validateWeblink.ts
2984
+ var import_mark = __toESM(require("mark.js"));
2985
+ var WEB_URI_PATTERN = "(?:(?:https?):\\/\\/)?(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,}(?::\\d{1,5})?(?:\\/[^\\s]*)?";
2986
+ var WEB_URI_IN_TEXT_REGEX = new RegExp(WEB_URI_PATTERN, "gi");
2987
+ var POSSIBLE_WEBLINK_EXCLUDE_SELECTORS = [
2988
+ "tag",
2989
+ "tag *",
2990
+ ".del",
2991
+ "del *",
2992
+ "uri",
2993
+ "uri *",
2994
+ "query",
2995
+ "query *",
2996
+ "comment",
2997
+ "comment *",
2998
+ ...IGNORED_ELEMENT_SELECTORS
2999
+ ];
3000
+ var collectPossibleWebLinks = (content) => {
3001
+ const clone = content.cloneNode(true);
3002
+ const possibleWebLinks = /* @__PURE__ */ new Set();
3003
+ const instance = new import_mark.default(clone);
3004
+ instance.markRegExp(WEB_URI_IN_TEXT_REGEX, {
3005
+ acrossElements: true,
3006
+ exclude: POSSIBLE_WEBLINK_EXCLUDE_SELECTORS,
3007
+ filter: (_textNode, term) => {
3008
+ possibleWebLinks.add(term);
3009
+ return true;
3010
+ }
3011
+ });
3012
+ return possibleWebLinks;
3013
+ };
3014
+ var validatePossibleWeblinks = (root) => {
3015
+ const errors = [];
3016
+ const possibleWebLinks = collectPossibleWebLinks(root);
3017
+ for (const possibleWebLink of possibleWebLinks) {
3018
+ errors.push(
3019
+ createValidationIssue({
3020
+ store: possibleWebLink,
3021
+ title: "Possible web link",
3022
+ kind: "possible-url",
3023
+ description: "This looks like a URL. Would you like to add weblink tags?",
3024
+ level: "warning"
3025
+ })
3026
+ );
3027
+ }
3028
+ return errors;
3029
+ };
3030
+
2973
3031
  // src/validation/validateXml.ts
2974
3032
  var validateElement = (element, root, elementsToLink, linkElements, schemasToValidateAgainst) => {
2975
3033
  if (isIgnoredElement(element)) {
@@ -3011,6 +3069,7 @@ var validateXml = (xml, elementsToLink, linkElements, schemasToValidateAgainst)
3011
3069
  const errors = [];
3012
3070
  errors.push(...validateConsecutiveFootnotes(xml));
3013
3071
  errors.push(...validateConsecutiveFootnoteCues(xml));
3072
+ errors.push(...validatePossibleWeblinks(xml));
3014
3073
  for (const child of Array.from(xml.children)) {
3015
3074
  errors.push(
3016
3075
  ...validateElement(
package/dist/index.mjs CHANGED
@@ -2902,6 +2902,54 @@ var validateReferenceCited = (referenceElement, linkElements) => {
2902
2902
  ];
2903
2903
  };
2904
2904
 
2905
+ // src/validation/validateWeblink.ts
2906
+ import Mark from "mark.js";
2907
+ var WEB_URI_PATTERN = "(?:(?:https?):\\/\\/)?(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,}(?::\\d{1,5})?(?:\\/[^\\s]*)?";
2908
+ var WEB_URI_IN_TEXT_REGEX = new RegExp(WEB_URI_PATTERN, "gi");
2909
+ var POSSIBLE_WEBLINK_EXCLUDE_SELECTORS = [
2910
+ "tag",
2911
+ "tag *",
2912
+ ".del",
2913
+ "del *",
2914
+ "uri",
2915
+ "uri *",
2916
+ "query",
2917
+ "query *",
2918
+ "comment",
2919
+ "comment *",
2920
+ ...IGNORED_ELEMENT_SELECTORS
2921
+ ];
2922
+ var collectPossibleWebLinks = (content) => {
2923
+ const clone = content.cloneNode(true);
2924
+ const possibleWebLinks = /* @__PURE__ */ new Set();
2925
+ const instance = new Mark(clone);
2926
+ instance.markRegExp(WEB_URI_IN_TEXT_REGEX, {
2927
+ acrossElements: true,
2928
+ exclude: POSSIBLE_WEBLINK_EXCLUDE_SELECTORS,
2929
+ filter: (_textNode, term) => {
2930
+ possibleWebLinks.add(term);
2931
+ return true;
2932
+ }
2933
+ });
2934
+ return possibleWebLinks;
2935
+ };
2936
+ var validatePossibleWeblinks = (root) => {
2937
+ const errors = [];
2938
+ const possibleWebLinks = collectPossibleWebLinks(root);
2939
+ for (const possibleWebLink of possibleWebLinks) {
2940
+ errors.push(
2941
+ createValidationIssue({
2942
+ store: possibleWebLink,
2943
+ title: "Possible web link",
2944
+ kind: "possible-url",
2945
+ description: "This looks like a URL. Would you like to add weblink tags?",
2946
+ level: "warning"
2947
+ })
2948
+ );
2949
+ }
2950
+ return errors;
2951
+ };
2952
+
2905
2953
  // src/validation/validateXml.ts
2906
2954
  var validateElement = (element, root, elementsToLink, linkElements, schemasToValidateAgainst) => {
2907
2955
  if (isIgnoredElement(element)) {
@@ -2943,6 +2991,7 @@ var validateXml = (xml, elementsToLink, linkElements, schemasToValidateAgainst)
2943
2991
  const errors = [];
2944
2992
  errors.push(...validateConsecutiveFootnotes(xml));
2945
2993
  errors.push(...validateConsecutiveFootnoteCues(xml));
2994
+ errors.push(...validatePossibleWeblinks(xml));
2946
2995
  for (const child of Array.from(xml.children)) {
2947
2996
  errors.push(
2948
2997
  ...validateElement(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pro-editor-schema",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Pro Editor XML schemas",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -26,11 +26,15 @@
26
26
  },
27
27
  "devDependencies": {
28
28
  "@eslint/js": "^10.0.1",
29
+ "@types/mark.js": "^8.11.12",
29
30
  "eslint": "^10.6.0",
30
31
  "happy-dom": "^20.0.10",
31
32
  "tsup": "^8.0.0",
32
33
  "typescript": "^5.0.0",
33
34
  "typescript-eslint": "^8.62.1",
34
35
  "vitest": "^3.2.4"
36
+ },
37
+ "dependencies": {
38
+ "mark.js": "^8.11.1"
35
39
  }
36
40
  }