pro-editor-schema 1.1.2 → 1.1.4

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/README.md CHANGED
@@ -18,18 +18,73 @@ npm install
18
18
 
19
19
  ## Scripts
20
20
 
21
- | Command | Description |
22
- | --- | --- |
23
- | `npm run dev` | Build in watch mode |
24
- | `npm run build` | Build CJS, ESM, and type declarations |
25
- | `npm run typecheck` | Run TypeScript without emitting files |
26
- | `npm run lint` | Run ESLint on `src/` |
27
- | `npm run test` | Run tests once with Vitest |
28
- | `npm run test:watch` | Run tests in watch mode |
29
- | `npm run check` | Run the full verification pipeline (`npm ci`, `typecheck`, `lint`, `test`, `build`) |
21
+ | Command | Description |
22
+ | -------------------- | ----------------------------------------------------------------------------------- |
23
+ | `npm run dev` | Build in watch mode |
24
+ | `npm run build` | Build CJS, ESM, and type declarations |
25
+ | `npm run typecheck` | Run TypeScript without emitting files |
26
+ | `npm run lint` | Run ESLint on `src/` |
27
+ | `npm run test` | Run tests once with Vitest |
28
+ | `npm run test:watch` | Run tests in watch mode |
29
+ | `npm run check` | Run the full verification pipeline (`npm ci`, `typecheck`, `lint`, `test`, `build`) |
30
30
 
31
31
  For local development, `npm run check` is the fastest way to verify everything before pushing.
32
32
 
33
+ ## Publishing
34
+
35
+ The package is published to npm as `pro-editor-schema`. Use the `staging` tag for pre-release installs, and the default `latest` tag for production.
36
+
37
+ ### Prerequisites
38
+
39
+ 1. You must have publish access to the `pro-editor-schema` package on npm.
40
+ 2. Log in if needed:
41
+
42
+ ```bash
43
+ npm login
44
+ ```
45
+
46
+ 3. Bump the version in `package.json` (and commit it). npm rejects republishing an existing version.
47
+ 4. Verify the package:
48
+
49
+ ```bash
50
+ npm run check
51
+ ```
52
+
53
+ ### Publish to staging
54
+
55
+ ```bash
56
+ npm publish --tag staging --access public
57
+ ```
58
+
59
+ Install the staging build in a consumer app with:
60
+
61
+ ```bash
62
+ npm install pro-editor-schema@staging
63
+ ```
64
+
65
+ ### Publish to production
66
+
67
+ Production uses npm’s default `latest` tag:
68
+
69
+ ```bash
70
+ npm publish --access public
71
+ ```
72
+
73
+ Install the production build with:
74
+
75
+ ```bash
76
+ npm install pro-editor-schema
77
+ # or explicitly:
78
+ npm install pro-editor-schema@latest
79
+ ```
80
+
81
+ ### Notes
82
+
83
+ - Always run `npm run check` before publishing so typecheck, lint, tests, and build succeed.
84
+ - Each publish needs a new `version` in `package.json`.
85
+ - Staging and production can point at different versions at the same time (for example `1.1.3` on `staging` and `1.1.2` on `latest`).
86
+ - GitHub Actions also publishes to `latest` when you push a `v*` git tag (see `.github/workflows/publish.yml`).
87
+
33
88
  ## CI
34
89
 
35
90
  GitHub Actions runs on push and pull requests to `main` / `master`:
@@ -125,12 +180,10 @@ const para = createElement({
125
180
  ```ts
126
181
  import { validateXml } from "pro-editor-schema";
127
182
 
128
- const errors = validateXml(
129
- rootElement,
130
- elementsToLink,
131
- linkElements,
132
- ["para", "heading"],
133
- );
183
+ const errors = validateXml(rootElement, elementsToLink, linkElements, [
184
+ "para",
185
+ "heading",
186
+ ]);
134
187
  ```
135
188
 
136
189
  `validateXml` parameters:
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?):\\/\\/|www\\.)(?:[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?):\\/\\/|www\\.)(?:[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.4",
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
  }