wikiparser-node 0.11.0 → 1.0.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 (179) hide show
  1. package/README.md +10 -9
  2. package/bundle/bundle.min.js +37 -0
  3. package/config/llwiki.json +1 -35
  4. package/config/minimum.json +136 -0
  5. package/config/moegirl.json +1 -44
  6. package/config/zhwiki.json +1 -466
  7. package/extensions/dist/base.js +105 -0
  8. package/extensions/dist/editor.js +172 -0
  9. package/extensions/dist/highlight.js +46 -0
  10. package/extensions/dist/lint.js +43 -0
  11. package/extensions/editor.css +63 -0
  12. package/extensions/ui.css +119 -0
  13. package/i18n/zh-hans.json +1 -0
  14. package/i18n/zh-hant.json +1 -0
  15. package/package.json +38 -31
  16. package/config/.schema.json +0 -134
  17. package/dist/index.d.ts +0 -114
  18. package/dist/lib/element.d.ts +0 -162
  19. package/dist/lib/node.d.ts +0 -291
  20. package/dist/lib/ranges.d.ts +0 -37
  21. package/dist/lib/text.d.ts +0 -64
  22. package/dist/lib/title.d.ts +0 -21
  23. package/dist/mixin/attributeParent.d.ts +0 -9
  24. package/dist/mixin/fixedToken.d.ts +0 -8
  25. package/dist/mixin/hidden.d.ts +0 -8
  26. package/dist/mixin/singleLine.d.ts +0 -8
  27. package/dist/mixin/sol.d.ts +0 -8
  28. package/dist/parser/brackets.d.ts +0 -12
  29. package/dist/parser/commentAndExt.d.ts +0 -8
  30. package/dist/parser/converter.d.ts +0 -7
  31. package/dist/parser/externalLinks.d.ts +0 -7
  32. package/dist/parser/hrAndDoubleUnderscore.d.ts +0 -11
  33. package/dist/parser/html.d.ts +0 -7
  34. package/dist/parser/links.d.ts +0 -7
  35. package/dist/parser/list.d.ts +0 -7
  36. package/dist/parser/magicLinks.d.ts +0 -7
  37. package/dist/parser/quotes.d.ts +0 -7
  38. package/dist/parser/selector.d.ts +0 -12
  39. package/dist/parser/table.d.ts +0 -11
  40. package/dist/src/arg.d.ts +0 -54
  41. package/dist/src/atom/hidden.d.ts +0 -5
  42. package/dist/src/atom/index.d.ts +0 -15
  43. package/dist/src/attribute.d.ts +0 -65
  44. package/dist/src/attributes.d.ts +0 -112
  45. package/dist/src/charinsert.d.ts +0 -32
  46. package/dist/src/converter.d.ts +0 -103
  47. package/dist/src/converterFlags.d.ts +0 -83
  48. package/dist/src/converterRule.d.ts +0 -75
  49. package/dist/src/extLink.d.ts +0 -62
  50. package/dist/src/gallery.d.ts +0 -33
  51. package/dist/src/hasNowiki/index.d.ts +0 -14
  52. package/dist/src/hasNowiki/pre.d.ts +0 -13
  53. package/dist/src/heading.d.ts +0 -44
  54. package/dist/src/html.d.ts +0 -56
  55. package/dist/src/imageParameter.d.ts +0 -65
  56. package/dist/src/imagemap.d.ts +0 -37
  57. package/dist/src/imagemapLink.d.ts +0 -21
  58. package/dist/src/index.d.ts +0 -186
  59. package/dist/src/link/category.d.ts +0 -16
  60. package/dist/src/link/file.d.ts +0 -85
  61. package/dist/src/link/galleryImage.d.ts +0 -15
  62. package/dist/src/link/index.d.ts +0 -88
  63. package/dist/src/magicLink.d.ts +0 -36
  64. package/dist/src/nested/choose.d.ts +0 -13
  65. package/dist/src/nested/combobox.d.ts +0 -13
  66. package/dist/src/nested/index.d.ts +0 -18
  67. package/dist/src/nested/references.d.ts +0 -13
  68. package/dist/src/nowiki/comment.d.ts +0 -31
  69. package/dist/src/nowiki/dd.d.ts +0 -17
  70. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -22
  71. package/dist/src/nowiki/hr.d.ts +0 -13
  72. package/dist/src/nowiki/index.d.ts +0 -27
  73. package/dist/src/nowiki/list.d.ts +0 -8
  74. package/dist/src/nowiki/noinclude.d.ts +0 -8
  75. package/dist/src/nowiki/quote.d.ts +0 -13
  76. package/dist/src/onlyinclude.d.ts +0 -24
  77. package/dist/src/paramTag/index.d.ts +0 -29
  78. package/dist/src/paramTag/inputbox.d.ts +0 -8
  79. package/dist/src/parameter.d.ts +0 -75
  80. package/dist/src/syntax.d.ts +0 -20
  81. package/dist/src/table/index.d.ts +0 -273
  82. package/dist/src/table/td.d.ts +0 -100
  83. package/dist/src/table/tr.d.ts +0 -91
  84. package/dist/src/tagPair/ext.d.ts +0 -18
  85. package/dist/src/tagPair/include.d.ts +0 -25
  86. package/dist/src/tagPair/index.d.ts +0 -41
  87. package/dist/src/transclude.d.ts +0 -199
  88. package/dist/tool/index.d.ts +0 -420
  89. package/dist/util/base.d.ts +0 -10
  90. package/dist/util/debug.d.ts +0 -20
  91. package/dist/util/diff.d.ts +0 -8
  92. package/dist/util/lint.d.ts +0 -28
  93. package/dist/util/string.d.ts +0 -55
  94. package/index.js +0 -333
  95. package/lib/element.js +0 -618
  96. package/lib/node.js +0 -730
  97. package/lib/ranges.js +0 -130
  98. package/lib/text.js +0 -265
  99. package/lib/title.js +0 -83
  100. package/mixin/attributeParent.js +0 -117
  101. package/mixin/fixedToken.js +0 -40
  102. package/mixin/hidden.js +0 -21
  103. package/mixin/singleLine.js +0 -31
  104. package/mixin/sol.js +0 -54
  105. package/parser/brackets.js +0 -128
  106. package/parser/commentAndExt.js +0 -62
  107. package/parser/converter.js +0 -46
  108. package/parser/externalLinks.js +0 -33
  109. package/parser/hrAndDoubleUnderscore.js +0 -49
  110. package/parser/html.js +0 -42
  111. package/parser/links.js +0 -94
  112. package/parser/list.js +0 -59
  113. package/parser/magicLinks.js +0 -41
  114. package/parser/quotes.js +0 -64
  115. package/parser/selector.js +0 -180
  116. package/parser/table.js +0 -114
  117. package/src/arg.js +0 -207
  118. package/src/atom/hidden.js +0 -13
  119. package/src/atom/index.js +0 -43
  120. package/src/attribute.js +0 -472
  121. package/src/attributes.js +0 -453
  122. package/src/charinsert.js +0 -97
  123. package/src/converter.js +0 -176
  124. package/src/converterFlags.js +0 -284
  125. package/src/converterRule.js +0 -256
  126. package/src/extLink.js +0 -180
  127. package/src/gallery.js +0 -149
  128. package/src/hasNowiki/index.js +0 -44
  129. package/src/hasNowiki/pre.js +0 -40
  130. package/src/heading.js +0 -134
  131. package/src/html.js +0 -254
  132. package/src/imageParameter.js +0 -303
  133. package/src/imagemap.js +0 -199
  134. package/src/imagemapLink.js +0 -41
  135. package/src/index.js +0 -938
  136. package/src/link/category.js +0 -44
  137. package/src/link/file.js +0 -287
  138. package/src/link/galleryImage.js +0 -120
  139. package/src/link/index.js +0 -388
  140. package/src/magicLink.js +0 -151
  141. package/src/nested/choose.js +0 -24
  142. package/src/nested/combobox.js +0 -23
  143. package/src/nested/index.js +0 -96
  144. package/src/nested/references.js +0 -23
  145. package/src/nowiki/comment.js +0 -71
  146. package/src/nowiki/dd.js +0 -59
  147. package/src/nowiki/doubleUnderscore.js +0 -56
  148. package/src/nowiki/hr.js +0 -41
  149. package/src/nowiki/index.js +0 -56
  150. package/src/nowiki/list.js +0 -16
  151. package/src/nowiki/noinclude.js +0 -28
  152. package/src/nowiki/quote.js +0 -69
  153. package/src/onlyinclude.js +0 -64
  154. package/src/paramTag/index.js +0 -89
  155. package/src/paramTag/inputbox.js +0 -35
  156. package/src/parameter.js +0 -239
  157. package/src/syntax.js +0 -91
  158. package/src/table/index.js +0 -985
  159. package/src/table/td.js +0 -343
  160. package/src/table/tr.js +0 -319
  161. package/src/tagPair/ext.js +0 -146
  162. package/src/tagPair/include.js +0 -50
  163. package/src/tagPair/index.js +0 -131
  164. package/src/transclude.js +0 -843
  165. package/tool/index.js +0 -1209
  166. package/typings/api.d.ts +0 -9
  167. package/typings/array.d.ts +0 -29
  168. package/typings/event.d.ts +0 -22
  169. package/typings/index.d.ts +0 -118
  170. package/typings/node.d.ts +0 -35
  171. package/typings/parser.d.ts +0 -12
  172. package/typings/table.d.ts +0 -10
  173. package/typings/token.d.ts +0 -31
  174. package/typings/tool.d.ts +0 -6
  175. package/util/base.js +0 -17
  176. package/util/debug.js +0 -73
  177. package/util/diff.js +0 -76
  178. package/util/lint.js +0 -57
  179. package/util/string.js +0 -126
@@ -1,146 +0,0 @@
1
- 'use strict';
2
-
3
- const {generateForSelf} = require('../../util/lint'),
4
- attributeParent = require('../../mixin/attributeParent'),
5
- Parser = require('../..'),
6
- Token = require('..'),
7
- TagPairToken = require('.'),
8
- AttributesToken = require('../attributes');
9
-
10
- /**
11
- * 扩展标签
12
- * @classdesc `{childNodes: [AttributesToken, NowikiToken|Token]}`
13
- */
14
- class ExtToken extends attributeParent(TagPairToken) {
15
- type = 'ext';
16
- closed = true;
17
-
18
- /**
19
- * @param {string} name 标签名
20
- * @param {string} attr 标签属性
21
- * @param {string} inner 内部wikitext
22
- * @param {string|undefined} closed 是否封闭
23
- * @param {import('../../typings/token').accum} accum
24
- */
25
- constructor(name, attr = '', inner = '', closed = undefined, config = Parser.getConfig(), accum = []) {
26
- attr = !attr || attr.trimStart() !== attr ? attr : ` ${attr}`;
27
- const lcName = name.toLowerCase(),
28
- attrToken = new AttributesToken(attr, 'ext-attrs', lcName, config, accum),
29
- /** @type {import('../../typings/token').ParserConfig} */
30
- newConfig = {...config, excludes: [...config.excludes]},
31
- ext = new Set(newConfig.ext);
32
- let /** @type {Token} */ innerToken;
33
- ext.delete(lcName);
34
- newConfig.ext = [...ext];
35
- switch (lcName) {
36
- case 'tab':
37
- ext.delete('tabs');
38
- newConfig.ext = [...ext];
39
- // fall through
40
- case 'indicator':
41
- case 'poem':
42
- case 'ref':
43
- case 'option':
44
- case 'combooption':
45
- case 'tabs':
46
- case 'poll':
47
- case 'seo':
48
- if (lcName === 'poem') {
49
- newConfig.excludes.push('heading');
50
- }
51
- innerToken = new Token(inner, newConfig, true, accum);
52
- break;
53
- case 'gallery': {
54
- const GalleryToken = require('../gallery');
55
- innerToken = new GalleryToken(inner, newConfig, accum);
56
- break;
57
- }
58
- case 'pre': {
59
- const PreToken = require('../hasNowiki/pre');
60
- innerToken = new PreToken(inner, newConfig, accum);
61
- break;
62
- }
63
- case 'charinsert': {
64
- const CharinsertToken = require('../charinsert');
65
- innerToken = new CharinsertToken(inner, newConfig, accum);
66
- break;
67
- }
68
- case 'references': {
69
- const ReferencesToken = require('../nested/references');
70
- innerToken = new ReferencesToken(inner, newConfig, accum);
71
- break;
72
- }
73
- case 'choose': {
74
- const ChooseToken = require('../nested/choose');
75
- innerToken = new ChooseToken(inner, newConfig, accum);
76
- break;
77
- }
78
- case 'combobox': {
79
- const ComboboxToken = require('../nested/combobox');
80
- innerToken = new ComboboxToken(inner, newConfig, accum);
81
- break;
82
- }
83
- case 'imagemap': {
84
- const ImagemapToken = require('../imagemap');
85
- innerToken = new ImagemapToken(inner, config, accum);
86
- break;
87
- }
88
- case 'dynamicpagelist': {
89
- const ParamTagToken = require('../paramTag');
90
- innerToken = new ParamTagToken(inner, newConfig, accum);
91
- break;
92
- }
93
- case 'inputbox': {
94
- newConfig.excludes.push('heading');
95
- const InputboxToken = require('../paramTag/inputbox');
96
- innerToken = new InputboxToken(inner, newConfig, accum);
97
- break;
98
- }
99
- // 更多定制扩展的代码示例:
100
- // ```
101
- // case 'extensionName': {
102
- // const ExtensionToken = require('../extension');
103
- // innerToken = new ExtensionToken(inner, newConfig, accum);
104
- // break;
105
- // }
106
- // ```
107
- default: {
108
- const NowikiToken = require('../nowiki');
109
- innerToken = new NowikiToken(inner, config);
110
- }
111
- }
112
- innerToken.setAttribute('name', lcName).type = 'ext-inner';
113
- super(name, attrToken, innerToken, closed, config, accum);
114
- }
115
-
116
- /**
117
- * @override
118
- * @param {number} start 起始位置
119
- */
120
- lint(start = this.getAbsoluteIndex()) {
121
- const errors = super.lint(start);
122
- if (this.name !== 'nowiki' && this.closest('html-attrs, table-attrs')) {
123
- const root = this.getRootNode(),
124
- excerpt = String(root).slice(Math.max(0, start - 25), start + 25),
125
- rect = {start, ...root.posFromIndex(start)};
126
- errors.push({...generateForSelf(this, rect, 'extension tag in HTML tag attributes'), excerpt});
127
- }
128
- return errors;
129
- }
130
-
131
- /** @override */
132
- cloneNode() {
133
- const inner = this.lastChild.cloneNode(),
134
- tags = this.getAttribute('tags'),
135
- config = this.getAttribute('config'),
136
- attr = String(this.firstChild);
137
- return Parser.run(() => {
138
- const token = new ExtToken(tags[0], attr, '', this.selfClosing ? undefined : tags[1], config);
139
- token.lastChild.safeReplaceWith(inner);
140
- return token;
141
- });
142
- }
143
- }
144
-
145
- Parser.classes.ExtToken = __filename;
146
- module.exports = ExtToken;
@@ -1,50 +0,0 @@
1
- 'use strict';
2
-
3
- const hidden = require('../../mixin/hidden'),
4
- Parser = require('../..'),
5
- TagPairToken = require('.');
6
-
7
- /**
8
- * `<includeonly>`或`<noinclude>`
9
- * @classdesc `{childNodes: [AstText, AstText]}`
10
- */
11
- class IncludeToken extends hidden(TagPairToken) {
12
- type = 'include';
13
-
14
- /**
15
- * @param {string} name 标签名
16
- * @param {string} attr 标签属性
17
- * @param {string|undefined} inner 内部wikitext
18
- * @param {string|undefined} closed 是否封闭
19
- * @param {import('../../typings/token').accum} accum
20
- */
21
- constructor(name, attr = '', inner = undefined, closed = undefined, config = Parser.getConfig(), accum = []) {
22
- super(name, attr, inner ?? '', inner === undefined ? closed : closed ?? '', config, accum);
23
- }
24
-
25
- /** @override */
26
- cloneNode() {
27
- const tags = this.getAttribute('tags'),
28
- config = this.getAttribute('config'),
29
- inner = this.selfClosing ? undefined : String(this.lastChild),
30
- closing = this.selfClosing || !this.closed ? undefined : tags[1],
31
- token = Parser.run(() => new IncludeToken(tags[0], String(this.firstChild), inner, closing, config));
32
- return token;
33
- }
34
-
35
- /**
36
- * @override
37
- * @param {string} str 新文本
38
- */
39
- setText(str) {
40
- return super.setText(str, 1);
41
- }
42
-
43
- /** 清除标签属性 */
44
- removeAttr() {
45
- super.setText('', 0);
46
- }
47
- }
48
-
49
- Parser.classes.IncludeToken = __filename;
50
- module.exports = IncludeToken;
@@ -1,131 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * @template T
5
- * @typedef {import('../../typings/node').TokenAttribute<T>} TokenAttribute
6
- */
7
-
8
- const Parser = require('../..'),
9
- fixedToken = require('../../mixin/fixedToken'),
10
- Token = require('..');
11
-
12
- /**
13
- * 成对标签
14
- * @classdesc `{childNodes: [AstText|AttributesToken, AstText|Token]}`
15
- */
16
- class TagPairToken extends fixedToken(Token) {
17
- #selfClosing;
18
- #closed;
19
- #tags;
20
-
21
- /** getter */
22
- get closed() {
23
- return this.#closed;
24
- }
25
-
26
- set closed(value) {
27
- this.#closed ||= Boolean(value);
28
- }
29
-
30
- /** getter */
31
- get selfClosing() {
32
- return this.#selfClosing;
33
- }
34
-
35
- set selfClosing(value) {
36
- value = Boolean(value);
37
- if (value !== this.#selfClosing && this.lastChild.text()) {
38
- Parser.warn(`<${this.name}>标签内部的${value ? '文本将被隐藏' : '原有文本将再次可见'}!`);
39
- }
40
- this.#selfClosing = value;
41
- }
42
-
43
- /** 内部wikitext */
44
- get innerText() {
45
- return this.#selfClosing ? undefined : this.lastChild.text();
46
- }
47
-
48
- /**
49
- * @param {string} name 标签名
50
- * @param {string|Token} attr 标签属性
51
- * @param {string|Token} inner 内部wikitext
52
- * @param {string|undefined} closed 是否封闭;约定`undefined`表示自闭合,`''`表示未闭合
53
- * @param {import('../../typings/token').accum} accum
54
- */
55
- constructor(name, attr, inner, closed, config = Parser.getConfig(), accum = []) {
56
- super(undefined, config, true);
57
- this.setAttribute('name', name.toLowerCase());
58
- this.#tags = [name, closed || name];
59
- this.#selfClosing = closed === undefined;
60
- this.#closed = closed !== '';
61
- this.append(attr, inner);
62
- let index = accum.indexOf(attr);
63
- if (index === -1) {
64
- index = accum.indexOf(inner);
65
- }
66
- if (index === -1) {
67
- index = Infinity;
68
- }
69
- accum.splice(index, 0, this);
70
- }
71
-
72
- /**
73
- * @override
74
- * @param {string} selector
75
- */
76
- toString(selector) {
77
- const {firstChild, lastChild, nextSibling, name} = this,
78
- [opening, closing] = this.#tags;
79
- if (selector && this.matches(selector)) {
80
- return '';
81
- } else if (!this.#closed && nextSibling) {
82
- Parser.error(`自动闭合 <${name}>`, lastChild);
83
- this.#closed = true;
84
- }
85
- return this.#selfClosing
86
- ? `<${opening}${String(firstChild)}/>`
87
- : `<${opening}${String(firstChild)}>${String(lastChild)}${this.#closed ? `</${closing}>` : ''}`;
88
- }
89
-
90
- /**
91
- * @override
92
- * @returns {string}
93
- */
94
- text() {
95
- const [opening, closing] = this.#tags;
96
- return this.#selfClosing
97
- ? `<${opening}${this.firstChild.text()}/>`
98
- : `<${opening}${super.text('>')}${this.#closed ? `</${closing}>` : ''}`;
99
- }
100
-
101
- /** @override */
102
- getPadding() {
103
- return this.#tags[0].length + 1;
104
- }
105
-
106
- /** @override */
107
- getGaps() {
108
- return 1;
109
- }
110
-
111
- /** @override */
112
- print() {
113
- const [opening, closing] = this.#tags;
114
- return super.print(this.#selfClosing
115
- ? {pre: `&lt;${opening}`, post: '/&gt;'}
116
- : {pre: `&lt;${opening}`, sep: '&gt;', post: this.#closed ? `&lt;/${closing}&gt;` : ''});
117
- }
118
-
119
- /**
120
- * @override
121
- * @template {string} T
122
- * @param {T} key 属性键
123
- * @returns {TokenAttribute<T>}
124
- */
125
- getAttribute(key) {
126
- return key === 'tags' ? [...this.#tags] : super.getAttribute(key);
127
- }
128
- }
129
-
130
- Parser.classes.TagPairToken = __filename;
131
- module.exports = TagPairToken;