pro-editor-schema 1.1.1 → 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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +52 -34
- package/dist/index.mjs +42 -34
- package/package.json +5 -1
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,42 +2980,52 @@ var validateReferenceCited = (referenceElement, linkElements) => {
|
|
|
2970
2980
|
];
|
|
2971
2981
|
};
|
|
2972
2982
|
|
|
2973
|
-
// src/validation/
|
|
2974
|
-
var
|
|
2975
|
-
var
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
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;
|
|
2983
3013
|
};
|
|
2984
|
-
var
|
|
2985
|
-
const
|
|
2986
|
-
|
|
2987
|
-
|
|
3014
|
+
var validatePossibleWeblinks = (root) => {
|
|
3015
|
+
const errors = [];
|
|
3016
|
+
const possibleWebLinks = collectPossibleWebLinks(root);
|
|
3017
|
+
for (const possibleWebLink of possibleWebLinks) {
|
|
3018
|
+
errors.push(
|
|
2988
3019
|
createValidationIssue({
|
|
2989
|
-
store:
|
|
2990
|
-
title: "
|
|
2991
|
-
kind: "
|
|
2992
|
-
description: "
|
|
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?",
|
|
2993
3024
|
level: "warning"
|
|
2994
3025
|
})
|
|
2995
|
-
|
|
2996
|
-
}
|
|
2997
|
-
if (isValidUri(url)) {
|
|
2998
|
-
return [];
|
|
3026
|
+
);
|
|
2999
3027
|
}
|
|
3000
|
-
return
|
|
3001
|
-
createValidationIssue({
|
|
3002
|
-
store: getStore(uriElement),
|
|
3003
|
-
title: "URL cannot be reached",
|
|
3004
|
-
kind: "unlinked",
|
|
3005
|
-
description: "URL cannot be reached. Please check and adjust.",
|
|
3006
|
-
level: "warning"
|
|
3007
|
-
})
|
|
3008
|
-
];
|
|
3028
|
+
return errors;
|
|
3009
3029
|
};
|
|
3010
3030
|
|
|
3011
3031
|
// src/validation/validateXml.ts
|
|
@@ -3028,9 +3048,6 @@ var validateElement = (element, root, elementsToLink, linkElements, schemasToVal
|
|
|
3028
3048
|
if (schema.tag === FOOTNOTE_SCHEMA.tag) {
|
|
3029
3049
|
errors.push(...validateFootnoteCue(element, linkElements));
|
|
3030
3050
|
}
|
|
3031
|
-
if (schema.tag === URI_SCHEMA.tag) {
|
|
3032
|
-
errors.push(...validateUri(element));
|
|
3033
|
-
}
|
|
3034
3051
|
if (isIgnoredValidation(schema.code)) {
|
|
3035
3052
|
return errors;
|
|
3036
3053
|
}
|
|
@@ -3052,6 +3069,7 @@ var validateXml = (xml, elementsToLink, linkElements, schemasToValidateAgainst)
|
|
|
3052
3069
|
const errors = [];
|
|
3053
3070
|
errors.push(...validateConsecutiveFootnotes(xml));
|
|
3054
3071
|
errors.push(...validateConsecutiveFootnoteCues(xml));
|
|
3072
|
+
errors.push(...validatePossibleWeblinks(xml));
|
|
3055
3073
|
for (const child of Array.from(xml.children)) {
|
|
3056
3074
|
errors.push(
|
|
3057
3075
|
...validateElement(
|
package/dist/index.mjs
CHANGED
|
@@ -2902,42 +2902,52 @@ var validateReferenceCited = (referenceElement, linkElements) => {
|
|
|
2902
2902
|
];
|
|
2903
2903
|
};
|
|
2904
2904
|
|
|
2905
|
-
// src/validation/
|
|
2906
|
-
|
|
2907
|
-
var
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
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;
|
|
2915
2935
|
};
|
|
2916
|
-
var
|
|
2917
|
-
const
|
|
2918
|
-
|
|
2919
|
-
|
|
2936
|
+
var validatePossibleWeblinks = (root) => {
|
|
2937
|
+
const errors = [];
|
|
2938
|
+
const possibleWebLinks = collectPossibleWebLinks(root);
|
|
2939
|
+
for (const possibleWebLink of possibleWebLinks) {
|
|
2940
|
+
errors.push(
|
|
2920
2941
|
createValidationIssue({
|
|
2921
|
-
store:
|
|
2922
|
-
title: "
|
|
2923
|
-
kind: "
|
|
2924
|
-
description: "
|
|
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?",
|
|
2925
2946
|
level: "warning"
|
|
2926
2947
|
})
|
|
2927
|
-
|
|
2928
|
-
}
|
|
2929
|
-
if (isValidUri(url)) {
|
|
2930
|
-
return [];
|
|
2948
|
+
);
|
|
2931
2949
|
}
|
|
2932
|
-
return
|
|
2933
|
-
createValidationIssue({
|
|
2934
|
-
store: getStore(uriElement),
|
|
2935
|
-
title: "URL cannot be reached",
|
|
2936
|
-
kind: "unlinked",
|
|
2937
|
-
description: "URL cannot be reached. Please check and adjust.",
|
|
2938
|
-
level: "warning"
|
|
2939
|
-
})
|
|
2940
|
-
];
|
|
2950
|
+
return errors;
|
|
2941
2951
|
};
|
|
2942
2952
|
|
|
2943
2953
|
// src/validation/validateXml.ts
|
|
@@ -2960,9 +2970,6 @@ var validateElement = (element, root, elementsToLink, linkElements, schemasToVal
|
|
|
2960
2970
|
if (schema.tag === FOOTNOTE_SCHEMA.tag) {
|
|
2961
2971
|
errors.push(...validateFootnoteCue(element, linkElements));
|
|
2962
2972
|
}
|
|
2963
|
-
if (schema.tag === URI_SCHEMA.tag) {
|
|
2964
|
-
errors.push(...validateUri(element));
|
|
2965
|
-
}
|
|
2966
2973
|
if (isIgnoredValidation(schema.code)) {
|
|
2967
2974
|
return errors;
|
|
2968
2975
|
}
|
|
@@ -2984,6 +2991,7 @@ var validateXml = (xml, elementsToLink, linkElements, schemasToValidateAgainst)
|
|
|
2984
2991
|
const errors = [];
|
|
2985
2992
|
errors.push(...validateConsecutiveFootnotes(xml));
|
|
2986
2993
|
errors.push(...validateConsecutiveFootnoteCues(xml));
|
|
2994
|
+
errors.push(...validatePossibleWeblinks(xml));
|
|
2987
2995
|
for (const child of Array.from(xml.children)) {
|
|
2988
2996
|
errors.push(
|
|
2989
2997
|
...validateElement(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pro-editor-schema",
|
|
3
|
-
"version": "1.1.
|
|
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
|
}
|