wikiparser-node 0.0.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 (65) hide show
  1. package/.eslintrc.json +229 -0
  2. package/LICENSE +674 -0
  3. package/README.md +1896 -0
  4. package/config/default.json +766 -0
  5. package/config/llwiki.json +686 -0
  6. package/config/moegirl.json +721 -0
  7. package/index.js +159 -0
  8. package/jsconfig.json +7 -0
  9. package/lib/element.js +690 -0
  10. package/lib/node.js +357 -0
  11. package/lib/ranges.js +122 -0
  12. package/lib/title.js +57 -0
  13. package/mixin/attributeParent.js +67 -0
  14. package/mixin/fixedToken.js +32 -0
  15. package/mixin/hidden.js +22 -0
  16. package/package.json +30 -0
  17. package/parser/brackets.js +107 -0
  18. package/parser/commentAndExt.js +61 -0
  19. package/parser/externalLinks.js +30 -0
  20. package/parser/hrAndDoubleUnderscore.js +26 -0
  21. package/parser/html.js +41 -0
  22. package/parser/links.js +92 -0
  23. package/parser/magicLinks.js +40 -0
  24. package/parser/quotes.js +63 -0
  25. package/parser/table.js +97 -0
  26. package/src/arg.js +150 -0
  27. package/src/atom/hidden.js +10 -0
  28. package/src/atom/index.js +33 -0
  29. package/src/attribute.js +342 -0
  30. package/src/extLink.js +116 -0
  31. package/src/heading.js +91 -0
  32. package/src/html.js +144 -0
  33. package/src/imageParameter.js +172 -0
  34. package/src/index.js +602 -0
  35. package/src/link/category.js +88 -0
  36. package/src/link/file.js +201 -0
  37. package/src/link/index.js +214 -0
  38. package/src/listToken.js +47 -0
  39. package/src/magicLink.js +66 -0
  40. package/src/nowiki/comment.js +45 -0
  41. package/src/nowiki/doubleUnderscore.js +42 -0
  42. package/src/nowiki/hr.js +41 -0
  43. package/src/nowiki/index.js +37 -0
  44. package/src/nowiki/noinclude.js +24 -0
  45. package/src/nowiki/quote.js +37 -0
  46. package/src/onlyinclude.js +42 -0
  47. package/src/parameter.js +165 -0
  48. package/src/syntax.js +80 -0
  49. package/src/table/index.js +867 -0
  50. package/src/table/td.js +259 -0
  51. package/src/table/tr.js +244 -0
  52. package/src/tagPair/ext.js +85 -0
  53. package/src/tagPair/include.js +45 -0
  54. package/src/tagPair/index.js +91 -0
  55. package/src/transclude.js +627 -0
  56. package/tool/index.js +898 -0
  57. package/typings/element.d.ts +28 -0
  58. package/typings/index.d.ts +49 -0
  59. package/typings/node.d.ts +23 -0
  60. package/typings/parser.d.ts +9 -0
  61. package/typings/table.d.ts +14 -0
  62. package/typings/token.d.ts +21 -0
  63. package/typings/tool.d.ts +10 -0
  64. package/util/debug.js +70 -0
  65. package/util/string.js +60 -0
@@ -0,0 +1,28 @@
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 {};
@@ -0,0 +1,49 @@
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
+
45
+ getTool(): typeof $;
46
+ }
47
+ }
48
+
49
+ export {};
@@ -0,0 +1,23 @@
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' ? string[] :
10
+ T extends 'stage' ? 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' ? boolean :
19
+ T extends 'pattern' ? RegExp :
20
+ string;
21
+ }
22
+
23
+ export {};
@@ -0,0 +1,9 @@
1
+ declare global {
2
+ interface BracketExecArray extends RegExpExecArray {
3
+ parts: string[][];
4
+ findEqual: boolean;
5
+ pos: number;
6
+ }
7
+ }
8
+
9
+ export {};
@@ -0,0 +1,14 @@
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 {};
@@ -0,0 +1,21 @@
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
+ }
16
+
17
+ type accum = Token[];
18
+ type acceptable = Record<string, number|string|Ranges|(number|string)[]>;
19
+ }
20
+
21
+ export {};
@@ -0,0 +1,10 @@
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 {};
package/util/debug.js ADDED
@@ -0,0 +1,70 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @param {ObjectConstructor} constructor
5
+ * @param {string} method
6
+ * @param {...string} args
7
+ */
8
+ const typeError = ({constructor}, method, ...args) => {
9
+ throw new TypeError(`${constructor.name}.${method} 方法仅接受 ${args.join('、')} 作为输入参数!`);
10
+ };
11
+
12
+ /**
13
+ * 不是被构造器或原型方法调用
14
+ * @param {string} name
15
+ */
16
+ const externalUse = (name, proxy = false) => {
17
+ if (!proxy && require('..').running) {
18
+ return false;
19
+ }
20
+ const regex = new RegExp(`^${
21
+ proxy ? 'Proxy' : 'new \\w*Token$|^(?:AstNode|AstElement|\\w*Token)'
22
+ }\\.(?!${name}$)`);
23
+ try {
24
+ throw new Error();
25
+ } catch (e) {
26
+ if (e instanceof Error) {
27
+ const mt = e.stack.match(/(?<=^\s+at )(?:new )?[\w.]+(?= \(\/)/gm);
28
+ return !mt.slice(2).some(func => regex.test(func));
29
+ }
30
+ }
31
+ };
32
+
33
+ /**
34
+ * @param {AstEvent} e
35
+ * @param {AstEventData} data
36
+ */
37
+ const undo = (e, data) => {
38
+ const {target, type} = e;
39
+ switch (type) {
40
+ case 'remove': {
41
+ const childNodes = [...target.childNodes];
42
+ childNodes.splice(data.position, 0, data.removed);
43
+ target.setAttribute('childNodes', childNodes);
44
+ break;
45
+ }
46
+ case 'insert': {
47
+ const childNodes = [...target.childNodes];
48
+ childNodes.splice(data.position, 1);
49
+ target.setAttribute('childNodes', childNodes);
50
+ break;
51
+ }
52
+ case 'replace': {
53
+ const {parentNode} = target,
54
+ childNodes = [...parentNode.childNodes];
55
+ childNodes.splice(data.position, 1, data.oldToken);
56
+ parentNode.setAttribute('childNodes', childNodes);
57
+ break;
58
+ }
59
+ case 'text': {
60
+ const childNodes = [...target.childNodes];
61
+ childNodes[data.position] = data.oldText;
62
+ target.setAttribute('childNodes', childNodes);
63
+ break;
64
+ }
65
+ default:
66
+ throw new RangeError(`无法撤销未知类型的事件:${type}`);
67
+ }
68
+ };
69
+
70
+ module.exports = {typeError, externalUse, undo};
package/util/string.js ADDED
@@ -0,0 +1,60 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * optionally convert to lower cases
5
+ * @param {string} val
6
+ * @param {boolean} i
7
+ */
8
+ const toCase = (val, i) => i ? val.toLowerCase() : val;
9
+
10
+ /**
11
+ * remove half-parsed comment-like tokens
12
+ * @param {string} str
13
+ */
14
+ const removeComment = str => str.replace(/\x00\d+c\x7f/g, '');
15
+
16
+ /** @param {string} str */
17
+ const ucfirst = str => str && `${str[0].toUpperCase()}${str.slice(1)}`;
18
+
19
+ /** @param {string} str */
20
+ const escapeRegExp = str => str.replace(/[\\{}()|.?*+\-^$[\]]/g, '\\$&');
21
+
22
+ /** @param {(string|AstNode)[]} childNodes */
23
+ const text = (childNodes, separator = '') => {
24
+ const AstNode = require('../lib/node'); // eslint-disable-line no-unused-vars
25
+ return childNodes.map(child => typeof child === 'string' ? child : child.text()).join(separator);
26
+ };
27
+
28
+ /**
29
+ * @param {string} start
30
+ * @param {string} end
31
+ * @param {string} separator
32
+ * @param {string} str
33
+ */
34
+ const explode = (start, end, separator, str) => {
35
+ if (str === undefined) {
36
+ return [];
37
+ }
38
+ const regex = new RegExp(`${[start, end, separator].map(escapeRegExp).join('|')}`, 'g'),
39
+ /** @type {string[]} */ exploded = [];
40
+ let mt = regex.exec(str),
41
+ depth = 0,
42
+ lastIndex = 0;
43
+ while (mt) {
44
+ const {0: match, index} = mt;
45
+ if (match !== separator) {
46
+ depth += match === start ? 1 : -1;
47
+ } else if (depth === 0) {
48
+ exploded.push(str.slice(lastIndex, index));
49
+ ({lastIndex} = regex);
50
+ }
51
+ mt = regex.exec(str);
52
+ }
53
+ exploded.push(str.slice(lastIndex));
54
+ return exploded;
55
+ };
56
+
57
+ const extUrlChar = '(?:[\\d.]+|\\[[\\da-f:.]+\\]|[^[\\]<>"\\x00-\\x20\\x7f\\p{Zs}\\ufffd])'
58
+ + '[^[\\]<>"\\x00-\\x20\\x7f\\p{Zs}\\ufffd]*';
59
+
60
+ module.exports = {toCase, removeComment, ucfirst, escapeRegExp, text, explode, extUrlChar};