wikiparser-node 1.3.9-b → 1.3.9

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 (153) hide show
  1. package/config/.schema.json +172 -0
  2. package/config/llwiki.json +35 -1
  3. package/config/moegirl.json +44 -1
  4. package/config/zhwiki.json +466 -1
  5. package/dist/addon/table.d.ts +6 -0
  6. package/dist/addon/table.js +558 -0
  7. package/dist/base.d.ts +51 -0
  8. package/dist/index.d.ts +32 -0
  9. package/dist/index.js +211 -0
  10. package/dist/internal.d.ts +44 -0
  11. package/dist/lib/element.d.ts +154 -0
  12. package/dist/lib/element.js +630 -0
  13. package/dist/lib/node.d.ts +146 -0
  14. package/dist/lib/node.js +419 -0
  15. package/dist/lib/range.d.ts +104 -0
  16. package/dist/lib/range.js +385 -0
  17. package/dist/lib/ranges.d.ts +26 -0
  18. package/dist/lib/ranges.js +118 -0
  19. package/dist/lib/text.d.ts +62 -0
  20. package/dist/lib/text.js +255 -0
  21. package/dist/lib/title.d.ts +38 -0
  22. package/dist/lib/title.js +163 -0
  23. package/dist/mixin/attributesParent.js +89 -0
  24. package/dist/mixin/fixed.js +25 -0
  25. package/dist/mixin/flagsParent.js +70 -0
  26. package/dist/mixin/hidden.js +25 -0
  27. package/dist/mixin/magicLinkParent.js +41 -0
  28. package/dist/mixin/singleLine.js +25 -0
  29. package/dist/mixin/sol.js +43 -0
  30. package/dist/mixin/syntax.js +54 -0
  31. package/dist/parser/braces.js +128 -0
  32. package/dist/parser/commentAndExt.js +85 -0
  33. package/dist/parser/converter.js +40 -0
  34. package/dist/parser/externalLinks.js +31 -0
  35. package/dist/parser/hrAndDoubleUnderscore.js +38 -0
  36. package/dist/parser/html.js +36 -0
  37. package/dist/parser/links.js +94 -0
  38. package/dist/parser/list.js +66 -0
  39. package/dist/parser/magicLinks.js +42 -0
  40. package/dist/parser/quotes.js +67 -0
  41. package/dist/parser/selector.js +162 -0
  42. package/dist/parser/table.js +120 -0
  43. package/dist/src/arg.d.ts +58 -0
  44. package/dist/src/arg.js +194 -0
  45. package/dist/src/atom.d.ts +12 -0
  46. package/dist/src/atom.js +27 -0
  47. package/dist/src/attribute.d.ts +88 -0
  48. package/dist/src/attribute.js +422 -0
  49. package/dist/src/attributes.d.ts +109 -0
  50. package/dist/src/attributes.js +343 -0
  51. package/dist/src/converter.d.ts +53 -0
  52. package/dist/src/converter.js +79 -0
  53. package/dist/src/converterFlags.d.ts +87 -0
  54. package/dist/src/converterFlags.js +224 -0
  55. package/dist/src/converterRule.d.ts +77 -0
  56. package/dist/src/converterRule.js +208 -0
  57. package/dist/src/extLink.d.ts +55 -0
  58. package/dist/src/extLink.js +122 -0
  59. package/dist/src/gallery.d.ts +54 -0
  60. package/dist/src/gallery.js +121 -0
  61. package/dist/src/heading.d.ts +78 -0
  62. package/dist/src/heading.js +143 -0
  63. package/dist/src/hidden.d.ts +23 -0
  64. package/dist/src/hidden.js +23 -0
  65. package/dist/src/html.d.ts +106 -0
  66. package/dist/src/html.js +268 -0
  67. package/dist/src/imageParameter.d.ts +65 -0
  68. package/dist/src/imageParameter.js +247 -0
  69. package/dist/src/imagemap.d.ts +56 -0
  70. package/dist/src/imagemap.js +147 -0
  71. package/dist/src/imagemapLink.d.ts +61 -0
  72. package/dist/src/imagemapLink.js +40 -0
  73. package/dist/src/index.d.ts +140 -0
  74. package/dist/src/index.js +769 -0
  75. package/dist/src/link/base.d.ts +52 -0
  76. package/dist/src/link/base.js +213 -0
  77. package/dist/src/link/category.d.ts +13 -0
  78. package/dist/src/link/category.js +29 -0
  79. package/dist/src/link/file.d.ts +96 -0
  80. package/dist/src/link/file.js +256 -0
  81. package/dist/src/link/galleryImage.d.ts +45 -0
  82. package/dist/src/link/galleryImage.js +106 -0
  83. package/dist/src/link/index.d.ts +53 -0
  84. package/dist/src/link/index.js +124 -0
  85. package/dist/src/magicLink.d.ts +69 -0
  86. package/dist/src/magicLink.js +147 -0
  87. package/dist/src/nested.d.ts +43 -0
  88. package/dist/src/nested.js +86 -0
  89. package/dist/src/nowiki/base.d.ts +48 -0
  90. package/dist/src/nowiki/base.js +42 -0
  91. package/dist/src/nowiki/comment.d.ts +43 -0
  92. package/dist/src/nowiki/comment.js +74 -0
  93. package/dist/src/nowiki/dd.d.ts +8 -0
  94. package/dist/src/nowiki/dd.js +25 -0
  95. package/dist/src/nowiki/doubleUnderscore.d.ts +47 -0
  96. package/dist/src/nowiki/doubleUnderscore.js +50 -0
  97. package/dist/src/nowiki/hr.d.ts +33 -0
  98. package/dist/src/nowiki/hr.js +14 -0
  99. package/dist/src/nowiki/index.d.ts +16 -0
  100. package/dist/src/nowiki/index.js +21 -0
  101. package/dist/src/nowiki/list.d.ts +31 -0
  102. package/dist/src/nowiki/list.js +48 -0
  103. package/dist/src/nowiki/listBase.d.ts +20 -0
  104. package/dist/src/nowiki/listBase.js +12 -0
  105. package/dist/src/nowiki/noinclude.d.ts +26 -0
  106. package/dist/src/nowiki/noinclude.js +24 -0
  107. package/dist/src/nowiki/quote.d.ts +30 -0
  108. package/dist/src/nowiki/quote.js +61 -0
  109. package/dist/src/onlyinclude.d.ts +16 -0
  110. package/dist/src/onlyinclude.js +57 -0
  111. package/dist/src/paramTag/index.d.ts +37 -0
  112. package/dist/src/paramTag/index.js +68 -0
  113. package/dist/src/paramTag/inputbox.d.ts +8 -0
  114. package/dist/src/paramTag/inputbox.js +23 -0
  115. package/dist/src/parameter.d.ts +88 -0
  116. package/dist/src/parameter.js +214 -0
  117. package/dist/src/pre.d.ts +28 -0
  118. package/dist/src/pre.js +51 -0
  119. package/dist/src/syntax.d.ts +30 -0
  120. package/dist/src/syntax.js +34 -0
  121. package/dist/src/table/base.d.ts +59 -0
  122. package/dist/src/table/base.js +78 -0
  123. package/dist/src/table/index.d.ts +230 -0
  124. package/dist/src/table/index.js +386 -0
  125. package/dist/src/table/td.d.ts +109 -0
  126. package/dist/src/table/td.js +270 -0
  127. package/dist/src/table/tr.d.ts +32 -0
  128. package/dist/src/table/tr.js +56 -0
  129. package/dist/src/table/trBase.d.ts +53 -0
  130. package/dist/src/table/trBase.js +153 -0
  131. package/dist/src/tagPair/ext.d.ts +57 -0
  132. package/dist/src/tagPair/ext.js +134 -0
  133. package/dist/src/tagPair/include.d.ts +56 -0
  134. package/dist/src/tagPair/include.js +70 -0
  135. package/dist/src/tagPair/index.d.ts +45 -0
  136. package/dist/src/tagPair/index.js +76 -0
  137. package/dist/src/transclude.d.ts +167 -0
  138. package/dist/src/transclude.js +694 -0
  139. package/dist/util/constants.js +113 -0
  140. package/dist/util/debug.js +83 -0
  141. package/dist/util/diff.js +72 -0
  142. package/dist/util/lint.js +30 -0
  143. package/dist/util/string.js +51 -0
  144. package/errors/README +1 -0
  145. package/package.json +13 -30
  146. package/printed/README +1 -0
  147. package/bundle/bundle.min.js +0 -36
  148. package/extensions/dist/base.js +0 -64
  149. package/extensions/dist/editor.js +0 -159
  150. package/extensions/dist/highlight.js +0 -30
  151. package/extensions/dist/lint.js +0 -48
  152. package/extensions/editor.css +0 -63
  153. package/extensions/ui.css +0 -114
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArgToken = void 0;
4
+ const string_1 = require("../util/string");
5
+ const lint_1 = require("../util/lint");
6
+ const constants_1 = require("../util/constants");
7
+ const debug_1 = require("../util/debug");
8
+ const Parser = require("../index");
9
+ const index_1 = require("./index");
10
+ const atom_1 = require("./atom");
11
+ const hidden_1 = require("./hidden");
12
+ /**
13
+ * `{{{}}}`包裹的参数
14
+ * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
15
+ */
16
+ class ArgToken extends index_1.Token {
17
+ type = 'arg';
18
+ /** 预设值 */
19
+ get default() {
20
+ return this.childNodes[1]?.text() ?? false;
21
+ }
22
+ /* NOT FOR BROWSER */
23
+ set default(value) {
24
+ this.setDefault(value);
25
+ }
26
+ /* NOT FOR BROWSER END */
27
+ /** @param parts 以'|'分隔的各部分 */
28
+ constructor(parts, config = Parser.getConfig(), accum = []) {
29
+ super(undefined, config, accum, {
30
+ AtomToken: 0, Token: 1, HiddenToken: '2:',
31
+ });
32
+ for (let i = 0; i < parts.length; i++) {
33
+ if (i === 0) {
34
+ const token = new atom_1.AtomToken(parts[i], 'arg-name', config, accum, {
35
+ 'Stage-2': ':', '!HeadingToken': '',
36
+ });
37
+ super.insertAt(token);
38
+ }
39
+ else if (i > 1) {
40
+ const token = new hidden_1.HiddenToken(parts[i], config, accum, {
41
+ 'Stage-2': ':', '!HeadingToken': '',
42
+ });
43
+ super.insertAt(token);
44
+ }
45
+ else {
46
+ const token = new index_1.Token(parts[i], config, accum);
47
+ token.type = 'arg-default';
48
+ token.setAttribute('stage', 2);
49
+ super.insertAt(token);
50
+ }
51
+ }
52
+ this.protectChildren(0);
53
+ }
54
+ /** @private */
55
+ toString(omit) {
56
+ return omit && this.matchesTypes(omit) ? '' : `{{{${super.toString(omit, '|')}}}}`;
57
+ }
58
+ /** @override */
59
+ text() {
60
+ return `{{{${(0, string_1.text)(this.childNodes.slice(0, 2), '|')}}}}`;
61
+ }
62
+ /** @private */
63
+ getAttribute(key) {
64
+ return key === 'padding' ? 3 : super.getAttribute(key);
65
+ }
66
+ /** @private */
67
+ getGaps() {
68
+ return 1;
69
+ }
70
+ /** @override */
71
+ lint(start = this.getAbsoluteIndex()) {
72
+ if (!this.getAttribute('include')) {
73
+ return [(0, lint_1.generateForSelf)(this, { start }, 'unexpected template argument')];
74
+ }
75
+ const { childNodes: [argName, argDefault, ...rest] } = this, errors = argName.lint(start + 3);
76
+ if (argDefault) {
77
+ errors.push(...argDefault.lint(start + 4 + String(argName).length));
78
+ }
79
+ if (rest.length > 0) {
80
+ const rect = { start, ...this.getRootNode().posFromIndex(start) };
81
+ errors.push(...rest.map(child => {
82
+ const error = (0, lint_1.generateForChild)(child, rect, 'invisible content inside triple braces');
83
+ return {
84
+ ...error,
85
+ startIndex: error.startIndex - 1,
86
+ startCol: error.startCol - 1,
87
+ };
88
+ }));
89
+ }
90
+ return errors;
91
+ }
92
+ /** @override */
93
+ print() {
94
+ return super.print({ pre: '{{{', post: '}}}', sep: '|' });
95
+ }
96
+ /** @override */
97
+ json() {
98
+ return {
99
+ ...super.json(),
100
+ default: this.default,
101
+ };
102
+ }
103
+ /* NOT FOR BROWSER */
104
+ /** @override */
105
+ cloneNode() {
106
+ const [name, ...cloned] = this.cloneChildNodes();
107
+ return debug_1.Shadow.run(() => {
108
+ const token = new ArgToken([''], this.getAttribute('config'));
109
+ token.firstChild.safeReplaceWith(name);
110
+ token.append(...cloned);
111
+ token.afterBuild();
112
+ return token;
113
+ });
114
+ }
115
+ /** 设置name */
116
+ #setName() {
117
+ this.setAttribute('name', this.firstChild.text().trim());
118
+ }
119
+ /** @private */
120
+ afterBuild() {
121
+ this.#setName();
122
+ const /** @implements */ argListener = ({ prevTarget }) => {
123
+ if (prevTarget === this.firstChild) {
124
+ this.#setName();
125
+ }
126
+ };
127
+ this.addEventListener(['remove', 'insert', 'replace', 'text'], argListener);
128
+ }
129
+ /** 移除无效部分 */
130
+ removeRedundant() {
131
+ debug_1.Shadow.run(() => {
132
+ for (let i = this.length - 1; i > 1; i--) {
133
+ super.removeAt(i);
134
+ }
135
+ });
136
+ }
137
+ /**
138
+ * @override
139
+ * @param i 移除位置
140
+ */
141
+ removeAt(i) {
142
+ if (i === 1) {
143
+ this.removeRedundant();
144
+ }
145
+ return super.removeAt(i);
146
+ }
147
+ /**
148
+ * @override
149
+ * @param token 待插入的子节点
150
+ * @param i 插入位置
151
+ */
152
+ insertAt(token, i = this.length) {
153
+ i += i < 0 ? this.length : 0;
154
+ if (i > 1) {
155
+ this.constructorError('不可插入多余的子节点');
156
+ }
157
+ else if (typeof token === 'string') {
158
+ this.constructorError('不可插入文本节点');
159
+ }
160
+ super.insertAt(token, i);
161
+ if (i === 1) {
162
+ token.type = 'arg-default';
163
+ }
164
+ return token;
165
+ }
166
+ /**
167
+ * 设置参数名
168
+ * @param name 新参数名
169
+ */
170
+ setName(name) {
171
+ const { childNodes } = Parser.parse(name, this.getAttribute('include'), 2, this.getAttribute('config'));
172
+ this.firstChild.replaceChildren(...childNodes);
173
+ }
174
+ /**
175
+ * 设置预设值
176
+ * @param value 预设值
177
+ */
178
+ setDefault(value) {
179
+ if (value === false) {
180
+ this.removeAt(1);
181
+ return;
182
+ }
183
+ const root = Parser.parse(value, this.getAttribute('include'), undefined, this.getAttribute('config')), { childNodes: [, oldDefault] } = this;
184
+ if (oldDefault) {
185
+ oldDefault.replaceChildren(...root.childNodes);
186
+ }
187
+ else {
188
+ root.type = 'arg-default';
189
+ this.insertAt(root);
190
+ }
191
+ }
192
+ }
193
+ exports.ArgToken = ArgToken;
194
+ constants_1.classes['ArgToken'] = __filename;
@@ -0,0 +1,12 @@
1
+ import * as Parser from '../index';
2
+ import { Token } from './index';
3
+ declare type AtomTypes = 'arg-name' | 'attr-key' | 'attr-value' | 'ext-attr-dirty' | 'html-attr-dirty' | 'table-attr-dirty' | 'converter-flag' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'invoke-function' | 'invoke-module' | 'template-name' | 'link-target' | 'param-line';
4
+ /** 不会被继续解析的plain Token */
5
+ export declare class AtomToken extends Token {
6
+ type: AtomTypes;
7
+ /** @class */
8
+ constructor(wikitext: string | undefined, type: AtomTypes, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
9
+ /** @override */
10
+ cloneNode(): this;
11
+ }
12
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AtomToken = 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
+ /** 不会被继续解析的plain Token */
9
+ class AtomToken extends index_1.Token {
10
+ /** @class */
11
+ constructor(wikitext, type, config = Parser.getConfig(), accum = [], acceptable) {
12
+ super(wikitext, config, accum, acceptable);
13
+ this.type = type;
14
+ }
15
+ /* NOT FOR BROWSER */
16
+ /** @override */
17
+ cloneNode() {
18
+ const cloned = this.cloneChildNodes(), config = this.getAttribute('config'), acceptable = this.getAttribute('acceptable');
19
+ return debug_1.Shadow.run(() => {
20
+ const token = new AtomToken(undefined, this.type, config, [], acceptable);
21
+ token.append(...cloned);
22
+ return token;
23
+ });
24
+ }
25
+ }
26
+ exports.AtomToken = AtomToken;
27
+ constants_1.classes['AtomToken'] = __filename;
@@ -0,0 +1,88 @@
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 } from '../internal';
6
+ export type AttributeTypes = 'ext-attr' | 'html-attr' | 'table-attr';
7
+ declare const AttributeToken_base: ((abstract new (...args: any[]) => {
8
+ removeAt(): never;
9
+ insertAt(token: string, i?: number | undefined): Parser.AstText;
10
+ insertAt<T extends Parser.AstNodes>(token: T, i?: number | undefined): T;
11
+ readonly length: number;
12
+ toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
13
+ text(separator?: string | undefined): string;
14
+ lint(start?: number | undefined): Parser.LintError[];
15
+ afterBuild(): void;
16
+ getAttribute<T_1 extends string>(key: T_1): TokenAttributeGetter<T_1>;
17
+ setAttribute<T_2 extends string>(key: T_2, value: TokenAttributeSetter<T_2>): void;
18
+ addEventListener(events: string | string[], listener: AstListener): void;
19
+ replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
20
+ constructorError(msg: string): never;
21
+ }) & {
22
+ readonly fixed: true;
23
+ }) & typeof Parser.Token;
24
+ /**
25
+ * 扩展和HTML标签属性
26
+ * @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
27
+ */
28
+ export declare class AttributeToken extends AttributeToken_base {
29
+ #private;
30
+ type: AttributeTypes;
31
+ readonly name: string;
32
+ readonly tag: string;
33
+ readonly childNodes: [AtomToken, Token];
34
+ abstract get children(): [AtomToken, Token];
35
+ abstract get firstChild(): AtomToken;
36
+ abstract get firstElementChild(): AtomToken;
37
+ abstract get lastChild(): Token;
38
+ abstract get lastElementChild(): Token;
39
+ abstract get parentNode(): AttributesToken | undefined;
40
+ abstract get parentElement(): AttributesToken | undefined;
41
+ abstract get nextSibling(): AtomToken | this | undefined;
42
+ abstract get nextElementSibling(): AtomToken | this | undefined;
43
+ abstract get previousSibling(): AtomToken | this | undefined;
44
+ abstract get previousElementSibling(): AtomToken | this | undefined;
45
+ /** 引号是否匹配 */
46
+ get balanced(): boolean;
47
+ set balanced(value: boolean);
48
+ /** getValue()的getter */
49
+ get value(): string | true;
50
+ set value(value: string | true);
51
+ /**
52
+ * @param type 标签类型
53
+ * @param tag 标签名
54
+ * @param key 属性名
55
+ * @param equal 等号
56
+ * @param value 属性值
57
+ * @param quotes 引号
58
+ */
59
+ constructor(type: AttributeTypes, tag: string, key: string, equal?: string, value?: string, quotes?: readonly [string?, string?], config?: Parser.Config, accum?: Token[]);
60
+ /** @override */
61
+ text(): string;
62
+ /** @override */
63
+ lint(start?: number): LintError[];
64
+ /** 获取属性值 */
65
+ getValue(): string | true;
66
+ /** @override */
67
+ print(): string;
68
+ /** @override */
69
+ cloneNode(): this;
70
+ /** 转义等号 */
71
+ escape(): void;
72
+ /** 闭合引号 */
73
+ close(): void;
74
+ /**
75
+ * 设置属性值
76
+ * @param value 参数值
77
+ * @throws `RangeError` 扩展标签属性不能包含 ">"
78
+ * @throws `RangeError` 同时包含单引号和双引号
79
+ */
80
+ setValue(value: string | boolean): void;
81
+ /**
82
+ * 修改属性名
83
+ * @param key 新属性名
84
+ * @throws `Error` title和alt属性不能更名
85
+ */
86
+ rename(key: string): void;
87
+ }
88
+ export {};