wikiparser-node 1.4.3-b → 1.4.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.
Files changed (166) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/config/.schema.json +172 -0
  4. package/config/enwiki.json +814 -1
  5. package/config/llwiki.json +35 -1
  6. package/config/moegirl.json +44 -1
  7. package/config/zhwiki.json +466 -1
  8. package/dist/addon/table.d.ts +6 -0
  9. package/dist/addon/table.js +564 -0
  10. package/dist/base.d.ts +58 -0
  11. package/dist/index.d.ts +30 -0
  12. package/dist/index.js +211 -0
  13. package/dist/internal.d.ts +44 -0
  14. package/dist/lib/element.d.ts +155 -0
  15. package/dist/lib/element.js +655 -0
  16. package/dist/lib/node.d.ts +146 -0
  17. package/dist/lib/node.js +428 -0
  18. package/dist/lib/range.d.ts +104 -0
  19. package/dist/lib/range.js +385 -0
  20. package/dist/lib/ranges.d.ts +26 -0
  21. package/dist/lib/ranges.js +118 -0
  22. package/dist/lib/text.d.ts +62 -0
  23. package/dist/lib/text.js +306 -0
  24. package/dist/lib/title.d.ts +38 -0
  25. package/dist/lib/title.js +164 -0
  26. package/dist/mixin/attributesParent.d.ts +50 -0
  27. package/dist/mixin/attributesParent.js +78 -0
  28. package/dist/mixin/fixed.d.ts +6 -0
  29. package/dist/mixin/fixed.js +30 -0
  30. package/dist/mixin/flagsParent.d.ts +72 -0
  31. package/dist/mixin/flagsParent.js +59 -0
  32. package/dist/mixin/hidden.d.ts +5 -0
  33. package/dist/mixin/hidden.js +24 -0
  34. package/dist/mixin/magicLinkParent.d.ts +40 -0
  35. package/dist/mixin/magicLinkParent.js +42 -0
  36. package/dist/mixin/singleLine.d.ts +6 -0
  37. package/dist/mixin/singleLine.js +26 -0
  38. package/dist/mixin/sol.d.ts +6 -0
  39. package/dist/mixin/sol.js +43 -0
  40. package/dist/mixin/syntax.d.ts +9 -0
  41. package/dist/mixin/syntax.js +50 -0
  42. package/dist/parser/braces.js +131 -0
  43. package/dist/parser/commentAndExt.js +90 -0
  44. package/dist/parser/converter.js +41 -0
  45. package/dist/parser/externalLinks.js +32 -0
  46. package/dist/parser/hrAndDoubleUnderscore.js +41 -0
  47. package/dist/parser/html.js +39 -0
  48. package/dist/parser/links.js +95 -0
  49. package/dist/parser/list.js +68 -0
  50. package/dist/parser/magicLinks.js +43 -0
  51. package/dist/parser/quotes.js +68 -0
  52. package/dist/parser/selector.js +162 -0
  53. package/dist/parser/table.js +124 -0
  54. package/dist/src/arg.d.ts +58 -0
  55. package/dist/src/arg.js +196 -0
  56. package/dist/src/atom.d.ts +12 -0
  57. package/dist/src/atom.js +27 -0
  58. package/dist/src/attribute.d.ts +69 -0
  59. package/dist/src/attribute.js +475 -0
  60. package/dist/src/attributes.d.ts +109 -0
  61. package/dist/src/attributes.js +346 -0
  62. package/dist/src/converter.d.ts +33 -0
  63. package/dist/src/converter.js +134 -0
  64. package/dist/src/converterFlags.d.ts +87 -0
  65. package/dist/src/converterFlags.js +226 -0
  66. package/dist/src/converterRule.d.ts +77 -0
  67. package/dist/src/converterRule.js +209 -0
  68. package/dist/src/extLink.d.ts +43 -0
  69. package/dist/src/extLink.js +186 -0
  70. package/dist/src/gallery.d.ts +54 -0
  71. package/dist/src/gallery.js +126 -0
  72. package/dist/src/heading.d.ts +47 -0
  73. package/dist/src/heading.js +190 -0
  74. package/dist/src/hidden.d.ts +7 -0
  75. package/dist/src/hidden.js +23 -0
  76. package/dist/src/html.d.ts +65 -0
  77. package/dist/src/html.js +337 -0
  78. package/dist/src/imageParameter.d.ts +65 -0
  79. package/dist/src/imageParameter.js +246 -0
  80. package/dist/src/imagemap.d.ts +56 -0
  81. package/dist/src/imagemap.js +150 -0
  82. package/dist/src/imagemapLink.d.ts +31 -0
  83. package/dist/src/imagemapLink.js +93 -0
  84. package/dist/src/index.d.ts +143 -0
  85. package/dist/src/index.js +803 -0
  86. package/dist/src/link/base.d.ts +52 -0
  87. package/dist/src/link/base.js +209 -0
  88. package/dist/src/link/category.d.ts +13 -0
  89. package/dist/src/link/category.js +28 -0
  90. package/dist/src/link/file.d.ts +96 -0
  91. package/dist/src/link/file.js +265 -0
  92. package/dist/src/link/galleryImage.d.ts +32 -0
  93. package/dist/src/link/galleryImage.js +157 -0
  94. package/dist/src/link/index.d.ts +56 -0
  95. package/dist/src/link/index.js +133 -0
  96. package/dist/src/magicLink.d.ts +59 -0
  97. package/dist/src/magicLink.js +199 -0
  98. package/dist/src/nested.d.ts +43 -0
  99. package/dist/src/nested.js +92 -0
  100. package/dist/src/nowiki/base.d.ts +31 -0
  101. package/dist/src/nowiki/base.js +93 -0
  102. package/dist/src/nowiki/comment.d.ts +25 -0
  103. package/dist/src/nowiki/comment.js +68 -0
  104. package/dist/src/nowiki/dd.d.ts +8 -0
  105. package/dist/src/nowiki/dd.js +24 -0
  106. package/dist/src/nowiki/doubleUnderscore.d.ts +18 -0
  107. package/dist/src/nowiki/doubleUnderscore.js +101 -0
  108. package/dist/src/nowiki/hr.d.ts +5 -0
  109. package/dist/src/nowiki/hr.js +63 -0
  110. package/dist/src/nowiki/index.d.ts +16 -0
  111. package/dist/src/nowiki/index.js +21 -0
  112. package/dist/src/nowiki/list.d.ts +16 -0
  113. package/dist/src/nowiki/list.js +97 -0
  114. package/dist/src/nowiki/listBase.d.ts +5 -0
  115. package/dist/src/nowiki/listBase.js +61 -0
  116. package/dist/src/nowiki/noinclude.d.ts +10 -0
  117. package/dist/src/nowiki/noinclude.js +23 -0
  118. package/dist/src/nowiki/quote.d.ts +14 -0
  119. package/dist/src/nowiki/quote.js +116 -0
  120. package/dist/src/onlyinclude.d.ts +16 -0
  121. package/dist/src/onlyinclude.js +57 -0
  122. package/dist/src/paramTag/index.d.ts +37 -0
  123. package/dist/src/paramTag/index.js +69 -0
  124. package/dist/src/paramTag/inputbox.d.ts +8 -0
  125. package/dist/src/paramTag/inputbox.js +22 -0
  126. package/dist/src/parameter.d.ts +70 -0
  127. package/dist/src/parameter.js +262 -0
  128. package/dist/src/pre.d.ts +28 -0
  129. package/dist/src/pre.js +55 -0
  130. package/dist/src/syntax.d.ts +20 -0
  131. package/dist/src/syntax.js +86 -0
  132. package/dist/src/table/base.d.ts +30 -0
  133. package/dist/src/table/base.js +132 -0
  134. package/dist/src/table/index.d.ts +233 -0
  135. package/dist/src/table/index.js +396 -0
  136. package/dist/src/table/td.d.ts +92 -0
  137. package/dist/src/table/td.js +337 -0
  138. package/dist/src/table/tr.d.ts +32 -0
  139. package/dist/src/table/tr.js +58 -0
  140. package/dist/src/table/trBase.d.ts +53 -0
  141. package/dist/src/table/trBase.js +154 -0
  142. package/dist/src/tagPair/ext.d.ts +32 -0
  143. package/dist/src/tagPair/ext.js +203 -0
  144. package/dist/src/tagPair/include.d.ts +35 -0
  145. package/dist/src/tagPair/include.js +63 -0
  146. package/dist/src/tagPair/index.d.ts +27 -0
  147. package/dist/src/tagPair/index.js +128 -0
  148. package/dist/src/transclude.d.ts +167 -0
  149. package/dist/src/transclude.js +710 -0
  150. package/dist/util/constants.js +113 -0
  151. package/dist/util/debug.js +88 -0
  152. package/dist/util/diff.js +82 -0
  153. package/dist/util/lint.js +30 -0
  154. package/dist/util/string.js +53 -0
  155. package/errors/README +1 -0
  156. package/i18n/zh-hans.json +1 -0
  157. package/i18n/zh-hant.json +1 -0
  158. package/package.json +15 -30
  159. package/printed/README +1 -0
  160. package/bundle/bundle.min.js +0 -36
  161. package/extensions/dist/base.js +0 -64
  162. package/extensions/dist/editor.js +0 -159
  163. package/extensions/dist/highlight.js +0 -59
  164. package/extensions/dist/lint.js +0 -48
  165. package/extensions/editor.css +0 -63
  166. package/extensions/ui.css +0 -141
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TrBaseToken = void 0;
4
+ const lint_1 = require("../../util/lint");
5
+ const debug_1 = require("../../util/debug");
6
+ const constants_1 = require("../../util/constants");
7
+ const __1 = require("..");
8
+ const base_1 = require("./base");
9
+ const td_1 = require("./td");
10
+ /** 表格行或表格 */
11
+ class TrBaseToken extends base_1.TableBaseToken {
12
+ /** @override */
13
+ lint(start = this.getAbsoluteIndex()) {
14
+ const errors = super.lint(start), inter = this.childNodes.find(({ type }) => type === 'table-inter');
15
+ if (!inter) {
16
+ return errors;
17
+ }
18
+ const first = inter.childNodes.find(child => child.text().trim()), tdPattern = /^\s*(?:!|\{\{\s*![!-]?\s*\}\})/u, isArg = (0, debug_1.isToken)('arg'), isTransclude = (0, debug_1.isToken)('magic-word');
19
+ if (!first
20
+ || tdPattern.test(String(first))
21
+ || isArg(first) && tdPattern.test(first.default || '')) {
22
+ return errors;
23
+ }
24
+ else if (isTransclude(first)) {
25
+ try {
26
+ if (first.getPossibleValues().every(token => tdPattern.test(token.text()))) {
27
+ return errors;
28
+ }
29
+ }
30
+ catch { }
31
+ }
32
+ const error = (0, lint_1.generateForChild)(inter, { start }, 'content to be moved out from the table');
33
+ errors.push({
34
+ ...error,
35
+ severity: first.type === 'template' ? 'warning' : 'error',
36
+ startIndex: error.startIndex + 1,
37
+ startLine: error.startLine + 1,
38
+ startCol: 0,
39
+ });
40
+ return errors;
41
+ }
42
+ /* NOT FOR BROWSER */
43
+ /** 修复简单的表格语法错误 */
44
+ #correct() {
45
+ const { childNodes: [, , child] } = this;
46
+ if (child?.constructor === __1.Token) {
47
+ const { firstChild } = child;
48
+ if (firstChild?.type !== 'text') {
49
+ child.prepend('\n');
50
+ }
51
+ else if (!firstChild.data.startsWith('\n')) {
52
+ firstChild.insertData(0, '\n');
53
+ }
54
+ }
55
+ }
56
+ /** @override */
57
+ text() {
58
+ this.#correct();
59
+ return super.text();
60
+ }
61
+ /** @private */
62
+ toString() {
63
+ this.#correct();
64
+ return super.toString();
65
+ }
66
+ /**
67
+ * @override
68
+ * @param i 移除位置
69
+ */
70
+ removeAt(i) {
71
+ i += i < 0 ? this.length : 0;
72
+ const child = this.childNodes[i];
73
+ if (child instanceof td_1.TdToken && child.isIndependent()) {
74
+ const { nextSibling } = child;
75
+ if (nextSibling?.type === 'td') {
76
+ nextSibling.independence();
77
+ }
78
+ }
79
+ return super.removeAt(i);
80
+ }
81
+ /**
82
+ * @override
83
+ * @param token 待插入的子节点
84
+ * @param i 插入位置
85
+ */
86
+ insertAt(token, i = this.length) {
87
+ if (!debug_1.Shadow.running && token.type !== 'td') {
88
+ if (this.type === 'tr') {
89
+ this.typeError('insertAt', 'TdToken');
90
+ }
91
+ else if (token.type !== 'tr') {
92
+ this.typeError('insertAt', 'TrToken', 'TdToken');
93
+ }
94
+ }
95
+ i += i < 0 ? this.length : 0;
96
+ const child = this.childNodes[i];
97
+ if (token instanceof td_1.TdToken && token.isIndependent() && child instanceof td_1.TdToken) {
98
+ child.independence();
99
+ }
100
+ return super.insertAt(token, i);
101
+ }
102
+ /** 获取行数 */
103
+ getRowCount() {
104
+ return Number(this.childNodes.some(child => child instanceof td_1.TdToken && child.isIndependent() && !child.firstChild.text().endsWith('+')));
105
+ }
106
+ /** 获取列数 */
107
+ getColCount() {
108
+ let count = 0, last = 0;
109
+ for (const child of this.childNodes) {
110
+ if (child instanceof td_1.TdToken) {
111
+ last = child.isIndependent() ? Number(child.subtype !== 'caption') : last;
112
+ count += last;
113
+ }
114
+ }
115
+ return count;
116
+ }
117
+ getNthCol(n, insert = false) {
118
+ const nCols = this.getColCount();
119
+ n += n < 0 ? nCols : 0;
120
+ if (n < 0 || n > nCols || n === nCols && !insert) {
121
+ throw new RangeError(`不存在第 ${n} 个单元格!`);
122
+ }
123
+ let last = 0;
124
+ const isTr = (0, debug_1.isToken)('tr'), isSyntax = (0, debug_1.isToken)('table-syntax');
125
+ for (const child of this.childNodes.slice(2)) {
126
+ if (child instanceof td_1.TdToken) {
127
+ if (child.isIndependent()) {
128
+ last = Number(child.subtype !== 'caption');
129
+ }
130
+ n -= last;
131
+ if (n < 0) {
132
+ return child;
133
+ }
134
+ }
135
+ else if (isTr(child) || isSyntax(child)) {
136
+ return child;
137
+ }
138
+ }
139
+ return undefined;
140
+ }
141
+ /**
142
+ * 插入新的单元格
143
+ * @param inner 单元格内部wikitext
144
+ * @param {TableCoords} coord 单元格坐标
145
+ * @param subtype 单元格类型
146
+ * @param attr 单元格属性
147
+ */
148
+ insertTableCell(inner, { column }, subtype = 'td', attr = {}) {
149
+ const token = (0, td_1.createTd)(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config'));
150
+ return this.insertBefore(token, this.getNthCol(column, true));
151
+ }
152
+ }
153
+ exports.TrBaseToken = TrBaseToken;
154
+ constants_1.classes['TrBaseToken'] = __filename;
@@ -0,0 +1,32 @@
1
+ import Parser from '../../index';
2
+ import { Token } from '../index';
3
+ import { TagPairToken } from './index';
4
+ import { AttributesToken } from '../attributes';
5
+ import type { LintError } from '../../base';
6
+ import type { AttributesParentBase } from '../../mixin/attributesParent';
7
+ export interface ExtToken extends AttributesParentBase {
8
+ }
9
+ /**
10
+ * 扩展标签
11
+ * @classdesc `{childNodes: [AttributesToken, Token]}`
12
+ */
13
+ export declare abstract class ExtToken extends TagPairToken {
14
+ readonly type = "ext";
15
+ closed: true;
16
+ readonly childNodes: readonly [AttributesToken, Token];
17
+ abstract get firstChild(): AttributesToken;
18
+ abstract get lastChild(): Token;
19
+ abstract get children(): [AttributesToken, Token];
20
+ abstract get firstElementChild(): AttributesToken;
21
+ /**
22
+ * @param name 标签名
23
+ * @param attr 标签属性
24
+ * @param inner 内部wikitext
25
+ * @param closed 是否封闭
26
+ */
27
+ constructor(name: string, attr?: string, inner?: string, closed?: string, config?: Parser.Config, accum?: Token[]);
28
+ /** @override */
29
+ lint(start?: number): LintError[];
30
+ /** @override */
31
+ cloneNode(): this;
32
+ }
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.ExtToken = void 0;
38
+ const lint_1 = require("../../util/lint");
39
+ const debug_1 = require("../../util/debug");
40
+ const constants_1 = require("../../util/constants");
41
+ const attributesParent_1 = require("../../mixin/attributesParent");
42
+ const index_1 = require("../../index");
43
+ const index_2 = require("../index");
44
+ const index_3 = require("./index");
45
+ const attributes_1 = require("../attributes");
46
+ /**
47
+ * 从数组中删除指定元素
48
+ * @param arr 数组
49
+ * @param ele 元素
50
+ */
51
+ const del = (arr, ele) => {
52
+ const set = new Set(arr);
53
+ set.delete(ele);
54
+ return [...set];
55
+ };
56
+ /* NOT FOR BROWSER END */
57
+ /**
58
+ * 扩展标签
59
+ * @classdesc `{childNodes: [AttributesToken, Token]}`
60
+ */
61
+ let ExtToken = (() => {
62
+ let _classDecorators = [(0, attributesParent_1.attributesParent)()];
63
+ let _classDescriptor;
64
+ let _classExtraInitializers = [];
65
+ let _classThis;
66
+ let _classSuper = index_3.TagPairToken;
67
+ var ExtToken = class extends _classSuper {
68
+ static { _classThis = this; }
69
+ static {
70
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
71
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
72
+ ExtToken = _classThis = _classDescriptor.value;
73
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
74
+ __runInitializers(_classThis, _classExtraInitializers);
75
+ }
76
+ type = 'ext';
77
+ /* NOT FOR BROWSER END */
78
+ /**
79
+ * @param name 标签名
80
+ * @param attr 标签属性
81
+ * @param inner 内部wikitext
82
+ * @param closed 是否封闭
83
+ */
84
+ constructor(name, attr, inner, closed, config = index_1.default.getConfig(), accum = []) {
85
+ const lcName = name.toLowerCase(),
86
+ // @ts-expect-error abstract class
87
+ attrToken = new attributes_1.AttributesToken(!attr || attr.trimStart() !== attr ? attr : ` ${attr}`, 'ext-attrs', lcName, config, accum), newConfig = { ...config, ext: del(config.ext, lcName), excludes: [...config.excludes ?? []] };
88
+ let innerToken;
89
+ switch (lcName) {
90
+ case 'tab':
91
+ newConfig.ext = del(newConfig.ext, 'tabs');
92
+ // fall through
93
+ case 'indicator':
94
+ case 'poem':
95
+ case 'ref':
96
+ case 'option':
97
+ case 'combooption':
98
+ case 'tabs':
99
+ case 'poll':
100
+ case 'seo':
101
+ if (lcName === 'poem') {
102
+ newConfig.excludes.push('heading');
103
+ }
104
+ innerToken = new index_2.Token(inner, newConfig, accum);
105
+ break;
106
+ case 'pre': {
107
+ const { PreToken } = require('../pre');
108
+ // @ts-expect-error abstract class
109
+ innerToken = new PreToken(inner, newConfig, accum);
110
+ break;
111
+ }
112
+ case 'dynamicpagelist': {
113
+ const { ParamTagToken } = require('../paramTag/index');
114
+ // @ts-expect-error abstract class
115
+ innerToken = new ParamTagToken(inner, newConfig, accum);
116
+ break;
117
+ }
118
+ case 'inputbox': {
119
+ newConfig.excludes.push('heading');
120
+ const { InputboxToken } = require('../paramTag/inputbox');
121
+ // @ts-expect-error abstract class
122
+ innerToken = new InputboxToken(inner, newConfig, accum);
123
+ break;
124
+ }
125
+ case 'references': {
126
+ const { NestedToken } = require('../nested');
127
+ // @ts-expect-error abstract class
128
+ innerToken = new NestedToken(inner, /<!--.*?(?:-->|$)|<(ref)(\s[^>]*)?>(.*?)<\/(ref\s*)>/gisu, ['ref'], newConfig, accum);
129
+ break;
130
+ }
131
+ case 'choose': {
132
+ const { NestedToken } = require('../nested');
133
+ // @ts-expect-error abstract class
134
+ innerToken = new NestedToken(inner, /<(option|choicetemplate)(\s[^>]*)?>(.*?)<\/(\1)>/gsu, ['option', 'choicetemplate'], newConfig, accum);
135
+ break;
136
+ }
137
+ case 'combobox': {
138
+ const { NestedToken } = require('../nested');
139
+ // @ts-expect-error abstract class
140
+ innerToken = new NestedToken(inner, /<(combooption)(\s[^>]*)?>(.*?)<\/(combooption\s*)>/gisu, ['combooption'], newConfig, accum);
141
+ break;
142
+ }
143
+ case 'gallery': {
144
+ const { GalleryToken } = require('../gallery');
145
+ // @ts-expect-error abstract class
146
+ innerToken = new GalleryToken(inner, newConfig, accum);
147
+ break;
148
+ }
149
+ case 'imagemap': {
150
+ const { ImagemapToken } = require('../imagemap');
151
+ // @ts-expect-error abstract class
152
+ innerToken = new ImagemapToken(inner, newConfig, accum);
153
+ break;
154
+ }
155
+ // 更多定制扩展的代码示例:
156
+ // ```
157
+ // case 'extensionName': {
158
+ // const {ExtensionToken}: typeof import('../extension') = require('../extension');
159
+ // innerToken = new ExtensionToken(inner, newConfig, accum);
160
+ // break;
161
+ // }
162
+ // ```
163
+ default: {
164
+ const { NowikiToken } = require('../nowiki/index');
165
+ // @ts-expect-error abstract class
166
+ innerToken = new NowikiToken(inner, newConfig);
167
+ }
168
+ }
169
+ innerToken.setAttribute('name', lcName);
170
+ innerToken.type = 'ext-inner';
171
+ super(name, attrToken, innerToken, closed, config, accum);
172
+ this.seal('closed', true);
173
+ }
174
+ /** @override */
175
+ lint(start = this.getAbsoluteIndex()) {
176
+ const errors = super.lint(start);
177
+ let rect;
178
+ if (this.name !== 'nowiki' && this.closest('html-attrs, table-attrs')) {
179
+ rect = { start, ...this.getRootNode().posFromIndex(start) };
180
+ errors.push((0, lint_1.generateForSelf)(this, rect, 'extension tag in HTML tag attributes'));
181
+ }
182
+ if (this.name === 'ref' && this.closest('heading-title')) {
183
+ rect ??= { start, ...this.getRootNode().posFromIndex(start) };
184
+ errors.push((0, lint_1.generateForSelf)(this, rect, 'variable anchor in a section header'));
185
+ }
186
+ return errors;
187
+ }
188
+ /* NOT FOR BROWSER */
189
+ /** @override */
190
+ cloneNode() {
191
+ const inner = this.lastChild.cloneNode(), tags = this.getAttribute('tags'), config = this.getAttribute('config'), attr = String(this.firstChild);
192
+ return debug_1.Shadow.run(() => {
193
+ // @ts-expect-error abstract class
194
+ const token = new ExtToken(tags[0], attr, '', this.selfClosing ? undefined : tags[1], config);
195
+ token.lastChild.safeReplaceWith(inner);
196
+ return token;
197
+ });
198
+ }
199
+ };
200
+ return ExtToken = _classThis;
201
+ })();
202
+ exports.ExtToken = ExtToken;
203
+ constants_1.classes['ExtToken'] = __filename;
@@ -0,0 +1,35 @@
1
+ import Parser from '../../index';
2
+ import { TagPairToken } from './index';
3
+ import type { LintError } from '../../base';
4
+ import type { AstText, Token } from '../../internal';
5
+ export declare abstract class IncludeToken extends TagPairToken {
6
+ readonly type = "include";
7
+ readonly childNodes: readonly [AstText, AstText];
8
+ abstract get firstChild(): AstText;
9
+ abstract get lastChild(): AstText;
10
+ abstract get children(): [];
11
+ abstract get firstElementChild(): undefined;
12
+ abstract get lastElementChild(): undefined;
13
+ /** @override */
14
+ get innerText(): string | undefined;
15
+ set innerText(text: string | undefined);
16
+ /**
17
+ * @param name 标签名
18
+ * @param attr 标签属性
19
+ * @param inner 内部wikitext
20
+ * @param closed 是否封闭
21
+ */
22
+ constructor(name: string, attr?: string, inner?: string, closed?: string, config?: Parser.Config, accum?: Token[]);
23
+ /** @override */
24
+ lint(start?: number): LintError[];
25
+ /** @override */
26
+ cloneNode(): this;
27
+ /**
28
+ * @override
29
+ * @param str 新文本
30
+ */
31
+ setText(str: string): string;
32
+ /** 清除标签属性 */
33
+ removeAttr(): void;
34
+ }
35
+ export {};
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IncludeToken = void 0;
4
+ const lint_1 = require("../../util/lint");
5
+ const debug_1 = require("../../util/debug");
6
+ const constants_1 = require("../../util/constants");
7
+ const hidden_1 = require("../../mixin/hidden");
8
+ const index_1 = require("../../index");
9
+ const index_2 = require("./index");
10
+ /**
11
+ * `<includeonly>`或`<noinclude>`或`<onlyinclude>`
12
+ * @classdesc `{childNodes: [AstText, AstText]}`
13
+ */
14
+ class IncludeToken extends (0, hidden_1.hiddenToken)(index_2.TagPairToken) {
15
+ type = 'include';
16
+ /** @override */
17
+ get innerText() {
18
+ return this.selfClosing ? undefined : this.lastChild.data;
19
+ }
20
+ set innerText(text) {
21
+ if (text === undefined) {
22
+ this.selfClosing = true;
23
+ }
24
+ else {
25
+ this.selfClosing = false;
26
+ this.setText(text);
27
+ }
28
+ }
29
+ /* NOT FOR BROWSER END */
30
+ /**
31
+ * @param name 标签名
32
+ * @param attr 标签属性
33
+ * @param inner 内部wikitext
34
+ * @param closed 是否封闭
35
+ */
36
+ constructor(name, attr = '', inner, closed, config = index_1.default.getConfig(), accum = []) {
37
+ super(name, attr, inner ?? '', inner === undefined ? closed : closed ?? '', config, accum);
38
+ }
39
+ /** @override */
40
+ lint(start = this.getAbsoluteIndex()) {
41
+ return this.closed ? [] : [(0, lint_1.generateForSelf)(this, { start }, index_1.default.msg('unclosed $1', `<${this.name}>`))];
42
+ }
43
+ /* NOT FOR BROWSER */
44
+ /** @override */
45
+ cloneNode() {
46
+ const tags = this.getAttribute('tags'), config = this.getAttribute('config'), { innerText } = this, closing = this.selfClosing || !this.closed ? undefined : tags[1];
47
+ // @ts-expect-error abstract class
48
+ return debug_1.Shadow.run(() => new IncludeToken(tags[0], this.firstChild.data, innerText, closing, config));
49
+ }
50
+ /**
51
+ * @override
52
+ * @param str 新文本
53
+ */
54
+ setText(str) {
55
+ return super.setText(str, 1);
56
+ }
57
+ /** 清除标签属性 */
58
+ removeAttr() {
59
+ super.setText('');
60
+ }
61
+ }
62
+ exports.IncludeToken = IncludeToken;
63
+ constants_1.classes['IncludeToken'] = __filename;
@@ -0,0 +1,27 @@
1
+ import Parser from '../../index';
2
+ import { Token } from '../index';
3
+ import type { AstNodes } from '../../lib/node';
4
+ /** 成对标签 */
5
+ export declare abstract class TagPairToken extends Token {
6
+ #private;
7
+ type: 'ext' | 'include';
8
+ readonly name: string;
9
+ closed: boolean;
10
+ selfClosing: boolean;
11
+ readonly childNodes: readonly [AstNodes, AstNodes];
12
+ abstract get firstChild(): AstNodes;
13
+ abstract get lastChild(): AstNodes;
14
+ /** 内部wikitext */
15
+ get innerText(): string | undefined;
16
+ /**
17
+ * @param name 标签名
18
+ * @param attr 标签属性
19
+ * @param inner 内部wikitext
20
+ * @param closed 是否封闭;约定`undefined`表示自封闭,`''`表示未闭合
21
+ */
22
+ constructor(name: string, attr: string | Token, inner: string | Token, closed?: string, config?: Parser.Config, accum?: Token[]);
23
+ /** @override */
24
+ text(): string;
25
+ /** @override */
26
+ print(): string;
27
+ }
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.TagPairToken = void 0;
38
+ const constants_1 = require("../../util/constants");
39
+ const fixed_1 = require("../../mixin/fixed");
40
+ const index_1 = require("../../index");
41
+ const index_2 = require("../index");
42
+ /** 成对标签 */
43
+ let TagPairToken = (() => {
44
+ let _classDecorators = [fixed_1.fixedToken];
45
+ let _classDescriptor;
46
+ let _classExtraInitializers = [];
47
+ let _classThis;
48
+ let _classSuper = index_2.Token;
49
+ var TagPairToken = class extends _classSuper {
50
+ static { _classThis = this; }
51
+ static {
52
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
53
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
54
+ TagPairToken = _classThis = _classDescriptor.value;
55
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
56
+ __runInitializers(_classThis, _classExtraInitializers);
57
+ }
58
+ #tags;
59
+ closed;
60
+ selfClosing;
61
+ /* NOT FOR BROWSER END */
62
+ /** 内部wikitext */
63
+ get innerText() {
64
+ return this.selfClosing ? undefined : this.lastChild.text();
65
+ }
66
+ /**
67
+ * @param name 标签名
68
+ * @param attr 标签属性
69
+ * @param inner 内部wikitext
70
+ * @param closed 是否封闭;约定`undefined`表示自封闭,`''`表示未闭合
71
+ */
72
+ constructor(name, attr, inner, closed, config = index_1.default.getConfig(), accum = []) {
73
+ super(undefined, config);
74
+ this.setAttribute('name', name.toLowerCase());
75
+ this.#tags = [name, closed || name];
76
+ this.closed = closed !== '';
77
+ this.selfClosing = closed === undefined;
78
+ this.append(attr, inner);
79
+ const index = typeof attr === 'string' ? -1 : accum.indexOf(attr);
80
+ accum.splice(index === -1 ? Infinity : index, 0, this);
81
+ }
82
+ /** @private */
83
+ toString() {
84
+ const { selfClosing, firstChild, lastChild,
85
+ /* NOT FOR BROWSER */
86
+ nextSibling, name, closed, } = this, [opening, closing] = this.#tags;
87
+ /* NOT FOR BROWSER */
88
+ if (!closed && nextSibling) {
89
+ index_1.default.error(`自动闭合 <${name}>`, lastChild);
90
+ this.closed = true;
91
+ }
92
+ /* NOT FOR BROWSER END */
93
+ return selfClosing
94
+ ? `<${opening}${String(firstChild)}/>`
95
+ : `<${opening}${String(firstChild)}>${String(lastChild)}${this.closed ? `</${closing}>` : ''}`;
96
+ }
97
+ /** @override */
98
+ text() {
99
+ const [opening, closing] = this.#tags;
100
+ return this.selfClosing
101
+ ? `<${opening}${this.firstChild.text()}/>`
102
+ : `<${opening}${super.text('>')}${this.closed ? `</${closing}>` : ''}`;
103
+ }
104
+ /** @private */
105
+ getAttribute(key) {
106
+ /* NOT FOR BROWSER */
107
+ if (key === 'tags') {
108
+ return [...this.#tags];
109
+ }
110
+ /* NOT FOR BROWSER END */
111
+ return key === 'padding' ? this.#tags[0].length + 1 : super.getAttribute(key);
112
+ }
113
+ /** @private */
114
+ getGaps() {
115
+ return 1;
116
+ }
117
+ /** @override */
118
+ print() {
119
+ const [opening, closing] = this.#tags;
120
+ return super.print(this.selfClosing
121
+ ? { pre: `&lt;${opening}`, post: '/&gt;' }
122
+ : { pre: `&lt;${opening}`, sep: '&gt;', post: this.closed ? `&lt;/${closing}&gt;` : '' });
123
+ }
124
+ };
125
+ return TagPairToken = _classThis;
126
+ })();
127
+ exports.TagPairToken = TagPairToken;
128
+ constants_1.classes['TagPairToken'] = __filename;