wikiparser-node 0.3.1 → 0.5.0

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 (80) hide show
  1. package/README.md +1 -1
  2. package/config/default.json +13 -17
  3. package/config/llwiki.json +11 -79
  4. package/config/moegirl.json +7 -1
  5. package/config/zhwiki.json +1269 -0
  6. package/index.js +130 -97
  7. package/lib/element.js +410 -518
  8. package/lib/node.js +493 -115
  9. package/lib/ranges.js +27 -19
  10. package/lib/text.js +175 -0
  11. package/lib/title.js +14 -6
  12. package/mixin/attributeParent.js +70 -24
  13. package/mixin/fixedToken.js +18 -10
  14. package/mixin/hidden.js +6 -4
  15. package/mixin/sol.js +39 -12
  16. package/package.json +17 -4
  17. package/parser/brackets.js +18 -18
  18. package/parser/commentAndExt.js +16 -14
  19. package/parser/converter.js +14 -13
  20. package/parser/externalLinks.js +12 -11
  21. package/parser/hrAndDoubleUnderscore.js +24 -14
  22. package/parser/html.js +8 -7
  23. package/parser/links.js +13 -13
  24. package/parser/list.js +12 -11
  25. package/parser/magicLinks.js +11 -10
  26. package/parser/quotes.js +6 -5
  27. package/parser/selector.js +175 -0
  28. package/parser/table.js +31 -24
  29. package/src/arg.js +91 -43
  30. package/src/atom/hidden.js +5 -2
  31. package/src/atom/index.js +17 -9
  32. package/src/attribute.js +210 -101
  33. package/src/converter.js +78 -43
  34. package/src/converterFlags.js +104 -45
  35. package/src/converterRule.js +136 -78
  36. package/src/extLink.js +81 -27
  37. package/src/gallery.js +63 -20
  38. package/src/heading.js +58 -20
  39. package/src/html.js +138 -48
  40. package/src/imageParameter.js +93 -58
  41. package/src/index.js +314 -186
  42. package/src/link/category.js +22 -54
  43. package/src/link/file.js +83 -32
  44. package/src/link/galleryImage.js +21 -7
  45. package/src/link/index.js +170 -81
  46. package/src/magicLink.js +64 -14
  47. package/src/nowiki/comment.js +36 -10
  48. package/src/nowiki/dd.js +37 -22
  49. package/src/nowiki/doubleUnderscore.js +21 -7
  50. package/src/nowiki/hr.js +11 -7
  51. package/src/nowiki/index.js +16 -9
  52. package/src/nowiki/list.js +2 -2
  53. package/src/nowiki/noinclude.js +8 -4
  54. package/src/nowiki/quote.js +38 -7
  55. package/src/onlyinclude.js +24 -7
  56. package/src/parameter.js +102 -62
  57. package/src/syntax.js +23 -20
  58. package/src/table/index.js +282 -174
  59. package/src/table/td.js +112 -61
  60. package/src/table/tr.js +135 -74
  61. package/src/tagPair/ext.js +30 -23
  62. package/src/tagPair/include.js +26 -11
  63. package/src/tagPair/index.js +72 -29
  64. package/src/transclude.js +235 -127
  65. package/tool/index.js +42 -32
  66. package/util/debug.js +21 -18
  67. package/util/diff.js +76 -0
  68. package/util/lint.js +40 -0
  69. package/util/string.js +56 -26
  70. package/.eslintrc.json +0 -319
  71. package/errors/README +0 -1
  72. package/jsconfig.json +0 -7
  73. package/printed/README +0 -1
  74. package/typings/element.d.ts +0 -28
  75. package/typings/index.d.ts +0 -52
  76. package/typings/node.d.ts +0 -23
  77. package/typings/parser.d.ts +0 -9
  78. package/typings/table.d.ts +0 -14
  79. package/typings/token.d.ts +0 -22
  80. package/typings/tool.d.ts +0 -10
package/.eslintrc.json DELETED
@@ -1,319 +0,0 @@
1
- {
2
- "env": {
3
- "node": true,
4
- "es2021": true
5
- },
6
- "plugins": [
7
- "promise",
8
- "regexp"
9
- ],
10
- "extends": [
11
- "eslint:recommended",
12
- "plugin:promise/recommended",
13
- "plugin:n/recommended-script",
14
- "plugin:regexp/recommended"
15
- ],
16
- "parserOptions": {
17
- "ecmaVersion": 13
18
- },
19
- "rules": {
20
- "array-callback-return": [
21
- 2,
22
- {
23
- "checkForEach": true
24
- }
25
- ],
26
- "no-await-in-loop": 2,
27
- "no-constant-binary-expression": 2,
28
- "no-constructor-return": 2,
29
- "no-fallthrough": 1,
30
- "no-promise-executor-return": 2,
31
- "no-self-compare": 2,
32
- "no-template-curly-in-string": 2,
33
- "no-undef": [
34
- 2,
35
- {
36
- "typeof": true
37
- }
38
- ],
39
- "no-unmodified-loop-condition": 2,
40
- "no-unreachable-loop": 2,
41
- "no-unsafe-negation": [
42
- 2,
43
- {
44
- "enforceForOrderingRelations": true
45
- }
46
- ],
47
- "no-unsafe-optional-chaining": [
48
- 2,
49
- {
50
- "disallowArithmeticOperators": true
51
- }
52
- ],
53
- "no-unused-vars": [
54
- 2,
55
- {
56
- "varsIgnorePattern": "AstNode|AstElement|[a-zA-Z]*Token",
57
- "ignoreRestSiblings": true
58
- }
59
- ],
60
- "no-use-before-define": [
61
- 2,
62
- {
63
- "functions": false,
64
- "classes": false,
65
- "variables": false
66
- }
67
- ],
68
- "require-atomic-updates": [
69
- 2,
70
- {
71
- "allowProperties": true
72
- }
73
- ],
74
- "block-scoped-var": 2,
75
- "class-methods-use-this": 0,
76
- "consistent-this": 2,
77
- "curly": 2,
78
- "default-case": 2,
79
- "default-case-last": 2,
80
- "default-param-last": 2,
81
- "dot-notation":2,
82
- "eqeqeq": 2,
83
- "func-names": [
84
- 2,
85
- "never"
86
- ],
87
- "logical-assignment-operators": [
88
- 2,
89
- "always",
90
- {
91
- "enforceForIfStatements": true
92
- }
93
- ],
94
- "multiline-comment-style": 2,
95
- "new-cap": [
96
- 1,
97
- {
98
- "capIsNew": false
99
- }
100
- ],
101
- "no-alert": 2,
102
- "no-array-constructor": 2,
103
- "no-bitwise": 2,
104
- "no-control-regex": 0,
105
- "no-else-return": 2,
106
- "no-empty": [
107
- 2,
108
- {
109
- "allowEmptyCatch": true
110
- }
111
- ],
112
- "no-eval": 2,
113
- "no-extend-native": 2,
114
- "no-extra-boolean-cast": [
115
- 2,
116
- {
117
- "enforceForLogicalOperands": true
118
- }
119
- ],
120
- "no-floating-decimal": 2,
121
- "no-implied-eval": 2,
122
- "no-invalid-this": [
123
- 2,
124
- {
125
- "capIsConstructor": false
126
- }
127
- ],
128
- "no-lone-blocks": 2,
129
- "no-lonely-if": 2,
130
- "no-loop-func": 2,
131
- "no-multi-assign": 2,
132
- "no-multi-str": 2,
133
- "no-nested-ternary": 1,
134
- "no-new": 0,
135
- "no-new-func": 2,
136
- "no-new-object": 2,
137
- "no-new-wrappers": 2,
138
- "no-octal-escape": 2,
139
- "no-param-reassign": 0,
140
- "no-return-assign": 2,
141
- "no-return-await": 2,
142
- "no-script-url": 2,
143
- "no-sequences": 2,
144
- "no-shadow": [
145
- 2,
146
- {
147
- "builtinGlobals": true,
148
- "allow": [
149
- "root"
150
- ]
151
- }
152
- ],
153
- "no-undef-init": 2,
154
- "no-unneeded-ternary": [
155
- 2,
156
- {
157
- "defaultAssignment": false
158
- }
159
- ],
160
- "no-unused-expressions": 2,
161
- "no-useless-computed-key": [
162
- 2,
163
- {
164
- "enforceForClassMembers": true
165
- }
166
- ],
167
- "no-useless-concat": 2,
168
- "no-useless-constructor": 2,
169
- "no-useless-rename": 2,
170
- "no-useless-return": 2,
171
- "no-var": 2,
172
- "no-void": 2,
173
- "object-shorthand": 2,
174
- "one-var-declaration-per-line": 2,
175
- "operator-assignment": 2,
176
- "prefer-arrow-callback": 2,
177
- "prefer-const": 2,
178
- "prefer-destructuring": 2,
179
- "prefer-exponentiation-operator": 2,
180
- "prefer-object-spread": 2,
181
- "prefer-regex-literals": [
182
- 2,
183
- {
184
- "disallowRedundantWrapping": true
185
- }
186
- ],
187
- "prefer-rest-params": 2,
188
- "prefer-spread": 2,
189
- "prefer-template": 1,
190
- "quote-props": [
191
- 2,
192
- "as-needed"
193
- ],
194
- "radix": [
195
- 2,
196
- "as-needed"
197
- ],
198
- "require-await": 2,
199
- "spaced-comment": 2,
200
- "strict": 2,
201
- "symbol-description": 2,
202
- "yoda": 2,
203
- "array-bracket-spacing": 2,
204
- "arrow-parens": [
205
- 2,
206
- "as-needed"
207
- ],
208
- "arrow-spacing": 2,
209
- "block-spacing": 2,
210
- "brace-style": 2,
211
- "comma-dangle": [
212
- 2,
213
- "always-multiline"
214
- ],
215
- "comma-spacing": 2,
216
- "comma-style": 2,
217
- "computed-property-spacing": 2,
218
- "dot-location": [
219
- 2,
220
- "property"
221
- ],
222
- "eol-last": 2,
223
- "func-call-spacing": 2,
224
- "indent": [
225
- 2,
226
- "tab",
227
- {
228
- "SwitchCase": 1
229
- }
230
- ],
231
- "key-spacing": 2,
232
- "keyword-spacing": 2,
233
- "linebreak-style": 2,
234
- "multiline-ternary": [
235
- 2,
236
- "always-multiline"
237
- ],
238
- "new-parens": 2,
239
- "no-extra-parens": 2,
240
- "no-multi-spaces": 2,
241
- "no-multiple-empty-lines": [
242
- 2,
243
- {
244
- "max": 1
245
- }
246
- ],
247
- "no-trailing-spaces": 2,
248
- "no-whitespace-before-property": 2,
249
- "operator-linebreak": [
250
- 2,
251
- "before"
252
- ],
253
- "padded-blocks": [
254
- 2,
255
- "never"
256
- ],
257
- "quotes": [
258
- 2,
259
- "single",
260
- {
261
- "avoidEscape": true,
262
- "allowTemplateLiterals": true
263
- }
264
- ],
265
- "rest-spread-spacing": 2,
266
- "semi": 2,
267
- "semi-spacing": 2,
268
- "semi-style": 2,
269
- "space-before-blocks": 2,
270
- "space-before-function-paren": [
271
- 2,
272
- {
273
- "anonymous": "never",
274
- "named": "never",
275
- "asyncArrow": "always"
276
- }
277
- ],
278
- "space-in-parens": 2,
279
- "space-infix-ops": 2,
280
- "space-unary-ops": 2,
281
- "switch-colon-spacing": 2,
282
- "template-curly-spacing": 2,
283
- "wrap-iife": [
284
- 2,
285
- "inside"
286
- ],
287
- "promise/no-multiple-resolved": 1,
288
- "n/exports-style": [
289
- 2,
290
- "module.exports"
291
- ],
292
- "n/no-path-concat": 2,
293
- "n/no-missing-require": 2,
294
- "regexp/no-contradiction-with-assertion": 2,
295
- "regexp/no-missing-g-flag": 2,
296
- "regexp/no-super-linear-backtracking": [
297
- 2,
298
- {
299
- "report": "potential"
300
- }
301
- ],
302
- "regexp/no-super-linear-move": [
303
- 2,
304
- {
305
- "report": "potential"
306
- }
307
- ],
308
- "regexp/no-extra-lookaround-assertions": 2,
309
- "regexp/no-octal": 2,
310
- "regexp/no-standalone-backslash": 2,
311
- "regexp/prefer-escape-replacement-dollar-char": 2,
312
- "regexp/prefer-quantifier": 2,
313
- "regexp/prefer-regexp-test": 2,
314
- "regexp/use-ignore-case": 2,
315
- "regexp/hexadecimal-escape": 2,
316
- "regexp/letter-case": 2,
317
- "regexp/prefer-lookaround": 2
318
- }
319
- }
package/errors/README DELETED
@@ -1 +0,0 @@
1
- 这里记录解析失败时处于半解析状态的维基文本以及错误信息。
package/jsconfig.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "esnext",
4
- "module": "commonJS",
5
- "moduleResolution": "node"
6
- }
7
- }
package/printed/README DELETED
@@ -1 +0,0 @@
1
- 这里存放以 JSON 格式打印的 AST。
@@ -1,28 +0,0 @@
1
- import Token from '../src';
2
-
3
- declare global {
4
- interface AstEvent extends Event {
5
- readonly target: Token;
6
- currentTarget: Token;
7
- prevTarget: ?Token;
8
- };
9
- interface AstEventData {
10
- position: number;
11
- removed: string|Token;
12
- inserted: string|Token;
13
- oldToken: Token;
14
- newToken: Token;
15
- oldText: string;
16
- newText: string;
17
- oldKey: string;
18
- newKey: string;
19
- }
20
- type AstListener = (e: AstEvent, data: AstEventData) => any;
21
-
22
- type pseudo = 'root'|'is'|'not'|'nth-child'|'nth-of-type'|'nth-last-child'|'nth-last-of-type'
23
- |'first-child'|'first-of-type'|'last-child'|'last-of-type'|'only-child'|'only-of-type'|'empty'
24
- |'contains'|'has'|'header'|'parent'|'hidden'|'visible';
25
- type pseudoCall = Record<pseudo, string[]>;
26
- }
27
-
28
- export {};
@@ -1,52 +0,0 @@
1
- import Token from '../src';
2
- import $ from '../tool';
3
- import Title from '../lib/title';
4
-
5
- declare global {
6
- interface Parser {
7
- warning: boolean;
8
- debugging: boolean;
9
-
10
- /** 默认输出到console.warn */
11
- warn(msg: string, ...args: any[]): void;
12
- /** 默认不输出到console.debug */
13
- debug(msg: string, ...args: any[]): void;
14
- /** 总是输出到console.error */
15
- error(msg: string, ...args: any[]): void;
16
- /** 总是输出到console.info */
17
- info(msg: string, ...args: any[]): void;
18
-
19
- running: boolean;
20
-
21
- run<T>(callback: () => T): T;
22
-
23
- /** 只储存导出各个Class的文件路径 */
24
- classes: Record<string, string>;
25
- mixins: Record<string, string>;
26
- parsers: Record<string, string>;
27
- /** 清除各模块的缓存 */
28
- clearCache(): void;
29
-
30
- log(f: Function): void;
31
-
32
- readonly aliases: string[][];
33
-
34
- config: string;
35
- getConfig(): ParserConfig;
36
-
37
- isInterwiki(title: string, config?: ParserConfig): RegExpMatchArray;
38
- normalizeTitle(
39
- title: string, defaultNs?: number, include?: boolean, config?: ParserConfig, halfParsed?: boolean
40
- ): Title;
41
-
42
- readonly MAX_STAGE: number;
43
- parse(wikitext: string|Token, include?: boolean, maxStage?: number, config?: ParserConfig): Token;
44
- reparse(date: string): Token;
45
-
46
- getTool(): typeof $;
47
-
48
- typeAliases: Record<string, string[]>;
49
- }
50
- }
51
-
52
- export {};
package/typings/node.d.ts DELETED
@@ -1,23 +0,0 @@
1
- import Ranges from '../lib/ranges';
2
- import Token from '../src';
3
- import ParameterToken from '../src/parameter';
4
-
5
- declare global {
6
- type TokenAttribute<T> =
7
- T extends 'childNodes' ? (string|Token)[] :
8
- T extends 'parentNode' ? Token|undefined :
9
- T extends 'optional'|'tags'|'flags' ? string[] :
10
- T extends 'stage'|'indent' ? number :
11
- T extends 'config' ? ParserConfig :
12
- T extends 'accum' ? accum :
13
- T extends 'acceptable' ? Record<string, Ranges> :
14
- T extends 'protectedChildren' ? Ranges :
15
- T extends 'keys' ? Set<string> :
16
- T extends 'args' ? Record<string, Set<ParameterToken>> :
17
- T extends 'attr' ? Map<string, string|true> :
18
- T extends 'include'|'selfLink'|'ul'|'ol'|'dt'|'unidirectional'|'bidirectional' ? boolean :
19
- T extends 'pattern' ? RegExp :
20
- string;
21
- }
22
-
23
- export {};
@@ -1,9 +0,0 @@
1
- declare global {
2
- interface BracketExecArray extends RegExpExecArray {
3
- parts: string[][];
4
- findEqual: boolean;
5
- pos: number;
6
- }
7
- }
8
-
9
- export {};
@@ -1,14 +0,0 @@
1
- declare global {
2
- interface TableCoords {
3
- row: number;
4
- column: number;
5
- start: boolean;
6
- }
7
-
8
- interface TableRenderedCoords {
9
- x: number;
10
- y: number;
11
- }
12
- }
13
-
14
- export {};
@@ -1,22 +0,0 @@
1
- import Token from '../src';
2
- import Ranges from '../lib/ranges';
3
-
4
- declare global {
5
- interface ParserConfig {
6
- ext: string[];
7
- html: [string[], string[], string[]];
8
- namespaces: Record<string, string>;
9
- nsid: Record<string, number>;
10
- parserFunction: [string[], string[], string[], string[]];
11
- doubleUnderscore: [string[], string[]];
12
- protocol: string;
13
- interwiki: string[];
14
- img: Record<string, string>;
15
- variants: string[];
16
- }
17
-
18
- type accum = Token[];
19
- type acceptable = Record<string, number|string|Ranges|(number|string)[]>;
20
- }
21
-
22
- export {};
package/typings/tool.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import Token from '../src';
2
-
3
- declare global {
4
- interface CollectionCallback<T, S> extends Function {
5
- call: (thisArg: string|Token, i: number, ele: S) => T;
6
- }
7
- type CollectionMap = (arr: Token[]) => (string|Token)[];
8
- }
9
-
10
- export {};