wikiparser-node 1.40.0 → 1.42.0

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.
Files changed (66) hide show
  1. package/README.md +55 -7
  2. package/bundle/bundle-es8.min.js +27 -27
  3. package/bundle/bundle-lsp.min.js +29 -29
  4. package/bundle/bundle.min.js +19 -19
  5. package/config/.schema.json +5 -0
  6. package/config/default.json +1 -1
  7. package/config/enwiki.json +3 -2
  8. package/config/jawiki.json +6 -5
  9. package/config/llwiki.json +2 -1
  10. package/config/minimum.json +1 -1
  11. package/config/moegirl.json +2 -1
  12. package/config/zhwiki.json +3 -2
  13. package/dist/addon/attribute.js +1 -1
  14. package/dist/addon/transclude.js +1 -3
  15. package/dist/base.d.mts +5 -3
  16. package/dist/base.d.ts +5 -3
  17. package/dist/bin/config.js +11 -10
  18. package/dist/index.js +1 -2
  19. package/dist/lib/element.d.ts +3 -8
  20. package/dist/lib/element.js +2 -26
  21. package/dist/lib/lintConfig.js +30 -23
  22. package/dist/lib/lsp.d.ts +2 -0
  23. package/dist/lib/lsp.js +8 -20
  24. package/dist/lib/node.d.ts +2 -0
  25. package/dist/lib/node.js +0 -7
  26. package/dist/lib/range.d.ts +0 -7
  27. package/dist/lib/range.js +5 -14
  28. package/dist/lib/text.js +4 -6
  29. package/dist/map.d.ts +66 -0
  30. package/dist/map.js +2 -0
  31. package/dist/mixin/attributesParent.d.ts +4 -3
  32. package/dist/mixin/elementLike.d.ts +13 -0
  33. package/dist/mixin/elementLike.js +66 -53
  34. package/dist/parser/selector.js +3 -3
  35. package/dist/render/extension.js +139 -8
  36. package/dist/render/html.js +72 -3
  37. package/dist/render/magicWords.js +6 -3
  38. package/dist/src/attribute.d.ts +2 -2
  39. package/dist/src/attribute.js +18 -14
  40. package/dist/src/attributes.d.ts +3 -3
  41. package/dist/src/attributes.js +35 -19
  42. package/dist/src/extLink.js +5 -4
  43. package/dist/src/heading.js +11 -3
  44. package/dist/src/index.js +3 -4
  45. package/dist/src/link/base.js +2 -4
  46. package/dist/src/link/file.js +5 -5
  47. package/dist/src/link/galleryImage.js +1 -3
  48. package/dist/src/magicLink.js +6 -5
  49. package/dist/src/multiLine/gallery.js +2 -3
  50. package/dist/src/nowiki/doubleUnderscore.d.ts +1 -0
  51. package/dist/src/nowiki/doubleUnderscore.js +4 -1
  52. package/dist/src/nowiki/quote.js +1 -3
  53. package/dist/src/parameter.js +5 -2
  54. package/dist/src/table/td.d.ts +2 -2
  55. package/dist/src/table/td.js +1 -1
  56. package/dist/src/tag/html.js +29 -12
  57. package/dist/src/tagPair/ext.js +4 -1
  58. package/dist/src/tagPair/translate.d.ts +1 -1
  59. package/dist/src/tagPair/translate.js +1 -1
  60. package/dist/util/debug.js +5 -7
  61. package/dist/util/html.js +3 -11
  62. package/dist/util/sharable.js +2 -0
  63. package/dist/util/sharable.mjs +3 -1
  64. package/extensions/dist/base.js +1 -1
  65. package/extensions/dist/env.js +34 -0
  66. package/package.json +19 -20
@@ -88,12 +88,15 @@ let HtmlToken = (() => {
88
88
  let _classThis;
89
89
  let _classSuper = index_2.TagToken;
90
90
  let _instanceExtraInitializers = [];
91
+ let _getTocLine_decorators;
91
92
  let _toHtmlInternal_decorators;
92
93
  var HtmlToken = class extends _classSuper {
93
94
  static { _classThis = this; }
94
95
  static {
95
96
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
97
+ _getTocLine_decorators = [(0, cached_1.cached)()];
96
98
  _toHtmlInternal_decorators = [(0, cached_1.cached)()];
99
+ __esDecorate(this, null, _getTocLine_decorators, { kind: "method", name: "getTocLine", static: false, private: false, access: { has: obj => "getTocLine" in obj, get: obj => obj.getTocLine }, metadata: _metadata }, null, _instanceExtraInitializers);
97
100
  __esDecorate(this, null, _toHtmlInternal_decorators, { kind: "method", name: "toHtmlInternal", static: false, private: false, access: { has: obj => "toHtmlInternal" in obj, get: obj => obj.toHtmlInternal }, metadata: _metadata }, null, _instanceExtraInitializers);
98
101
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
99
102
  HtmlToken = _classThis = _classDescriptor.value;
@@ -319,25 +322,39 @@ let HtmlToken = (() => {
319
322
  }
320
323
  }
321
324
  /** @private */
325
+ getTocLine() {
326
+ if (this.closing || !/^h\d$/u.test(this.name)) {
327
+ return undefined;
328
+ }
329
+ const matched = this.findMatchingTag();
330
+ if (!matched) {
331
+ return undefined;
332
+ }
333
+ const range = this.createRange();
334
+ range.setStartAfter(this);
335
+ range.setEndBefore(matched);
336
+ const content = (0, html_1.html)(range.cloneContents(), '', { nocc: true });
337
+ return [(0, html_1.getId)(content), content];
338
+ }
339
+ /** @private */
322
340
  toHtmlInternal() {
323
- const { closing, name } = this, [, selfClosingTags, voidTags] = this.getAttribute('config').html, tag = name + (closing ? '' : super.toHtmlInternal());
341
+ const { closing, name, selfClosing } = this, [, selfClosingTags, voidTags] = this.getAttribute('config').html, tag = name + (closing ? '' : super.toHtmlInternal());
324
342
  if (voidTags.includes(name)) {
325
343
  return closing && name !== 'br' ? '' : `<${tag}>`;
326
344
  }
327
- const result = `<${closing ? '/' : ''}${tag}>${this.#selfClosing && !closing && selfClosingTags.includes(name) ? `</${name}>` : ''}`;
328
- if (/^h\d$/u.test(name) && (this.closing || !this.id)) {
329
- const matched = this.findMatchingTag();
330
- if (matched) {
331
- if (closing) {
332
- return result + (matched.id ? '' : '</div>');
345
+ const result = `<${closing ? '/' : ''}${tag}>${selfClosing && !closing && selfClosingTags.includes(name) ? `</${name}>` : ''}`;
346
+ if (/^h\d$/u.test(name)) {
347
+ if (closing) {
348
+ return result + (this.findMatchingTag()?.id === '' ? '</div>' : '');
349
+ }
350
+ else if (!this.id) {
351
+ const id = this.getTocLine()?.[0];
352
+ if (id !== undefined) {
353
+ return `<div class="mw-heading mw-heading${name.slice(-1)}">${result.slice(0, -1)} id="${id}">`;
333
354
  }
334
- const range = this.createRange();
335
- range.setStartAfter(this);
336
- range.setEndBefore(matched);
337
- return `<div class="mw-heading mw-heading${name.slice(-1)}">${result.slice(0, -1)} id="${(0, html_1.getId)(range.cloneContents())}">`;
338
355
  }
339
356
  }
340
- return result;
357
+ return (this.tocData ?? '') + result;
341
358
  }
342
359
  /** @private */
343
360
  getRange() {
@@ -103,6 +103,7 @@ let ExtToken = (() => {
103
103
  innerToken = new PreToken(inner, newConfig, accum);
104
104
  break;
105
105
  }
106
+ newConfig.excludes.push('list');
106
107
  // fall through
107
108
  case 'indicator':
108
109
  case 'poem':
@@ -125,7 +126,9 @@ let ExtToken = (() => {
125
126
  case 'tab':
126
127
  newConfig.ext = newConfig.ext.filter(e => e !== 'tabs');
127
128
  break;
128
- // No default
129
+ case 'ref':
130
+ newConfig.ext = newConfig.ext.filter(e => e !== 'references');
131
+ // no default
129
132
  }
130
133
  innerToken = new index_2.Token(inner, newConfig, accum);
131
134
  break;
@@ -26,7 +26,7 @@ export declare abstract class TranslateToken extends TagPairToken implements Omi
26
26
  */
27
27
  constructor(attr?: string, inner?: string, config?: Config, accum?: Token[]);
28
28
  /** @implements */
29
- getAttr(key: string): true | undefined;
29
+ getAttr(key: string): '' | undefined;
30
30
  /** @implements */
31
31
  hasAttr(key: string): boolean;
32
32
  /** @implements */
@@ -125,7 +125,7 @@ let TranslateToken = (() => {
125
125
  }
126
126
  /** @implements */
127
127
  getAttr(key) {
128
- return (0, string_1.trimLc)(key) === 'nowrap' && this.#isNowrap() || undefined;
128
+ return (0, string_1.trimLc)(key) === 'nowrap' && this.#isNowrap() ? '' : undefined;
129
129
  }
130
130
  /** @implements */
131
131
  hasAttr(key) {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCanonicalName = exports.undo = exports.mixin = exports.emptyArray = exports.getMagicWordInfo = exports.setChildNodes = exports.isLink = exports.isRowEnd = exports.isToken = exports.Shadow = void 0;
3
+ exports.getCanonicalName = exports.undo = exports.mixin = exports.emptyArray = exports.getMagicWordInfo = exports.setChildNodes = exports.isLink = exports.isRowEnd = exports.Shadow = void 0;
4
+ exports.isToken = isToken;
4
5
  exports.Shadow = {
5
6
  running: false,
6
7
  /** @private */
@@ -50,12 +51,9 @@ exports.Shadow = {
50
51
  },
51
52
  rev: 0,
52
53
  };
53
- /**
54
- * 是否是某一特定类型的节点
55
- * @param type 节点类型
56
- */
57
- const isToken = (type) => (node) => node.type === type;
58
- exports.isToken = isToken;
54
+ function isToken(type) {
55
+ return (node) => node.type === type;
56
+ }
59
57
  /**
60
58
  * 是否是行尾
61
59
  * @param token 节点
package/dist/util/html.js CHANGED
@@ -95,9 +95,9 @@ const html = (childNodes, separator, opt = {}) => {
95
95
  if ((child.length > 0 || /\s$/u.test(innerText))
96
96
  && previousSibling.is('list')
97
97
  && !/[;#*]/u.test(innerText)
98
- && child.closest('ext-inner#poem,list-range')?.type === 'ext-inner') {
98
+ && child.closest('ext#poem,list-range')?.type === 'ext') {
99
99
  lastPrefix = '';
100
- result = `<span style="display: inline-block; margin-inline-start: ${previousSibling.indent}em;">${result}</span>`;
100
+ result = `<span class="mw-poem-indented" style="display: inline-block; margin-inline-start: ${previousSibling.indent}em;">${result}</span>`;
101
101
  }
102
102
  else {
103
103
  result = result.trim();
@@ -145,15 +145,7 @@ exports.html = html;
145
145
  * @param tokens inner tokens of a section heading
146
146
  */
147
147
  const getId = (tokens) => {
148
- let content;
149
- if (typeof tokens === 'string') {
150
- content = tokens;
151
- }
152
- else {
153
- const opt = { nocc: true };
154
- content = Array.isArray(tokens) ? (0, exports.html)(tokens, '', opt) : tokens.toHtmlInternal(opt);
155
- }
156
- const id = (0, string_1.decodeHtml)((0, string_1.sanitizeAlt)(content.replaceAll('_', ' ')))
148
+ const content = typeof tokens === 'string' ? tokens : tokens.toHtmlInternal({ nocc: true }), id = (0, string_1.decodeHtml)((0, string_1.sanitizeAlt)(content.replaceAll('_', ' ')))
157
149
  .replace(/[\s_]+/gu, '_');
158
150
  return id.endsWith('_') ? id.slice(0, -1) : id;
159
151
  };
@@ -88,6 +88,8 @@ exports.htmlAttrs = (() => ({
88
88
  categorytree: blockAttrs,
89
89
  combooption: blockAttrs,
90
90
  img: new Set(['alt', 'src', 'width', 'height', 'loading', 'srcset']),
91
+ /* NOT FOR BROWSER ONLY */
92
+ a: new Set(['href', 'rel', 'rev']),
91
93
  }))();
92
94
  exports.extAttrs = (() => ({
93
95
  pre: new Set(['format']),
@@ -85,7 +85,9 @@ const htmlAttrs = /* @__PURE__ */ (() => ({
85
85
  poem: blockAttrs,
86
86
  categorytree: blockAttrs,
87
87
  combooption: blockAttrs,
88
- img: /* @__PURE__ */ new Set(["alt", "src", "width", "height", "loading", "srcset"])
88
+ img: /* @__PURE__ */ new Set(["alt", "src", "width", "height", "loading", "srcset"]),
89
+ /* NOT FOR BROWSER ONLY */
90
+ a: /* @__PURE__ */ new Set(["href", "rel", "rev"])
89
91
  }))();
90
92
  const extAttrs = /* @__PURE__ */ (() => ({
91
93
  pre: /* @__PURE__ */ new Set(["format"]),
@@ -1,6 +1,6 @@
1
1
  (() => {
2
2
  var _a;
3
- const version = '1.40.0', src = (_a = document.currentScript) === null || _a === void 0 ? void 0 : _a.src, file = /\/extensions\/dist\/base\.(?:min\.)?js$/u, CDN = src && file.test(src)
3
+ const version = '1.42.0', src = (_a = document.currentScript) === null || _a === void 0 ? void 0 : _a.src, file = /\/extensions\/dist\/base\.(?:min\.)?js$/u, CDN = src && file.test(src)
4
4
  ? src.replace(file, '')
5
5
  : `https://fastly.jsdelivr.net/npm/wikiparser-node@${version}`;
6
6
  const workerJS = () => {
@@ -0,0 +1,34 @@
1
+ (() => {
2
+ const execute = (obj) => {
3
+ Object.entries(obj.files).find(([k]) => k.endsWith('.data.js'))[1]();
4
+ };
5
+ Object.assign(globalThis, {
6
+ mw: {
7
+ loader: {
8
+ done: false,
9
+ impl(callback) {
10
+ execute(callback()[1]);
11
+ },
12
+ implement(name, callback) {
13
+ if (typeof callback === 'object') {
14
+ execute(callback);
15
+ }
16
+ else if (!this.done) {
17
+ callback();
18
+ }
19
+ if (name.startsWith('ext.CodeMirror.data')) {
20
+ this.done = true;
21
+ }
22
+ },
23
+ state() {
24
+ },
25
+ },
26
+ config: {
27
+ values: {},
28
+ set({ extCodeMirrorConfig }) {
29
+ this.values.extCodeMirrorConfig = extCodeMirrorConfig;
30
+ },
31
+ },
32
+ },
33
+ });
34
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikiparser-node",
3
- "version": "1.40.0",
3
+ "version": "1.42.0",
4
4
  "description": "A Node.js parser for MediaWiki markup with AST",
5
5
  "keywords": [
6
6
  "mediawiki",
@@ -8,7 +8,7 @@
8
8
  "parser",
9
9
  "browser"
10
10
  ],
11
- "homepage": "https://github.com/bhsd-harry/wikiparser-node/wiki",
11
+ "homepage": "https://github.com/bhsd-harry/wikiparser-node#readme",
12
12
  "bugs": {
13
13
  "url": "https://github.com/bhsd-harry/wikiparser-node/issues"
14
14
  },
@@ -24,7 +24,7 @@
24
24
  "/errors/README",
25
25
  "/config/",
26
26
  "!/config/mediawikiwiki.json",
27
- "!/config/testwiki.json",
27
+ "!/config/github.json",
28
28
  "/data/",
29
29
  "/i18n/",
30
30
  "/coverage/badge.svg",
@@ -82,10 +82,10 @@
82
82
  ]
83
83
  },
84
84
  "dependencies": {
85
- "@bhsd/cm-util": "^1.1.0",
85
+ "@bhsd/cm-util": "^2.0.1",
86
86
  "@bhsd/common": "^2.2.1",
87
- "@bhsd/nodejs": "^1.0.0",
88
- "@bhsd/stylelint-util": "^1.0.2",
87
+ "@bhsd/nodejs": "^1.0.1",
88
+ "@bhsd/stylelint-util": "^1.0.3",
89
89
  "binary-search": "^1.3.6",
90
90
  "vscode-languageserver-types": "^3.17.5"
91
91
  },
@@ -93,37 +93,36 @@
93
93
  "color-name": "~2.0.2",
94
94
  "entities": "^8.0.0",
95
95
  "mathoid-texvcjs": "^0.6.0",
96
- "prism-wiki": "^2.1.0",
96
+ "prism-wiki": "^2.1.1",
97
97
  "prismjs": "^1.30.0",
98
- "stylelint": "^17.11.0",
98
+ "stylelint": "^17.12.0",
99
99
  "vscode-css-languageservice": "^6.3.10",
100
100
  "vscode-html-languageservice": "^5.6.2",
101
101
  "vscode-json-languageservice": "^5.7.2"
102
102
  },
103
103
  "devDependencies": {
104
- "@bhsd/code-standard": "^2.4.2",
105
- "@bhsd/test-util": "^1.2.0",
106
- "@codemirror/lint": "^6.9.5",
107
- "@eslint/markdown": "^8.0.1",
104
+ "@bhsd/code-standard": "^2.5.1",
105
+ "@bhsd/test-util": "^1.3.1",
106
+ "@codemirror/lint": "^6.9.6",
107
+ "@eslint/markdown": "^8.0.2",
108
108
  "@types/color-name": "^2.0.0",
109
109
  "@types/color-rgba": "^2.1.3",
110
110
  "@types/mocha": "^10.0.10",
111
- "@types/node": "^24.11.0",
111
+ "@types/node": "^25.9.0",
112
112
  "@types/prismjs": "^1.26.6",
113
- "@typescript-eslint/eslint-plugin": "^8.59.2",
114
- "@typescript-eslint/parser": "^8.59.2",
113
+ "@typescript-eslint/parser": "^8.59.4",
115
114
  "c8": "^11.0.0",
116
- "codejar-async": "^4.3.0",
115
+ "codejar-async": "^4.3.1",
117
116
  "color-rgba": "^3.0.0",
118
117
  "diff2html-cli": "^5.2.15",
119
118
  "esbuild": "^0.28.0",
120
- "eslint": "^10.3.0",
119
+ "eslint": "^10.4.1",
121
120
  "markdownlint-cli2": "^0.22.1",
122
- "mocha": "^11.7.5",
121
+ "mocha": "^11.7.6",
123
122
  "monaco-editor": "~0.53.0",
124
- "tsx": "^4.21.0",
123
+ "tsx": "^4.22.3",
125
124
  "typescript": "^6.0.3",
126
- "v8r": "^6.0.0",
125
+ "v8r": "^6.1.0",
127
126
  "vscode-languageserver-textdocument": "^1.0.12"
128
127
  },
129
128
  "engines": {