wikiparser-node 1.2.0 → 1.3.0-b

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 (154) hide show
  1. package/bundle/bundle.min.js +36 -0
  2. package/config/llwiki.json +1 -35
  3. package/config/moegirl.json +1 -44
  4. package/config/zhwiki.json +1 -466
  5. package/extensions/dist/base.js +68 -0
  6. package/extensions/dist/editor.js +159 -0
  7. package/extensions/dist/highlight.js +30 -0
  8. package/extensions/dist/lint.js +48 -0
  9. package/extensions/editor.css +63 -0
  10. package/extensions/ui.css +117 -0
  11. package/package.json +33 -12
  12. package/config/.schema.json +0 -172
  13. package/dist/addon/table.d.ts +0 -6
  14. package/dist/addon/table.js +0 -564
  15. package/dist/base.d.ts +0 -46
  16. package/dist/bin/toc.js +0 -18
  17. package/dist/index.d.ts +0 -31
  18. package/dist/index.js +0 -209
  19. package/dist/internal.d.ts +0 -44
  20. package/dist/lib/element.d.ts +0 -155
  21. package/dist/lib/element.js +0 -654
  22. package/dist/lib/node.d.ts +0 -146
  23. package/dist/lib/node.js +0 -419
  24. package/dist/lib/range.d.ts +0 -104
  25. package/dist/lib/range.js +0 -385
  26. package/dist/lib/ranges.d.ts +0 -26
  27. package/dist/lib/ranges.js +0 -117
  28. package/dist/lib/text.d.ts +0 -62
  29. package/dist/lib/text.js +0 -235
  30. package/dist/lib/title.d.ts +0 -38
  31. package/dist/lib/title.js +0 -162
  32. package/dist/mixin/attributesParent.js +0 -94
  33. package/dist/mixin/fixed.js +0 -32
  34. package/dist/mixin/flagsParent.js +0 -70
  35. package/dist/mixin/hidden.js +0 -22
  36. package/dist/mixin/magicLinkParent.js +0 -41
  37. package/dist/mixin/singleLine.js +0 -25
  38. package/dist/mixin/sol.js +0 -43
  39. package/dist/mixin/syntax.js +0 -56
  40. package/dist/parser/braces.js +0 -123
  41. package/dist/parser/commentAndExt.js +0 -69
  42. package/dist/parser/converter.js +0 -40
  43. package/dist/parser/externalLinks.js +0 -28
  44. package/dist/parser/hrAndDoubleUnderscore.js +0 -38
  45. package/dist/parser/html.js +0 -36
  46. package/dist/parser/links.js +0 -94
  47. package/dist/parser/list.js +0 -59
  48. package/dist/parser/magicLinks.js +0 -40
  49. package/dist/parser/quotes.js +0 -67
  50. package/dist/parser/selector.js +0 -162
  51. package/dist/parser/table.js +0 -112
  52. package/dist/src/arg.d.ts +0 -58
  53. package/dist/src/arg.js +0 -190
  54. package/dist/src/atom.d.ts +0 -12
  55. package/dist/src/atom.js +0 -27
  56. package/dist/src/attribute.d.ts +0 -86
  57. package/dist/src/attribute.js +0 -392
  58. package/dist/src/attributes.d.ts +0 -107
  59. package/dist/src/attributes.js +0 -344
  60. package/dist/src/converter.d.ts +0 -51
  61. package/dist/src/converter.js +0 -79
  62. package/dist/src/converterFlags.d.ts +0 -87
  63. package/dist/src/converterFlags.js +0 -223
  64. package/dist/src/converterRule.d.ts +0 -81
  65. package/dist/src/converterRule.js +0 -212
  66. package/dist/src/extLink.d.ts +0 -53
  67. package/dist/src/extLink.js +0 -121
  68. package/dist/src/gallery.d.ts +0 -55
  69. package/dist/src/gallery.js +0 -123
  70. package/dist/src/heading.d.ts +0 -72
  71. package/dist/src/heading.js +0 -128
  72. package/dist/src/hidden.d.ts +0 -21
  73. package/dist/src/hidden.js +0 -23
  74. package/dist/src/html.d.ts +0 -103
  75. package/dist/src/html.js +0 -230
  76. package/dist/src/imageParameter.d.ts +0 -66
  77. package/dist/src/imageParameter.js +0 -247
  78. package/dist/src/imagemap.d.ts +0 -57
  79. package/dist/src/imagemap.js +0 -148
  80. package/dist/src/imagemapLink.d.ts +0 -57
  81. package/dist/src/imagemapLink.js +0 -40
  82. package/dist/src/index.d.ts +0 -146
  83. package/dist/src/index.js +0 -777
  84. package/dist/src/link/base.d.ts +0 -52
  85. package/dist/src/link/base.js +0 -207
  86. package/dist/src/link/category.d.ts +0 -13
  87. package/dist/src/link/category.js +0 -29
  88. package/dist/src/link/file.d.ts +0 -96
  89. package/dist/src/link/file.js +0 -253
  90. package/dist/src/link/galleryImage.d.ts +0 -43
  91. package/dist/src/link/galleryImage.js +0 -106
  92. package/dist/src/link/index.d.ts +0 -53
  93. package/dist/src/link/index.js +0 -123
  94. package/dist/src/magicLink.d.ts +0 -69
  95. package/dist/src/magicLink.js +0 -148
  96. package/dist/src/nested.d.ts +0 -44
  97. package/dist/src/nested.js +0 -87
  98. package/dist/src/nowiki/base.d.ts +0 -46
  99. package/dist/src/nowiki/base.js +0 -42
  100. package/dist/src/nowiki/comment.d.ts +0 -39
  101. package/dist/src/nowiki/comment.js +0 -67
  102. package/dist/src/nowiki/dd.d.ts +0 -8
  103. package/dist/src/nowiki/dd.js +0 -25
  104. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -43
  105. package/dist/src/nowiki/doubleUnderscore.js +0 -50
  106. package/dist/src/nowiki/hr.d.ts +0 -29
  107. package/dist/src/nowiki/hr.js +0 -14
  108. package/dist/src/nowiki/index.d.ts +0 -16
  109. package/dist/src/nowiki/index.js +0 -21
  110. package/dist/src/nowiki/list.d.ts +0 -29
  111. package/dist/src/nowiki/list.js +0 -48
  112. package/dist/src/nowiki/listBase.d.ts +0 -18
  113. package/dist/src/nowiki/listBase.js +0 -12
  114. package/dist/src/nowiki/noinclude.d.ts +0 -25
  115. package/dist/src/nowiki/noinclude.js +0 -25
  116. package/dist/src/nowiki/quote.d.ts +0 -22
  117. package/dist/src/nowiki/quote.js +0 -50
  118. package/dist/src/onlyinclude.d.ts +0 -16
  119. package/dist/src/onlyinclude.js +0 -57
  120. package/dist/src/paramTag/index.d.ts +0 -37
  121. package/dist/src/paramTag/index.js +0 -68
  122. package/dist/src/paramTag/inputbox.d.ts +0 -8
  123. package/dist/src/paramTag/inputbox.js +0 -23
  124. package/dist/src/parameter.d.ts +0 -84
  125. package/dist/src/parameter.js +0 -206
  126. package/dist/src/pre.d.ts +0 -28
  127. package/dist/src/pre.js +0 -51
  128. package/dist/src/syntax.d.ts +0 -24
  129. package/dist/src/syntax.js +0 -30
  130. package/dist/src/table/base.d.ts +0 -52
  131. package/dist/src/table/base.js +0 -78
  132. package/dist/src/table/index.d.ts +0 -229
  133. package/dist/src/table/index.js +0 -380
  134. package/dist/src/table/td.d.ts +0 -103
  135. package/dist/src/table/td.js +0 -261
  136. package/dist/src/table/tr.d.ts +0 -32
  137. package/dist/src/table/tr.js +0 -56
  138. package/dist/src/table/trBase.d.ts +0 -54
  139. package/dist/src/table/trBase.js +0 -159
  140. package/dist/src/tagPair/ext.d.ts +0 -58
  141. package/dist/src/tagPair/ext.js +0 -142
  142. package/dist/src/tagPair/include.d.ts +0 -52
  143. package/dist/src/tagPair/include.js +0 -58
  144. package/dist/src/tagPair/index.d.ts +0 -47
  145. package/dist/src/tagPair/index.js +0 -93
  146. package/dist/src/transclude.d.ts +0 -167
  147. package/dist/src/transclude.js +0 -689
  148. package/dist/util/constants.js +0 -108
  149. package/dist/util/debug.js +0 -64
  150. package/dist/util/diff.js +0 -72
  151. package/dist/util/lint.js +0 -48
  152. package/dist/util/string.js +0 -61
  153. package/errors/README +0 -1
  154. package/printed/README +0 -1
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OnlyincludeToken = void 0;
4
- const debug_1 = require("../util/debug");
5
- const constants_1 = require("../util/constants");
6
- const Parser = require("../index");
7
- const index_1 = require("./index");
8
- /**
9
- * 嵌入时的`<onlyinclude>`
10
- * @classdesc `{childNodes: ...AstText|Token}`
11
- */
12
- class OnlyincludeToken extends index_1.Token {
13
- type = 'onlyinclude';
14
- /* NOT FOR BROWSER */
15
- /** 内部wikitext */
16
- get innerText() {
17
- return this.text();
18
- }
19
- /** @throws `RangeError` 不允许包含`</onlyinclude>` */
20
- set innerText(text) {
21
- if (text.includes('</onlyinclude>')) {
22
- throw new RangeError('不允许包含 "</onlyinclude>"!');
23
- }
24
- this.replaceChildren(...Parser.parse(text, true, undefined, this.getAttribute('config')).childNodes);
25
- }
26
- /* NOT FOR BROWSER END */
27
- /** @private */
28
- toString(omit) {
29
- return omit && this.matchesTypes(omit) ? '' : `<onlyinclude>${super.toString(omit)}</onlyinclude>`;
30
- }
31
- /** @private */
32
- getAttribute(key) {
33
- if (key === 'padding') {
34
- return 13;
35
- }
36
- return (key === 'plain') || super.getAttribute(key);
37
- }
38
- /** @override */
39
- print() {
40
- return super.print({
41
- pre: '<span class="wpb-ext">&lt;onlyinclude&gt;</span>',
42
- post: '<span class="wpb-ext">&lt;/onlyinclude&gt;</span>',
43
- });
44
- }
45
- /* NOT FOR BROWSER */
46
- /** @override */
47
- cloneNode() {
48
- const cloned = this.cloneChildNodes();
49
- return debug_1.Shadow.run(() => {
50
- const token = new OnlyincludeToken(undefined, this.getAttribute('config'));
51
- token.append(...cloned);
52
- return token;
53
- });
54
- }
55
- }
56
- exports.OnlyincludeToken = OnlyincludeToken;
57
- constants_1.classes['OnlyincludeToken'] = __filename;
@@ -1,37 +0,0 @@
1
- import * as Parser from '../../index';
2
- import { Token } from '../index';
3
- import { AtomToken } from '../atom';
4
- import type { LintError } from '../../base';
5
- import type { AttributesToken, ExtToken } from '../../internal';
6
- /**
7
- * `<dynamicpagelist>`
8
- * @classdesc `{childNodes: ...AtomToken}`
9
- */
10
- export declare class ParamTagToken extends Token {
11
- readonly type = "ext-inner";
12
- readonly name: string;
13
- readonly childNodes: AtomToken[];
14
- abstract get children(): AtomToken[];
15
- abstract get firstChild(): AtomToken | undefined;
16
- abstract get firstElementChild(): AtomToken | undefined;
17
- abstract get lastChild(): AtomToken | undefined;
18
- abstract get lastElementChild(): AtomToken | undefined;
19
- abstract get nextSibling(): undefined;
20
- abstract get nextElementSibling(): undefined;
21
- abstract get previousSibling(): AttributesToken;
22
- abstract get previousElementSibling(): AttributesToken;
23
- abstract get parentNode(): ExtToken | undefined;
24
- abstract get parentElement(): ExtToken | undefined;
25
- /** @class */
26
- constructor(wikitext?: string, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
27
- /** @override */
28
- text(): string;
29
- /** @override */
30
- lint(start?: number): LintError[];
31
- /** @override */
32
- print(): string;
33
- /** @override */
34
- cloneNode(this: this & {
35
- constructor: new (...args: any[]) => unknown;
36
- }): this;
37
- }
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ParamTagToken = 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 singleLine_1 = require("../../mixin/singleLine");
8
- const Parser = require("../../index");
9
- const index_1 = require("../index");
10
- const atom_1 = require("../atom");
11
- /**
12
- * `<dynamicpagelist>`
13
- * @classdesc `{childNodes: ...AtomToken}`
14
- */
15
- class ParamTagToken extends index_1.Token {
16
- type = 'ext-inner';
17
- /** @class */
18
- constructor(wikitext, config = Parser.getConfig(), accum = [], acceptable = {}) {
19
- super(undefined, config, accum, {
20
- SingleLineAtomToken: ':',
21
- });
22
- if (wikitext) {
23
- const SingleLineAtomToken = (0, singleLine_1.singleLine)(atom_1.AtomToken);
24
- this.append(...wikitext.split('\n').map(line => new SingleLineAtomToken(line, 'param-line', config, accum, {
25
- AstText: ':', ...acceptable,
26
- })));
27
- }
28
- }
29
- /** @private */
30
- toString(omit) {
31
- return super.toString(omit, '\n');
32
- }
33
- /** @override */
34
- text() {
35
- return super.text('\n');
36
- }
37
- /** @private */
38
- getGaps() {
39
- return 1;
40
- }
41
- /** @override */
42
- lint(start = this.getAbsoluteIndex()) {
43
- let rect;
44
- return this.childNodes.filter(child => {
45
- const { childNodes } = child, i = childNodes.findIndex(({ type }) => type !== 'text'), str = (i >= 0 ? childNodes.slice(0, i).map(String).join('') : String(child)).trim();
46
- return str && !(i >= 0 ? /^[a-z]+(?:\[\])?\s*(?:=|$)/iu : /^[a-z]+(?:\[\])?\s*=/iu).test(str);
47
- }).map(child => {
48
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
49
- return (0, lint_1.generateForChild)(child, rect, Parser.msg('invalid parameter of $1', this.name));
50
- });
51
- }
52
- /** @override */
53
- print() {
54
- return super.print({ sep: '\n' });
55
- }
56
- /* NOT FOR BROWSER */
57
- /** @override */
58
- cloneNode() {
59
- const cloned = this.cloneChildNodes();
60
- return debug_1.Shadow.run(() => {
61
- const token = new this.constructor(undefined, this.getAttribute('config'));
62
- token.append(...cloned);
63
- return token;
64
- });
65
- }
66
- }
67
- exports.ParamTagToken = ParamTagToken;
68
- constants_1.classes['ParamTagToken'] = __filename;
@@ -1,8 +0,0 @@
1
- import * as Parser from '../../index';
2
- import { ParamTagToken } from './index';
3
- import type { Token } from '../index';
4
- /** `<inputbox>` */
5
- export declare class InputboxToken extends ParamTagToken {
6
- /** @class */
7
- constructor(wikitext?: string, config?: Parser.Config, accum?: Token[]);
8
- }
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InputboxToken = void 0;
4
- const constants_1 = require("../../util/constants");
5
- const braces_1 = require("../../parser/braces");
6
- const Parser = require("../../index");
7
- const index_1 = require("./index");
8
- /** `<inputbox>` */
9
- // @ts-expect-error not implementing all abstract methods
10
- class InputboxToken extends index_1.ParamTagToken {
11
- /** @class */
12
- constructor(wikitext, config = Parser.getConfig(), accum = []) {
13
- const placeholder = Symbol('InputboxToken');
14
- accum.push(placeholder);
15
- wikitext &&= (0, braces_1.parseBraces)(wikitext, config, accum);
16
- accum.splice(accum.indexOf(placeholder), 1);
17
- super(wikitext, config, accum, {
18
- ArgToken: ':', TranscludeToken: ':',
19
- });
20
- }
21
- }
22
- exports.InputboxToken = InputboxToken;
23
- constants_1.classes['InputboxToken'] = __filename;
@@ -1,84 +0,0 @@
1
- import * as Parser from '../index';
2
- import { Token } from './index';
3
- import type { LintError } from '../base';
4
- import type { AtomToken, SyntaxToken, TranscludeToken } from '../internal';
5
- declare const ParameterToken_base: ((abstract new (...args: any[]) => {
6
- removeAt(): never;
7
- insertAt(token: string, i?: number | undefined): Parser.AstText;
8
- insertAt<T extends Parser.AstNodes>(token: T, i?: number | undefined): T;
9
- readonly length: number;
10
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
11
- text(separator?: string | undefined): string;
12
- afterBuild(): void;
13
- getAttribute<T_1 extends string>(key: T_1): TokenAttributeGetter<T_1>;
14
- setAttribute<T_2 extends string>(key: T_2, value: TokenAttributeSetter<T_2>): void;
15
- addEventListener(events: string | string[], listener: AstListener): void;
16
- replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
17
- }) & {
18
- readonly fixed: true;
19
- }) & typeof Parser.Token;
20
- /**
21
- * 模板或魔术字参数
22
- * @classdesc `{childNodes: [Token, Token]}`
23
- */
24
- export declare class ParameterToken extends ParameterToken_base {
25
- readonly type = "parameter";
26
- readonly name: string;
27
- readonly childNodes: [Token, Token];
28
- abstract get children(): [Token, Token];
29
- abstract get firstChild(): Token;
30
- abstract get firstElementChild(): Token;
31
- abstract get lastChild(): Token;
32
- abstract get lastElementChild(): Token;
33
- abstract get parentNode(): TranscludeToken | undefined;
34
- abstract get parentElement(): TranscludeToken | undefined;
35
- abstract get nextSibling(): this | undefined;
36
- abstract get nextElementSibling(): this | undefined;
37
- abstract get previousSibling(): AtomToken | SyntaxToken | this;
38
- abstract get previousElementSibling(): AtomToken | SyntaxToken | this;
39
- /** 是否是匿名参数 */
40
- get anon(): boolean;
41
- set anon(value: boolean);
42
- /** getValue()的getter */
43
- get value(): string;
44
- set value(value: string);
45
- /** 是否是重复参数 */
46
- get duplicated(): boolean;
47
- set duplicated(value: boolean);
48
- /**
49
- * @param key 参数名
50
- * @param value 参数值
51
- */
52
- constructor(key?: string | number, value?: string, config?: Parser.Config, accum?: Token[]);
53
- /** @override */
54
- text(): string;
55
- /** @override */
56
- lint(start?: number): LintError[];
57
- /** @override */
58
- print(): string;
59
- /** @override */
60
- cloneNode(): this;
61
- /**
62
- * @override
63
- * @param token 待替换的节点
64
- */
65
- safeReplaceWith(token: this): void;
66
- /** 获取参数值 */
67
- getValue(): string;
68
- /**
69
- * 设置参数值
70
- * @param value 参数值
71
- */
72
- setValue(value: string): void;
73
- /**
74
- * 修改参数名
75
- * @param key 新参数名
76
- * @param force 是否无视冲突命名
77
- * @throws `Error` 仅用于模板参数
78
- * @throws `RangeError` 更名造成重复参数
79
- */
80
- rename(key: string, force?: boolean): void;
81
- /** 转义 `=` */
82
- escape(): void;
83
- }
84
- export {};
@@ -1,206 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ParameterToken = void 0;
4
- const string_1 = require("../util/string");
5
- const lint_1 = require("../util/lint");
6
- const debug_1 = require("../util/debug");
7
- const constants_1 = require("../util/constants");
8
- const fixed_1 = require("../mixin/fixed");
9
- const Parser = require("../index");
10
- const index_1 = require("./index");
11
- /**
12
- * 准确获取参数名
13
- * @param name 预定的参数名
14
- */
15
- const getName = (name) => name.toString(new Set(['comment', 'noinclude', 'include']))
16
- .replace(/^[ \t\n\0\v]+|(?<=[^ \t\n\0\v])[ \t\n\0\v]+$/gu, '');
17
- /**
18
- * 模板或魔术字参数
19
- * @classdesc `{childNodes: [Token, Token]}`
20
- */
21
- class ParameterToken extends (0, fixed_1.fixed)(index_1.Token) {
22
- type = 'parameter';
23
- /** 是否是匿名参数 */
24
- get anon() {
25
- return this.firstChild.length === 0;
26
- }
27
- /* NOT FOR BROWSER */
28
- set anon(value) {
29
- if (value) {
30
- throw new Error('无法将命名参数转换为匿名参数!');
31
- }
32
- this.parentNode?.anonToNamed();
33
- }
34
- /** getValue()的getter */
35
- get value() {
36
- return this.getValue();
37
- }
38
- set value(value) {
39
- this.setValue(value);
40
- }
41
- /** 是否是重复参数 */
42
- get duplicated() {
43
- try {
44
- return Boolean(this.parentNode?.getDuplicatedArgs().some(([key]) => key === this.name));
45
- }
46
- catch {
47
- return false;
48
- }
49
- }
50
- set duplicated(value) {
51
- if (this.duplicated && !value) {
52
- this.parentNode.fixDuplication();
53
- }
54
- }
55
- /* NOT FOR BROWSER END */
56
- /**
57
- * @param key 参数名
58
- * @param value 参数值
59
- */
60
- constructor(key, value, config = Parser.getConfig(), accum = []) {
61
- super(undefined, config, accum);
62
- const keyToken = new index_1.Token(typeof key === 'number' ? undefined : key, config, accum, {
63
- 'Stage-11': ':', '!HeadingToken': '',
64
- }), token = new index_1.Token(value, config, accum);
65
- keyToken.type = 'parameter-key';
66
- token.type = 'parameter-value';
67
- token.setAttribute('stage', 2);
68
- this.append(keyToken, token);
69
- }
70
- /** @private */
71
- afterBuild() {
72
- if (!this.anon) {
73
- const { parentNode, firstChild } = this, name = getName(firstChild);
74
- this.setAttribute('name', name);
75
- if (parentNode) {
76
- parentNode.getAttribute('keys').add(name);
77
- parentNode.getArgs(name, false, false).add(this);
78
- }
79
- }
80
- const /** @implements */ parameterListener = ({ prevTarget }, data) => {
81
- if (!this.anon) { // 匿名参数不管怎么变动还是匿名
82
- const { firstChild, name } = this;
83
- if (prevTarget === firstChild) {
84
- const newKey = getName(firstChild);
85
- data.oldKey = name;
86
- data.newKey = newKey;
87
- this.setAttribute('name', newKey);
88
- }
89
- }
90
- };
91
- this.addEventListener(['remove', 'insert', 'replace', 'text'], parameterListener);
92
- }
93
- /** @private */
94
- toString(omit) {
95
- return this.anon
96
- && !(omit && this.matchesTypes(omit))
97
- ? this.lastChild.toString(omit)
98
- : super.toString(omit, '=');
99
- }
100
- /** @override */
101
- text() {
102
- return this.anon ? this.lastChild.text() : super.text('=');
103
- }
104
- /** @private */
105
- getGaps() {
106
- return this.anon ? 0 : 1;
107
- }
108
- /** @override */
109
- lint(start = this.getAbsoluteIndex()) {
110
- const errors = super.lint(start), { firstChild, lastChild, } = this, link = new RegExp(`https?://${string_1.extUrlCharFirst}${string_1.extUrlChar}$`, 'iu')
111
- .exec(firstChild.toString(new Set(['comment', 'noinclude', 'include'])))?.[0];
112
- if (link && new URL(link).search) {
113
- const e = (0, lint_1.generateForChild)(firstChild, { start }, 'unescaped query string in an anonymous parameter');
114
- errors.push({
115
- ...e,
116
- startIndex: e.endIndex,
117
- endIndex: e.endIndex + 1,
118
- startLine: e.endLine,
119
- startCol: e.endCol,
120
- endCol: e.endCol + 1,
121
- excerpt: `${String(firstChild).slice(-25)}=${String(lastChild).slice(0, 25)}`,
122
- });
123
- }
124
- return errors;
125
- }
126
- /** @override */
127
- print() {
128
- return super.print({ sep: this.anon ? '' : '=' });
129
- }
130
- /* NOT FOR BROWSER */
131
- /** @override */
132
- cloneNode() {
133
- const [key, value] = this.cloneChildNodes(), config = this.getAttribute('config');
134
- return debug_1.Shadow.run(() => {
135
- const token = new ParameterToken(this.anon ? Number(this.name) : undefined, undefined, config);
136
- token.firstChild.safeReplaceWith(key);
137
- token.lastChild.safeReplaceWith(value);
138
- token.afterBuild();
139
- if (this.anon) {
140
- token.setAttribute('name', this.name);
141
- }
142
- return token;
143
- });
144
- }
145
- /**
146
- * @override
147
- * @param token 待替换的节点
148
- */
149
- safeReplaceWith(token) {
150
- Parser.warn(`${this.constructor.name}.safeReplaceWith 方法退化到 replaceWith。`);
151
- this.replaceWith(token);
152
- }
153
- /** 获取参数值 */
154
- getValue() {
155
- const value = this.lastChild.text();
156
- return this.anon && this.parentNode?.isTemplate() !== false ? value : value.trim();
157
- }
158
- /**
159
- * 设置参数值
160
- * @param value 参数值
161
- */
162
- setValue(value) {
163
- const { childNodes } = Parser.parse(value, this.getAttribute('include'), undefined, this.getAttribute('config'));
164
- this.lastChild.replaceChildren(...childNodes);
165
- }
166
- /**
167
- * 修改参数名
168
- * @param key 新参数名
169
- * @param force 是否无视冲突命名
170
- * @throws `Error` 仅用于模板参数
171
- * @throws `RangeError` 更名造成重复参数
172
- */
173
- rename(key, force = false) {
174
- const { parentNode, anon } = this;
175
- // 必须检测是否是TranscludeToken
176
- if (parentNode?.isTemplate() === false) {
177
- throw new Error(`${this.constructor.name}.rename 方法仅用于模板参数!`);
178
- }
179
- else if (anon) {
180
- parentNode?.anonToNamed();
181
- }
182
- const root = Parser.parse(key, this.getAttribute('include'), undefined, this.getAttribute('config')), name = getName(root);
183
- if (this.name === name) {
184
- Parser.warn('未改变实际参数名', name);
185
- }
186
- else if (parentNode?.hasArg(name)) {
187
- if (force) {
188
- Parser.warn('参数更名造成重复参数', name);
189
- }
190
- else {
191
- throw new RangeError(`参数更名造成重复参数:${name}`);
192
- }
193
- }
194
- this.firstChild.replaceChildren(...root.childNodes);
195
- }
196
- /** 转义 `=` */
197
- escape() {
198
- for (const child of this.lastChild.childNodes) {
199
- if (child.type === 'text') {
200
- child.escape();
201
- }
202
- }
203
- }
204
- }
205
- exports.ParameterToken = ParameterToken;
206
- constants_1.classes['ParameterToken'] = __filename;
package/dist/src/pre.d.ts DELETED
@@ -1,28 +0,0 @@
1
- import * as Parser from '../index';
2
- import { Token } from './index';
3
- import { NoincludeToken } from './nowiki/noinclude';
4
- import type { AstText, AttributesToken, ExtToken, ConverterToken } from '../internal';
5
- /**
6
- * `<pre>`
7
- * @classdesc `{childNodes: [...AstText|NoincludeToken|ConverterToken]}`
8
- */
9
- export declare class PreToken extends Token {
10
- readonly type = "ext-inner";
11
- readonly name: 'pre';
12
- readonly childNodes: (AstText | NoincludeToken | ConverterToken)[];
13
- abstract get children(): (NoincludeToken | ConverterToken)[];
14
- abstract get firstChild(): AstText | NoincludeToken | ConverterToken | undefined;
15
- abstract get firstElementChild(): NoincludeToken | ConverterToken | undefined;
16
- abstract get lastChild(): AstText | NoincludeToken | ConverterToken | undefined;
17
- abstract get lastElementChild(): NoincludeToken | ConverterToken | undefined;
18
- abstract get nextSibling(): undefined;
19
- abstract get nextElementSibling(): undefined;
20
- abstract get previousSibling(): AttributesToken;
21
- abstract get previousElementSibling(): AttributesToken;
22
- abstract get parentNode(): ExtToken | undefined;
23
- abstract get parentElement(): ExtToken | undefined;
24
- /** @class */
25
- constructor(wikitext?: string, config?: Parser.Config, accum?: Token[]);
26
- /** @override */
27
- cloneNode(): this;
28
- }
package/dist/src/pre.js DELETED
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PreToken = void 0;
4
- const debug_1 = require("../util/debug");
5
- const constants_1 = require("../util/constants");
6
- const Parser = require("../index");
7
- const index_1 = require("./index");
8
- const noinclude_1 = require("./nowiki/noinclude");
9
- /**
10
- * `<pre>`
11
- * @classdesc `{childNodes: [...AstText|NoincludeToken|ConverterToken]}`
12
- */
13
- class PreToken extends index_1.Token {
14
- type = 'ext-inner';
15
- /** @class */
16
- constructor(wikitext, config = Parser.getConfig(), accum = []) {
17
- if (wikitext) {
18
- const opening = '<nowiki>', closing = '</nowiki>', { length } = opening;
19
- let i = wikitext.indexOf(opening), j = wikitext.indexOf(closing, i + length), str = '';
20
- while (i !== -1 && j !== -1) {
21
- new noinclude_1.NoincludeToken(opening, config, accum);
22
- new noinclude_1.NoincludeToken(closing, config, accum);
23
- str += `${wikitext.slice(0, i)}\0${accum.length - 1}c\x7F${wikitext.slice(i + length, j)}\0${accum.length}c\x7F`;
24
- wikitext = wikitext.slice(j + length + 1);
25
- i = wikitext.indexOf(opening);
26
- j = wikitext.indexOf(closing, i + length);
27
- }
28
- wikitext = `${str}${wikitext}`;
29
- }
30
- super(wikitext, config, accum, {
31
- AstText: ':', NoincludeToken: ':', ConverterToken: ':',
32
- });
33
- this.setAttribute('stage', constants_1.MAX_STAGE - 1);
34
- }
35
- /** @private */
36
- getAttribute(key) {
37
- return (key === 'plain') || super.getAttribute(key);
38
- }
39
- /* NOT FOR BROWSER */
40
- /** @override */
41
- cloneNode() {
42
- const cloned = this.cloneChildNodes();
43
- return debug_1.Shadow.run(() => {
44
- const token = new PreToken(undefined, this.getAttribute('config'));
45
- token.append(...cloned);
46
- return token;
47
- });
48
- }
49
- }
50
- exports.PreToken = PreToken;
51
- constants_1.classes['PreToken'] = __filename;
@@ -1,24 +0,0 @@
1
- import * as Parser from '../index';
2
- import { Token } from './index';
3
- declare type SyntaxTypes = 'plain' | 'heading-trail' | 'magic-word-name' | 'table-syntax';
4
- declare const SyntaxToken_base: (abstract new (...args: any[]) => {
5
- "__#5@#pattern": RegExp;
6
- afterBuild(): void;
7
- getAttribute<T extends string>(key: T): TokenAttributeGetter<T>;
8
- setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
9
- replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
10
- readonly length: number;
11
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
12
- text(separator?: string | undefined): string;
13
- insertAt(token: unknown, i?: number | undefined): unknown;
14
- addEventListener(events: string | string[], listener: AstListener): void;
15
- }) & typeof Parser.Token;
16
- /** 满足特定语法格式的plain Token */
17
- export declare class SyntaxToken extends SyntaxToken_base {
18
- type: SyntaxTypes;
19
- /** @param pattern 语法正则 */
20
- constructor(wikitext: string | undefined, pattern: RegExp, type?: SyntaxTypes, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
21
- /** @override */
22
- cloneNode(): this;
23
- }
24
- export {};
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SyntaxToken = void 0;
4
- const debug_1 = require("../util/debug");
5
- const constants_1 = require("../util/constants");
6
- const syntax_1 = require("../mixin/syntax");
7
- const Parser = require("../index");
8
- const index_1 = require("./index");
9
- /** 满足特定语法格式的plain Token */
10
- class SyntaxToken extends (0, syntax_1.syntax)(index_1.Token) {
11
- /** @param pattern 语法正则 */
12
- constructor(wikitext, pattern, type = 'plain', config = Parser.getConfig(), accum = [], acceptable) {
13
- super(wikitext, config, accum, acceptable);
14
- this.type = type;
15
- this.setAttribute('pattern', pattern);
16
- }
17
- /* NOT FOR BROWSER */
18
- /** @override */
19
- cloneNode() {
20
- const cloned = this.cloneChildNodes(), config = this.getAttribute('config'), acceptable = this.getAttribute('acceptable'), pattern = this.getAttribute('pattern');
21
- return debug_1.Shadow.run(() => {
22
- const token = new SyntaxToken(undefined, pattern, this.type, config, [], acceptable);
23
- token.append(...cloned);
24
- token.afterBuild();
25
- return token;
26
- });
27
- }
28
- }
29
- exports.SyntaxToken = SyntaxToken;
30
- constants_1.classes['SyntaxToken'] = __filename;
@@ -1,52 +0,0 @@
1
- import * as Parser from '../../index';
2
- import { Token } from '../index';
3
- import { SyntaxToken } from '../syntax';
4
- import { AttributesToken } from '../attributes';
5
- declare const TableBaseToken_base: (abstract new (...args: any[]) => {
6
- readonly childNodes: Parser.AstNodes[];
7
- readonly "__#8@#attributesChild": Parser.AttributesToken;
8
- attributes: Record<string, string | true>;
9
- className: string;
10
- classList: Set<string>;
11
- id: string;
12
- hasAttr(key: string): boolean;
13
- getAttr(key: string): string | true | undefined;
14
- getAttrNames(): Set<string>;
15
- getAttrs(): Record<string, string | true>;
16
- setAttr(key: string, value: string | boolean): void;
17
- removeAttr(key: string): void;
18
- toggleAttr(key: string, force?: boolean | undefined): void;
19
- readonly length: number;
20
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
21
- text(separator?: string | undefined): string;
22
- insertAt(token: unknown, i?: number | undefined): unknown;
23
- afterBuild(): void;
24
- getAttribute<T extends string>(key: T): TokenAttributeGetter<T>;
25
- setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
26
- addEventListener(events: string | string[], listener: AstListener): void;
27
- replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
28
- }) & typeof Parser.Token;
29
- /**
30
- * 表格行,含开头的换行,不含结尾的换行
31
- * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ...Token]}`
32
- */
33
- export declare abstract class TableBaseToken extends TableBaseToken_base {
34
- type: 'table' | 'tr' | 'td';
35
- readonly childNodes: [SyntaxToken, AttributesToken, ...Token[]];
36
- abstract get children(): [SyntaxToken, AttributesToken, ...Token[]];
37
- abstract get firstChild(): SyntaxToken;
38
- abstract get firstElementChild(): SyntaxToken;
39
- abstract get lastChild(): Token;
40
- abstract get lastElementChild(): Token;
41
- /**
42
- * @param pattern 表格语法正则
43
- * @param syntax 表格语法
44
- * @param attr 表格属性
45
- */
46
- constructor(pattern: RegExp, syntax?: string, attr?: string, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
47
- /** @override */
48
- cloneNode(): this;
49
- /** 转义表格语法 */
50
- escape(): void;
51
- }
52
- export {};