wikiparser-node 1.0.0-beta.5 → 1.0.2-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 (148) hide show
  1. package/bundle/bundle.min.js +37 -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 +70 -0
  6. package/extensions/dist/editor.js +172 -0
  7. package/extensions/dist/highlight.js +39 -0
  8. package/extensions/dist/lint.js +48 -0
  9. package/extensions/editor.css +63 -0
  10. package/extensions/ui.css +119 -0
  11. package/package.json +24 -12
  12. package/config/.schema.json +0 -160
  13. package/dist/bin/toc.js +0 -18
  14. package/dist/index.d.ts +0 -58
  15. package/dist/index.js +0 -313
  16. package/dist/internal.d.ts +0 -44
  17. package/dist/lib/element.d.ts +0 -167
  18. package/dist/lib/element.js +0 -659
  19. package/dist/lib/node.d.ts +0 -147
  20. package/dist/lib/node.js +0 -428
  21. package/dist/lib/range.d.ts +0 -139
  22. package/dist/lib/range.js +0 -412
  23. package/dist/lib/ranges.d.ts +0 -28
  24. package/dist/lib/ranges.js +0 -123
  25. package/dist/lib/text.d.ts +0 -63
  26. package/dist/lib/text.js +0 -216
  27. package/dist/lib/title.d.ts +0 -20
  28. package/dist/lib/title.js +0 -108
  29. package/dist/mixin/attributesParent.js +0 -92
  30. package/dist/mixin/fixed.js +0 -31
  31. package/dist/mixin/hidden.js +0 -22
  32. package/dist/mixin/singleLine.js +0 -25
  33. package/dist/mixin/sol.js +0 -43
  34. package/dist/mixin/syntax.js +0 -55
  35. package/dist/parser/braces.js +0 -120
  36. package/dist/parser/commentAndExt.js +0 -64
  37. package/dist/parser/converter.js +0 -39
  38. package/dist/parser/externalLinks.js +0 -27
  39. package/dist/parser/hrAndDoubleUnderscore.js +0 -37
  40. package/dist/parser/html.js +0 -35
  41. package/dist/parser/links.js +0 -93
  42. package/dist/parser/list.js +0 -58
  43. package/dist/parser/magicLinks.js +0 -39
  44. package/dist/parser/quotes.js +0 -66
  45. package/dist/parser/selector.js +0 -161
  46. package/dist/parser/table.js +0 -109
  47. package/dist/src/arg.d.ts +0 -58
  48. package/dist/src/arg.js +0 -186
  49. package/dist/src/atom.d.ts +0 -12
  50. package/dist/src/atom.js +0 -25
  51. package/dist/src/attribute.d.ts +0 -86
  52. package/dist/src/attribute.js +0 -417
  53. package/dist/src/attributes.d.ts +0 -108
  54. package/dist/src/attributes.js +0 -354
  55. package/dist/src/converter.d.ts +0 -63
  56. package/dist/src/converter.js +0 -126
  57. package/dist/src/converterFlags.d.ts +0 -84
  58. package/dist/src/converterFlags.js +0 -210
  59. package/dist/src/converterRule.d.ts +0 -84
  60. package/dist/src/converterRule.js +0 -244
  61. package/dist/src/extLink.d.ts +0 -51
  62. package/dist/src/extLink.js +0 -148
  63. package/dist/src/gallery.d.ts +0 -54
  64. package/dist/src/gallery.js +0 -119
  65. package/dist/src/heading.d.ts +0 -73
  66. package/dist/src/heading.js +0 -115
  67. package/dist/src/hidden.d.ts +0 -21
  68. package/dist/src/hidden.js +0 -22
  69. package/dist/src/html.d.ts +0 -100
  70. package/dist/src/html.js +0 -229
  71. package/dist/src/imageParameter.d.ts +0 -63
  72. package/dist/src/imageParameter.js +0 -246
  73. package/dist/src/imagemap.d.ts +0 -57
  74. package/dist/src/imagemap.js +0 -144
  75. package/dist/src/imagemapLink.d.ts +0 -57
  76. package/dist/src/imagemapLink.js +0 -39
  77. package/dist/src/index.d.ts +0 -148
  78. package/dist/src/index.js +0 -783
  79. package/dist/src/link/base.d.ts +0 -55
  80. package/dist/src/link/base.js +0 -221
  81. package/dist/src/link/category.d.ts +0 -13
  82. package/dist/src/link/category.js +0 -29
  83. package/dist/src/link/file.d.ts +0 -88
  84. package/dist/src/link/file.js +0 -251
  85. package/dist/src/link/galleryImage.d.ts +0 -47
  86. package/dist/src/link/galleryImage.js +0 -114
  87. package/dist/src/link/index.d.ts +0 -49
  88. package/dist/src/link/index.js +0 -136
  89. package/dist/src/magicLink.d.ts +0 -62
  90. package/dist/src/magicLink.js +0 -130
  91. package/dist/src/nested.d.ts +0 -44
  92. package/dist/src/nested.js +0 -85
  93. package/dist/src/nowiki/base.d.ts +0 -44
  94. package/dist/src/nowiki/base.js +0 -36
  95. package/dist/src/nowiki/comment.d.ts +0 -34
  96. package/dist/src/nowiki/comment.js +0 -52
  97. package/dist/src/nowiki/dd.d.ts +0 -5
  98. package/dist/src/nowiki/dd.js +0 -18
  99. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -47
  100. package/dist/src/nowiki/doubleUnderscore.js +0 -49
  101. package/dist/src/nowiki/hr.d.ts +0 -32
  102. package/dist/src/nowiki/hr.js +0 -14
  103. package/dist/src/nowiki/index.d.ts +0 -16
  104. package/dist/src/nowiki/index.js +0 -20
  105. package/dist/src/nowiki/list.d.ts +0 -24
  106. package/dist/src/nowiki/list.js +0 -31
  107. package/dist/src/nowiki/listBase.d.ts +0 -29
  108. package/dist/src/nowiki/listBase.js +0 -34
  109. package/dist/src/nowiki/noinclude.d.ts +0 -26
  110. package/dist/src/nowiki/noinclude.js +0 -25
  111. package/dist/src/nowiki/quote.d.ts +0 -22
  112. package/dist/src/nowiki/quote.js +0 -48
  113. package/dist/src/onlyinclude.d.ts +0 -14
  114. package/dist/src/onlyinclude.js +0 -49
  115. package/dist/src/paramTag/index.d.ts +0 -37
  116. package/dist/src/paramTag/index.js +0 -66
  117. package/dist/src/paramTag/inputbox.d.ts +0 -8
  118. package/dist/src/paramTag/inputbox.js +0 -22
  119. package/dist/src/parameter.d.ts +0 -82
  120. package/dist/src/parameter.js +0 -190
  121. package/dist/src/pre.d.ts +0 -28
  122. package/dist/src/pre.js +0 -49
  123. package/dist/src/syntax.d.ts +0 -24
  124. package/dist/src/syntax.js +0 -28
  125. package/dist/src/table/base.d.ts +0 -59
  126. package/dist/src/table/base.js +0 -80
  127. package/dist/src/table/index.d.ts +0 -239
  128. package/dist/src/table/index.js +0 -776
  129. package/dist/src/table/td.d.ts +0 -106
  130. package/dist/src/table/td.js +0 -256
  131. package/dist/src/table/tr.d.ts +0 -30
  132. package/dist/src/table/tr.js +0 -50
  133. package/dist/src/table/trBase.d.ts +0 -54
  134. package/dist/src/table/trBase.js +0 -151
  135. package/dist/src/tagPair/ext.d.ts +0 -56
  136. package/dist/src/tagPair/ext.js +0 -138
  137. package/dist/src/tagPair/include.d.ts +0 -46
  138. package/dist/src/tagPair/include.js +0 -41
  139. package/dist/src/tagPair/index.d.ts +0 -47
  140. package/dist/src/tagPair/index.js +0 -94
  141. package/dist/src/transclude.d.ts +0 -171
  142. package/dist/src/transclude.js +0 -697
  143. package/dist/util/debug.js +0 -42
  144. package/dist/util/diff.js +0 -72
  145. package/dist/util/lint.js +0 -48
  146. package/dist/util/string.js +0 -70
  147. package/errors/README +0 -1
  148. package/printed/README +0 -1
@@ -1,63 +0,0 @@
1
- import { AstNode } from './node';
2
- import type { LintError } from '../index';
3
- /** 文本节点 */
4
- export declare class AstText extends AstNode {
5
- #private;
6
- readonly type = "text";
7
- name: undefined;
8
- data: string;
9
- /** 文本长度 */
10
- get length(): number;
11
- /** @param text 包含文本 */
12
- constructor(text: string);
13
- /** 可见部分 */
14
- text(): string;
15
- /**
16
- * Linter
17
- * @param start
18
- */
19
- lint(start?: number): LintError[];
20
- /**
21
- * 替换字符串
22
- * @param text 替换的字符串
23
- */
24
- replaceData(text: string): void;
25
- /** 复制 */
26
- cloneNode(): AstText;
27
- /**
28
- * 在后方添加字符串
29
- * @param text 添加的字符串
30
- */
31
- appendData(text: string): void;
32
- /**
33
- * 删减字符串
34
- * @param offset 起始位置
35
- * @param count 删减字符数
36
- */
37
- deleteData(offset: number, count: number): void;
38
- /**
39
- * 插入字符串
40
- * @param offset 插入位置
41
- * @param text 待插入的字符串
42
- */
43
- insertData(offset: number, text: string): void;
44
- /**
45
- * 提取子串
46
- * @param offset 起始位置
47
- * @param count 字符数
48
- */
49
- substringData(offset: number, count: number): string;
50
- /**
51
- * 将文本子节点分裂为两部分
52
- * @param offset 分裂位置
53
- * @throws `RangeError` 错误的断开位置
54
- * @throws `Error` 没有父节点
55
- */
56
- splitText(offset: number): AstText;
57
- /**
58
- * @override
59
- * @param j 字符位置
60
- * @throws `RangeError` 超出文本长度范围
61
- */
62
- getRelativeIndex(j?: number): number;
63
- }
package/dist/lib/text.js DELETED
@@ -1,216 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AstText = void 0;
4
- const Parser = require("../index");
5
- const node_1 = require("./node");
6
- const errorSyntax = /https?:\/\/|\{+|\}+|\[{2,}|\[(?![^[]*\])|(?<=^|\])([^[]*?)\]+|\]{2,}|<\s*\/?([a-z]\w*)/giu, errorSyntaxUrl = /\{+|\}+|\[{2,}|\[(?![^[]*\])|(?<=^|\])([^[]*?)\]+|\]{2,}|<\s*\/?([a-z]\w*)/giu, disallowedTags = [
7
- 'html',
8
- 'base',
9
- 'head',
10
- 'style',
11
- 'title',
12
- 'body',
13
- 'menu',
14
- 'a',
15
- 'area',
16
- 'audio',
17
- 'img',
18
- 'map',
19
- 'track',
20
- 'video',
21
- 'embed',
22
- 'iframe',
23
- 'object',
24
- 'picture',
25
- 'source',
26
- 'canvas',
27
- 'script',
28
- 'col',
29
- 'colgroup',
30
- 'tbody',
31
- 'tfoot',
32
- 'thead',
33
- 'button',
34
- 'datalist',
35
- 'fieldset',
36
- 'form',
37
- 'input',
38
- 'label',
39
- 'legend',
40
- 'meter',
41
- 'optgroup',
42
- 'option',
43
- 'output',
44
- 'progress',
45
- 'select',
46
- 'textarea',
47
- 'details',
48
- 'dialog',
49
- 'slot',
50
- 'template',
51
- 'dir',
52
- 'frame',
53
- 'frameset',
54
- 'marquee',
55
- 'param',
56
- 'xmp',
57
- ];
58
- /** 文本节点 */
59
- class AstText extends node_1.AstNode {
60
- type = 'text';
61
- data;
62
- /* NOT FOR BROWSER */
63
- /** 文本长度 */
64
- get length() {
65
- return this.data.length;
66
- }
67
- /* NOT FOR BROWSER END */
68
- /** @param text 包含文本 */
69
- constructor(text) {
70
- super();
71
- Object.defineProperties(this, {
72
- data: { value: text, writable: false },
73
- childNodes: { enumerable: false, configurable: false },
74
- type: { enumerable: false, writable: false, configurable: false },
75
- });
76
- }
77
- /** @private */
78
- toString() {
79
- return this.data;
80
- }
81
- /** 可见部分 */
82
- text() {
83
- return this.data;
84
- }
85
- /**
86
- * Linter
87
- * @param start
88
- */
89
- lint(start = this.getAbsoluteIndex()) {
90
- const { data, parentNode, nextSibling, previousSibling } = this, type = parentNode?.type, name = parentNode?.name, nextType = nextSibling?.type, previousType = previousSibling?.type, errorRegex = type === 'free-ext-link' || type === 'ext-link-url' || type === 'image-parameter' && name === 'link'
91
- ? errorSyntaxUrl
92
- : errorSyntax, errors = [...data.matchAll(errorRegex)], { ext, html } = this.getRootNode().getAttribute('config');
93
- if (errors.length > 0) {
94
- const root = this.getRootNode(), { top, left } = root.posFromIndex(start), tags = new Set([ext, html, disallowedTags].flat(2));
95
- return errors
96
- .map(({ 0: error, 1: prefix, 2: tag, index }) => {
97
- if (prefix) {
98
- index += prefix.length;
99
- error = error.slice(prefix.length);
100
- }
101
- const startIndex = start + index, lines = data.slice(0, index).split('\n'), startLine = lines.length + top - 1, line = lines.at(-1), startCol = lines.length === 1 ? left + line.length : line.length, { 0: char, length } = error, endIndex = startIndex + length, end = char === '}' || char === ']' ? endIndex + 1 : startIndex + 49, rootStr = String(root), nextChar = rootStr[endIndex], previousChar = rootStr[startIndex - 1], severity = length > 1 && (char !== '<' || /[\s/>]/u.test(nextChar ?? ''))
102
- || char === '{' && (nextChar === char || previousChar === '-')
103
- || char === '}' && (previousChar === char || nextChar === '-')
104
- || char === '[' && (nextChar === char || type === 'ext-link-text'
105
- || !data.slice(index + 1).trim() && nextType === 'free-ext-link')
106
- || char === ']' && (previousChar === char
107
- || !data.slice(0, index).trim() && previousType === 'free-ext-link')
108
- ? 'error'
109
- : 'warning';
110
- return (char !== 'h' || index > 0) && (char !== '<' || tags.has(tag.toLowerCase())) && {
111
- message: Parser.msg('lonely "$1"', char === 'h' ? error : char),
112
- severity,
113
- startIndex,
114
- endIndex,
115
- startLine,
116
- endLine: startLine,
117
- startCol,
118
- endCol: startCol + length,
119
- excerpt: rootStr.slice(Math.max(0, end - 50), end),
120
- };
121
- }).filter(Boolean);
122
- }
123
- return [];
124
- }
125
- /**
126
- * 修改内容
127
- * @param text 新内容
128
- */
129
- #setData(text) {
130
- const { data } = this, e = new Event('text', { bubbles: true });
131
- this.setAttribute('data', text);
132
- if (data !== text) {
133
- this.dispatchEvent(e, { oldText: data, newText: text });
134
- }
135
- }
136
- /**
137
- * 替换字符串
138
- * @param text 替换的字符串
139
- */
140
- replaceData(text) {
141
- this.#setData(text);
142
- }
143
- /* NOT FOR BROWSER */
144
- /** 复制 */
145
- cloneNode() {
146
- return new AstText(this.data);
147
- }
148
- /**
149
- * 在后方添加字符串
150
- * @param text 添加的字符串
151
- */
152
- appendData(text) {
153
- this.#setData(this.data + text);
154
- }
155
- /**
156
- * 删减字符串
157
- * @param offset 起始位置
158
- * @param count 删减字符数
159
- */
160
- deleteData(offset, count) {
161
- this.#setData(this.data.slice(0, offset) + (offset < 0 && offset + count >= 0 ? '' : this.data.slice(offset + count)));
162
- }
163
- /**
164
- * 插入字符串
165
- * @param offset 插入位置
166
- * @param text 待插入的字符串
167
- */
168
- insertData(offset, text) {
169
- this.#setData(this.data.slice(0, offset) + text + this.data.slice(offset));
170
- }
171
- /**
172
- * 提取子串
173
- * @param offset 起始位置
174
- * @param count 字符数
175
- */
176
- substringData(offset, count) {
177
- return this.data.substr(offset, count);
178
- }
179
- /**
180
- * 将文本子节点分裂为两部分
181
- * @param offset 分裂位置
182
- * @throws `RangeError` 错误的断开位置
183
- * @throws `Error` 没有父节点
184
- */
185
- splitText(offset) {
186
- if (offset > this.length || offset < -this.length) {
187
- throw new RangeError(`错误的断开位置:${offset}`);
188
- }
189
- const { parentNode, data } = this;
190
- if (!parentNode) {
191
- throw new Error('待分裂的文本节点没有父节点!');
192
- }
193
- const newText = new AstText(data.slice(offset)), childNodes = [...parentNode.childNodes];
194
- this.setAttribute('data', data.slice(0, offset));
195
- childNodes.splice(childNodes.indexOf(this) + 1, 0, newText);
196
- newText.setAttribute('parentNode', parentNode);
197
- parentNode.setAttribute('childNodes', childNodes);
198
- return newText;
199
- }
200
- /**
201
- * @override
202
- * @param j 字符位置
203
- * @throws `RangeError` 超出文本长度范围
204
- */
205
- getRelativeIndex(j) {
206
- if (j === undefined) {
207
- return super.getRelativeIndex();
208
- }
209
- else if (j < 0 || j > this.length) {
210
- throw new RangeError(`超出文本长度范围!`);
211
- }
212
- return j;
213
- }
214
- }
215
- exports.AstText = AstText;
216
- Parser.classes['AstText'] = __filename;
@@ -1,20 +0,0 @@
1
- import * as Parser from '../index';
2
- /** MediaWiki页面标题对象 */
3
- export declare class Title {
4
- valid: boolean;
5
- ns: number;
6
- fragment: string | undefined;
7
- encoded: boolean;
8
- main: string;
9
- prefix: string;
10
- interwiki: string;
11
- /** 完整标题 */
12
- get title(): string;
13
- /**
14
- * @param title 标题(含或不含命名空间前缀)
15
- * @param defaultNs 命名空间
16
- * @param decode 是否需要解码
17
- * @param selfLink 是否允许selfLink
18
- */
19
- constructor(title: string, defaultNs?: number, config?: Parser.Config, decode?: boolean, selfLink?: boolean);
20
- }
package/dist/lib/title.js DELETED
@@ -1,108 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Title = void 0;
4
- const string_1 = require("../util/string");
5
- const Parser = require("../index");
6
- /** MediaWiki页面标题对象 */
7
- class Title {
8
- valid;
9
- ns;
10
- fragment;
11
- encoded = false;
12
- /* NOT FOR BROWSER */
13
- main;
14
- prefix;
15
- interwiki = '';
16
- /** @private */
17
- conversionTable = new Map();
18
- /** @private */
19
- redirects = new Map();
20
- /** 完整标题 */
21
- get title() {
22
- let title = `${this.interwiki && `${this.interwiki}:`}${this.prefix}${this.main.replaceAll(' ', '_')}`;
23
- const redirected = this.redirects.get(title);
24
- if (redirected) {
25
- return redirected;
26
- }
27
- this.autoConvert();
28
- title = `${this.interwiki && `${this.interwiki}:`}${this.prefix}${this.main.replaceAll(' ', '_')}`;
29
- return this.redirects.get(title) ?? title;
30
- }
31
- /* NOT FOR BROWSER END */
32
- /**
33
- * @param title 标题(含或不含命名空间前缀)
34
- * @param defaultNs 命名空间
35
- * @param decode 是否需要解码
36
- * @param selfLink 是否允许selfLink
37
- */
38
- constructor(title, defaultNs = 0, config = Parser.getConfig(), decode = false, selfLink = false) {
39
- const { namespaces, nsid } = config;
40
- let namespace = namespaces[defaultNs] ?? '';
41
- title = (0, string_1.decodeHtml)(title);
42
- if (decode && title.includes('%')) {
43
- try {
44
- const encoded = /%(?!21|3[ce]|5[bd]|7[b-d])[\da-f]{2}/iu.test(title);
45
- title = decodeURIComponent(title);
46
- this.encoded = encoded;
47
- }
48
- catch { }
49
- }
50
- title = title.replaceAll('_', ' ').trim();
51
- if (title.startsWith(':')) {
52
- namespace = '';
53
- title = title.slice(1).trim();
54
- }
55
- const iw = defaultNs ? null : Parser.isInterwiki(title, config);
56
- if (iw) {
57
- this.interwiki = iw[1].toLowerCase();
58
- title = title.slice(iw[0].length);
59
- }
60
- const m = title.split(':');
61
- if (m.length > 1) {
62
- const ns = nsid[m[0].trim().toLowerCase()], id = ns === undefined ? undefined : namespaces[ns];
63
- if (id !== undefined) {
64
- namespace = id;
65
- title = m.slice(1).join(':').trim();
66
- }
67
- }
68
- this.ns = nsid[namespace.toLowerCase()];
69
- const i = title.indexOf('#');
70
- let fragment;
71
- if (i !== -1) {
72
- fragment = title.slice(i + 1).trimEnd();
73
- if (fragment.includes('%')) {
74
- try {
75
- fragment = decodeURIComponent(fragment);
76
- }
77
- catch { }
78
- }
79
- else if (fragment.includes('.')) {
80
- try {
81
- fragment = decodeURIComponent(fragment.replaceAll('.', '%'));
82
- }
83
- catch { }
84
- }
85
- title = title.slice(0, i).trim();
86
- }
87
- this.valid = Boolean(title || selfLink && fragment !== undefined || this.interwiki)
88
- && !/\0\d+[eh!+-]\x7F|[<>[\]{}|]|%[\da-f]{2}/iu.test(title);
89
- this.fragment = fragment;
90
- this.main = title && `${title[0].toUpperCase()}${title.slice(1)}`;
91
- this.prefix = `${namespace}${namespace && ':'}`;
92
- }
93
- /* NOT FOR BROWSER */
94
- /** @private */
95
- toString() {
96
- return `${this.title}${this.fragment === undefined ? '' : `#${this.fragment}`}`;
97
- }
98
- /** @private */
99
- autoConvert() {
100
- const { conversionTable } = this;
101
- if (conversionTable.size > 0) {
102
- const regex = new RegExp([...conversionTable.keys()].sort().reverse().map(string_1.escapeRegExp).join('|'), 'gu');
103
- this.main = this.main.replace(regex, p => conversionTable.get(p));
104
- }
105
- }
106
- }
107
- exports.Title = Title;
108
- Parser.classes['Title'] = __filename;
@@ -1,92 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.attributesParent = void 0;
4
- const Parser = require("../index");
5
- /**
6
- * 子节点含有AttributesToken的类
7
- * @param constructor 基类
8
- * @param i AttributesToken子节点的位置
9
- */
10
- const attributesParent = (constructor, i = 0) => {
11
- /** 子节点含有AttributesToken的类 */
12
- class AttributesParent extends constructor {
13
- /** AttributesToken子节点 */
14
- get #attributesChild() {
15
- return this.childNodes.at(i);
16
- }
17
- /** getAttrs()方法的getter写法 */
18
- get attributes() {
19
- return this.#attributesChild.attributes;
20
- }
21
- /** 以字符串表示的class属性 */
22
- get className() {
23
- return this.#attributesChild.className;
24
- }
25
- set className(className) {
26
- this.#attributesChild.className = className;
27
- }
28
- /** 以Set表示的class属性 */
29
- get classList() {
30
- return this.#attributesChild.classList;
31
- }
32
- /** id属性 */
33
- get id() {
34
- return this.#attributesChild.id;
35
- }
36
- set id(id) {
37
- this.#attributesChild.id = id;
38
- }
39
- /**
40
- * AttributesToken子节点是否具有某属性
41
- * @param key 属性键
42
- */
43
- hasAttr(key) {
44
- return this.#attributesChild.hasAttr(key);
45
- }
46
- /**
47
- * 获取AttributesToken子节点的属性
48
- * @param key 属性键
49
- */
50
- getAttr(key) {
51
- return this.#attributesChild.getAttr(key);
52
- }
53
- /** 列举AttributesToken子节点的属性键 */
54
- getAttrNames() {
55
- return this.#attributesChild.getAttrNames();
56
- }
57
- /** AttributesToken子节点是否具有任意属性 */
58
- hasAttrs() {
59
- return this.#attributesChild.hasAttrs();
60
- }
61
- /** 获取AttributesToken子节点的全部标签属性 */
62
- getAttrs() {
63
- return this.#attributesChild.getAttrs();
64
- }
65
- /**
66
- * 对AttributesToken子节点设置属性
67
- * @param key 属性键
68
- * @param value 属性值
69
- */
70
- setAttr(key, value) {
71
- this.#attributesChild.setAttr(key, value);
72
- }
73
- /**
74
- * 移除AttributesToken子节点的某属性
75
- * @param key 属性键
76
- */
77
- removeAttr(key) {
78
- this.#attributesChild.removeAttr(key);
79
- }
80
- /**
81
- * 开关AttributesToken子节点的某属性
82
- * @param key 属性键
83
- * @param force 强制开启或关闭
84
- */
85
- toggleAttr(key, force) {
86
- this.#attributesChild.toggleAttr(key, force);
87
- }
88
- }
89
- return AttributesParent;
90
- };
91
- exports.attributesParent = attributesParent;
92
- Parser.mixins['attributesParent'] = __filename;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fixed = void 0;
4
- const Parser = require("../index");
5
- /**
6
- * 不可增删子节点的类
7
- * @param constructor 基类
8
- */
9
- const fixed = (constructor) => {
10
- /** 不可增删子节点的类 */
11
- class FixedToken extends constructor {
12
- static fixed = true;
13
- /**
14
- * @override
15
- * @throws `Error` 不可用
16
- */
17
- removeAt() {
18
- throw new Error(`${this.constructor.name} 不可删除元素!`);
19
- }
20
- /** @ignore */
21
- insertAt(token, i = this.length) {
22
- if (Parser.running) {
23
- return super.insertAt(token, i);
24
- }
25
- throw new Error(`${this.constructor.name} 不可插入元素!`);
26
- }
27
- }
28
- return FixedToken;
29
- };
30
- exports.fixed = fixed;
31
- Parser.mixins['fixed'] = __filename;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hidden = void 0;
4
- const Parser = require("../index");
5
- /**
6
- * 解析后不可见的类
7
- * @param constructor 基类
8
- */
9
- const hidden = (constructor) => {
10
- /** 解析后不可见的类 */
11
- class AnyHiddenToken extends constructor {
12
- static hidden = true;
13
- /** 没有可见部分 */
14
- // eslint-disable-next-line class-methods-use-this
15
- text() {
16
- return '';
17
- }
18
- }
19
- return AnyHiddenToken;
20
- };
21
- exports.hidden = hidden;
22
- Parser.mixins['hidden'] = __filename;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.singleLine = void 0;
4
- const Parser = require("../index");
5
- /**
6
- * 不可包含换行符的类
7
- * @param constructor 基类
8
- */
9
- const singleLine = (constructor) => {
10
- /** 不可包含换行符的类 */
11
- class SingleLineToken extends constructor {
12
- /** @private */
13
- toString(omit) {
14
- return super.toString(omit).replaceAll('\n', ' ');
15
- }
16
- /** @override */
17
- text() {
18
- return super.text().replaceAll('\n', ' ');
19
- }
20
- }
21
- Object.defineProperty(SingleLineToken, 'name', { value: `SingleLine${constructor.name}` });
22
- return SingleLineToken;
23
- };
24
- exports.singleLine = singleLine;
25
- Parser.mixins['singleLine'] = __filename;
package/dist/mixin/sol.js DELETED
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sol = void 0;
4
- const Parser = require("../index");
5
- /**
6
- * 只能位于行首的类
7
- * @param constructor 基类
8
- */
9
- const sol = (constructor) => {
10
- /** 只能位于行首的类 */
11
- class SolToken extends constructor {
12
- /** 是否可以视为root节点 */
13
- #isRoot() {
14
- const { parentNode, type } = this;
15
- return parentNode?.type === 'root'
16
- || type !== 'heading' && parentNode?.type === 'ext-inner' && parentNode.name === 'poem';
17
- }
18
- /** 在前方插入newline */
19
- prependNewLine() {
20
- const { previousVisibleSibling } = this;
21
- return (previousVisibleSibling && !String(previousVisibleSibling).endsWith('\n')) ?? !this.#isRoot()
22
- ? '\n'
23
- : '';
24
- }
25
- /** @private */
26
- toString(omit) {
27
- return omit && this.matchesTypes(omit)
28
- ? ''
29
- : `${this.prependNewLine()}${super.toString(omit)}`;
30
- }
31
- /** @private */
32
- getPadding() {
33
- return this.prependNewLine().length;
34
- }
35
- /** @override */
36
- text() {
37
- return `${this.prependNewLine()}${super.text()}`;
38
- }
39
- }
40
- return SolToken;
41
- };
42
- exports.sol = sol;
43
- Parser.mixins['sol'] = __filename;
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.syntax = void 0;
4
- const debug_1 = require("../util/debug");
5
- const string_1 = require("../util/string");
6
- const Parser = require("../index");
7
- /**
8
- * 满足特定语法格式的Token
9
- * @param constructor 基类
10
- * @param pattern 语法正则
11
- */
12
- const syntax = (constructor, pattern) => {
13
- /** 满足特定语法格式的Token */
14
- class SyntaxToken extends constructor {
15
- #pattern = pattern;
16
- /** @private */
17
- afterBuild() {
18
- const /** @implements */ syntaxListener = (e, data) => {
19
- if (!Parser.running && !this.#pattern.test(this.text())) {
20
- (0, debug_1.undo)(e, data);
21
- Parser.error(`不可修改 ${this.constructor.name} 的语法!`, this.#pattern);
22
- throw new Error(`不可修改 ${this.constructor.name} 的语法!`);
23
- }
24
- };
25
- this.addEventListener(['remove', 'insert', 'replace', 'text'], syntaxListener);
26
- }
27
- /** @private */
28
- getAttribute(key) {
29
- return key === 'pattern' ? this.#pattern : super.getAttribute(key);
30
- }
31
- /** @private */
32
- setAttribute(key, value) {
33
- if (key === 'pattern') {
34
- this.#pattern = value;
35
- }
36
- else {
37
- super.setAttribute(key, value);
38
- }
39
- }
40
- /**
41
- * @override
42
- * @param elements 待替换的子节点
43
- */
44
- replaceChildren(...elements) {
45
- if (Parser.running || this.#pattern.test((0, string_1.text)(elements))) {
46
- Parser.run(() => {
47
- super.replaceChildren(...elements);
48
- });
49
- }
50
- }
51
- }
52
- return SyntaxToken;
53
- };
54
- exports.syntax = syntax;
55
- Parser.mixins['syntax'] = __filename;