wikilint 1.1.0 → 2.0.0-beta.1

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 (228) hide show
  1. package/README.md +2 -1
  2. package/config/.schema.json +33 -0
  3. package/config/default.json +1 -0
  4. package/config/llwiki.json +1 -0
  5. package/config/minimum.json +136 -0
  6. package/config/moegirl.json +1 -0
  7. package/config/zhwiki.json +1 -0
  8. package/dist/bin/cli.js +133 -0
  9. package/dist/index.d.ts +50 -109
  10. package/dist/index.js +80 -0
  11. package/dist/internal.d.ts +44 -0
  12. package/dist/lib/element.d.ts +55 -20
  13. package/dist/lib/element.js +162 -0
  14. package/dist/lib/node.d.ts +54 -76
  15. package/dist/lib/node.js +160 -0
  16. package/dist/lib/text.d.ts +30 -22
  17. package/dist/lib/text.js +118 -0
  18. package/dist/lib/title.d.ts +15 -10
  19. package/dist/lib/title.js +60 -0
  20. package/dist/mixin/hidden.js +21 -0
  21. package/dist/parser/braces.js +119 -0
  22. package/dist/parser/commentAndExt.js +63 -0
  23. package/dist/parser/converter.js +38 -0
  24. package/dist/parser/externalLinks.js +26 -0
  25. package/dist/parser/hrAndDoubleUnderscore.js +36 -0
  26. package/dist/parser/html.js +34 -0
  27. package/dist/parser/links.js +92 -0
  28. package/dist/parser/list.js +57 -0
  29. package/dist/parser/magicLinks.js +38 -0
  30. package/dist/parser/quotes.js +65 -0
  31. package/dist/parser/table.js +107 -0
  32. package/dist/src/arg.d.ts +24 -14
  33. package/dist/src/arg.js +91 -0
  34. package/dist/src/atom.d.ts +10 -0
  35. package/dist/src/atom.js +14 -0
  36. package/dist/src/attribute.d.ts +49 -30
  37. package/dist/src/attribute.js +273 -0
  38. package/dist/src/attributes.d.ts +31 -22
  39. package/dist/src/attributes.js +126 -0
  40. package/dist/src/converter.d.ts +18 -16
  41. package/dist/src/converter.js +57 -0
  42. package/dist/src/converterFlags.d.ts +33 -15
  43. package/dist/src/converterFlags.js +84 -0
  44. package/dist/src/converterRule.d.ts +22 -17
  45. package/dist/src/converterRule.js +67 -0
  46. package/dist/src/extLink.d.ts +22 -12
  47. package/dist/src/extLink.js +58 -0
  48. package/dist/src/gallery.d.ts +28 -11
  49. package/dist/src/gallery.js +84 -0
  50. package/dist/src/heading.d.ts +27 -13
  51. package/dist/src/heading.js +89 -0
  52. package/dist/src/hidden.d.ts +15 -0
  53. package/dist/src/hidden.js +11 -0
  54. package/dist/src/html.d.ts +33 -18
  55. package/dist/src/html.js +141 -0
  56. package/dist/src/imageParameter.d.ts +31 -22
  57. package/dist/src/imageParameter.js +130 -0
  58. package/dist/src/imagemap.d.ts +32 -15
  59. package/dist/src/imagemap.js +115 -0
  60. package/dist/src/imagemapLink.d.ts +18 -9
  61. package/dist/src/imagemapLink.js +29 -0
  62. package/dist/src/index.d.ts +31 -40
  63. package/dist/src/index.js +370 -0
  64. package/dist/src/link/base.d.ts +37 -0
  65. package/dist/src/link/base.js +104 -0
  66. package/dist/src/link/category.d.ts +5 -7
  67. package/dist/src/link/category.js +11 -0
  68. package/dist/src/link/file.d.ts +38 -11
  69. package/dist/src/link/file.js +144 -0
  70. package/dist/src/link/galleryImage.d.ts +18 -12
  71. package/dist/src/link/galleryImage.js +53 -0
  72. package/dist/src/link/index.d.ts +6 -29
  73. package/dist/src/link/index.js +14 -0
  74. package/dist/src/magicLink.d.ts +12 -10
  75. package/dist/src/magicLink.js +51 -0
  76. package/dist/src/nested.d.ts +33 -0
  77. package/dist/src/nested.js +62 -0
  78. package/dist/src/nowiki/base.d.ts +14 -0
  79. package/dist/src/nowiki/base.js +11 -0
  80. package/dist/src/nowiki/comment.d.ts +28 -13
  81. package/dist/src/nowiki/comment.js +41 -0
  82. package/dist/src/nowiki/dd.d.ts +5 -7
  83. package/dist/src/nowiki/dd.js +11 -0
  84. package/dist/src/nowiki/doubleUnderscore.d.ts +16 -8
  85. package/dist/src/nowiki/doubleUnderscore.js +23 -0
  86. package/dist/src/nowiki/hr.d.ts +5 -12
  87. package/dist/src/nowiki/hr.js +11 -0
  88. package/dist/src/nowiki/index.d.ts +13 -14
  89. package/dist/src/nowiki/index.js +23 -0
  90. package/dist/src/nowiki/list.d.ts +5 -7
  91. package/dist/src/nowiki/list.js +11 -0
  92. package/dist/src/nowiki/noinclude.d.ts +14 -7
  93. package/dist/src/nowiki/noinclude.js +12 -0
  94. package/dist/src/nowiki/quote.d.ts +8 -16
  95. package/dist/src/nowiki/quote.js +46 -0
  96. package/dist/src/onlyinclude.d.ts +14 -7
  97. package/dist/src/onlyinclude.js +34 -0
  98. package/dist/src/paramTag/index.d.ts +25 -12
  99. package/dist/src/paramTag/index.js +56 -0
  100. package/dist/src/paramTag/inputbox.d.ts +7 -7
  101. package/dist/src/paramTag/inputbox.js +19 -0
  102. package/dist/src/parameter.d.ts +28 -16
  103. package/dist/src/parameter.js +86 -0
  104. package/dist/src/pre.d.ts +21 -0
  105. package/dist/src/pre.js +37 -0
  106. package/dist/src/syntax.d.ts +11 -12
  107. package/dist/src/syntax.js +20 -0
  108. package/dist/src/table/base.d.ts +21 -0
  109. package/dist/src/table/base.js +24 -0
  110. package/dist/src/table/index.d.ts +29 -6
  111. package/dist/src/table/index.js +59 -0
  112. package/dist/src/table/td.d.ts +36 -22
  113. package/dist/src/table/td.js +100 -0
  114. package/dist/src/table/tr.d.ts +15 -15
  115. package/dist/src/table/tr.js +23 -0
  116. package/dist/src/table/trBase.d.ts +23 -0
  117. package/dist/src/table/trBase.js +48 -0
  118. package/dist/src/tagPair/ext.d.ts +19 -13
  119. package/dist/src/tagPair/ext.js +122 -0
  120. package/dist/src/tagPair/include.d.ts +28 -10
  121. package/dist/src/tagPair/include.js +25 -0
  122. package/dist/src/tagPair/index.d.ts +25 -18
  123. package/dist/src/tagPair/index.js +67 -0
  124. package/dist/src/transclude.d.ts +49 -39
  125. package/dist/src/transclude.js +304 -0
  126. package/dist/util/diff.js +71 -0
  127. package/dist/util/lint.js +46 -0
  128. package/dist/util/string.js +41 -0
  129. package/errors/README +1 -0
  130. package/i18n/zh-hans.json +46 -0
  131. package/i18n/zh-hant.json +46 -0
  132. package/package.json +29 -27
  133. package/bin/cli.js +0 -143
  134. package/dist/mixin/hidden.d.ts +0 -8
  135. package/dist/parser/brackets.d.ts +0 -12
  136. package/dist/parser/commentAndExt.d.ts +0 -8
  137. package/dist/parser/converter.d.ts +0 -7
  138. package/dist/parser/externalLinks.d.ts +0 -7
  139. package/dist/parser/hrAndDoubleUnderscore.d.ts +0 -11
  140. package/dist/parser/html.d.ts +0 -7
  141. package/dist/parser/links.d.ts +0 -7
  142. package/dist/parser/list.d.ts +0 -7
  143. package/dist/parser/magicLinks.d.ts +0 -7
  144. package/dist/parser/quotes.d.ts +0 -7
  145. package/dist/parser/table.d.ts +0 -11
  146. package/dist/src/atom/hidden.d.ts +0 -5
  147. package/dist/src/atom/index.d.ts +0 -14
  148. package/dist/src/hasNowiki/index.d.ts +0 -14
  149. package/dist/src/hasNowiki/pre.d.ts +0 -13
  150. package/dist/src/nested/choose.d.ts +0 -13
  151. package/dist/src/nested/combobox.d.ts +0 -13
  152. package/dist/src/nested/index.d.ts +0 -20
  153. package/dist/src/nested/references.d.ts +0 -13
  154. package/dist/util/lint.d.ts +0 -28
  155. package/dist/util/string.d.ts +0 -31
  156. package/index.js +0 -76
  157. package/lib/element.js +0 -115
  158. package/lib/node.js +0 -231
  159. package/lib/text.js +0 -168
  160. package/lib/title.js +0 -56
  161. package/mixin/hidden.js +0 -18
  162. package/parser/brackets.js +0 -127
  163. package/parser/commentAndExt.js +0 -61
  164. package/parser/converter.js +0 -45
  165. package/parser/externalLinks.js +0 -32
  166. package/parser/hrAndDoubleUnderscore.js +0 -48
  167. package/parser/html.js +0 -41
  168. package/parser/links.js +0 -98
  169. package/parser/list.js +0 -58
  170. package/parser/magicLinks.js +0 -40
  171. package/parser/quotes.js +0 -63
  172. package/parser/table.js +0 -113
  173. package/src/arg.js +0 -93
  174. package/src/atom/hidden.js +0 -11
  175. package/src/atom/index.js +0 -26
  176. package/src/attribute.js +0 -286
  177. package/src/attributes.js +0 -147
  178. package/src/converter.js +0 -70
  179. package/src/converterFlags.js +0 -97
  180. package/src/converterRule.js +0 -74
  181. package/src/extLink.js +0 -60
  182. package/src/gallery.js +0 -94
  183. package/src/hasNowiki/index.js +0 -32
  184. package/src/hasNowiki/pre.js +0 -28
  185. package/src/heading.js +0 -83
  186. package/src/html.js +0 -130
  187. package/src/imageParameter.js +0 -141
  188. package/src/imagemap.js +0 -140
  189. package/src/imagemapLink.js +0 -29
  190. package/src/index.js +0 -413
  191. package/src/link/category.js +0 -13
  192. package/src/link/file.js +0 -132
  193. package/src/link/galleryImage.js +0 -62
  194. package/src/link/index.js +0 -119
  195. package/src/magicLink.js +0 -67
  196. package/src/nested/choose.js +0 -23
  197. package/src/nested/combobox.js +0 -22
  198. package/src/nested/index.js +0 -69
  199. package/src/nested/references.js +0 -22
  200. package/src/nowiki/comment.js +0 -47
  201. package/src/nowiki/dd.js +0 -13
  202. package/src/nowiki/doubleUnderscore.js +0 -26
  203. package/src/nowiki/hr.js +0 -22
  204. package/src/nowiki/index.js +0 -34
  205. package/src/nowiki/list.js +0 -13
  206. package/src/nowiki/noinclude.js +0 -14
  207. package/src/nowiki/quote.js +0 -51
  208. package/src/onlyinclude.js +0 -39
  209. package/src/paramTag/index.js +0 -66
  210. package/src/paramTag/inputbox.js +0 -32
  211. package/src/parameter.js +0 -96
  212. package/src/syntax.js +0 -23
  213. package/src/table/index.js +0 -45
  214. package/src/table/td.js +0 -118
  215. package/src/table/tr.js +0 -73
  216. package/src/tagPair/ext.js +0 -126
  217. package/src/tagPair/include.js +0 -26
  218. package/src/tagPair/index.js +0 -77
  219. package/src/transclude.js +0 -336
  220. package/typings/api.d.ts +0 -9
  221. package/typings/index.d.ts +0 -50
  222. package/typings/node.d.ts +0 -16
  223. package/typings/parser.d.ts +0 -5
  224. package/typings/token.d.ts +0 -28
  225. package/util/base.js +0 -17
  226. package/util/diff.js +0 -76
  227. package/util/lint.js +0 -55
  228. package/util/string.js +0 -75
package/README.md CHANGED
@@ -17,6 +17,7 @@ npx wikilint --config zhwiki --include *.wiki
17
17
  | `-c`, `--config` \<path or preset config\> | Choose parser's configuration | `default` |
18
18
  | `-h`, `--help` | Print available options | |
19
19
  | `-i`, `--include` | Parse for inclusion | no inclusion |
20
+ | `-l`, `--lang` | Choose i18n language | English
20
21
  | `-q`, `--quiet` | Report errors only | errors and warnings |
21
- | `-s`, `--strict` | Exit `1` when there is an error or warning<br>Override `-q` or `--quiet` | Exit `1` only where there is an error |
22
+ | `-s`, `--strict` | Exit when there is an error or warning<br>Override `-q` or `--quiet` | Exit `1` only where there is an error |
22
23
  | `-v`, `--version` | Print package version | |
@@ -95,6 +95,12 @@
95
95
  "type": "string",
96
96
  "pattern": "^[a-z:/]+(?:\\|[a-z:/]+)*$"
97
97
  },
98
+ "interwiki": {
99
+ "type": "array",
100
+ "items": {
101
+ "type": "string"
102
+ }
103
+ },
98
104
  "img": {
99
105
  "description": "image-related magic words",
100
106
  "type": "object",
@@ -110,6 +116,32 @@
110
116
  "type": "string",
111
117
  "pattern": "^[-a-z]+$"
112
118
  }
119
+ },
120
+ "conversionTable": {
121
+ "description": "table of unidirectional conversions",
122
+ "type": "array",
123
+ "items": {
124
+ "type": "array",
125
+ "items": {
126
+ "type": "string",
127
+ "pattern": "^[^ <>[\\]{}|]+$"
128
+ },
129
+ "minItems": 2,
130
+ "maxItems": 2
131
+ }
132
+ },
133
+ "redirects": {
134
+ "description": "table of redirects",
135
+ "type": "array",
136
+ "items": {
137
+ "type": "array",
138
+ "items": {
139
+ "type": "string",
140
+ "pattern": "^[^ <>[\\]{}|]+$"
141
+ },
142
+ "minItems": 2,
143
+ "maxItems": 2
144
+ }
113
145
  }
114
146
  },
115
147
  "required": [
@@ -120,6 +152,7 @@
120
152
  "parserFunction",
121
153
  "doubleUnderscore",
122
154
  "protocol",
155
+ "interwiki",
123
156
  "img",
124
157
  "variants"
125
158
  ],
@@ -754,6 +754,7 @@
754
754
  ]
755
755
  ],
756
756
  "protocol": "bitcoin:|ftp://|ftps://|geo:|git://|gopher://|http://|https://|irc://|ircs://|magnet:|mailto:|mms://|news:|nntp://|redis://|sftp://|sip:|sips:|sms:|ssh://|svn://|tel:|telnet://|urn:|worldwind://|xmpp:",
757
+ "interwiki": [],
757
758
  "img": {
758
759
  "thumbnail": "thumbnail",
759
760
  "thumb": "thumbnail",
@@ -518,6 +518,7 @@
518
518
  ]
519
519
  ],
520
520
  "protocol": "bitcoin:|ftp://|ftps://|geo:|git://|gopher://|http://|https://|irc://|ircs://|magnet:|mailto:|mms://|news:|nntp://|redis://|sftp://|sip:|sips:|sms:|ssh://|svn://|tel:|telnet://|urn:|worldwind://|xmpp:",
521
+ "interwiki": [],
521
522
  "img": {
522
523
  "thumbnail": "thumbnail",
523
524
  "thumb": "thumbnail",
@@ -0,0 +1,136 @@
1
+ {
2
+ "ext": [],
3
+ "html": [
4
+ [
5
+ "b",
6
+ "bdi",
7
+ "del",
8
+ "i",
9
+ "ins",
10
+ "u",
11
+ "font",
12
+ "big",
13
+ "small",
14
+ "sub",
15
+ "sup",
16
+ "h1",
17
+ "h2",
18
+ "h3",
19
+ "h4",
20
+ "h5",
21
+ "h6",
22
+ "cite",
23
+ "code",
24
+ "em",
25
+ "s",
26
+ "strike",
27
+ "strong",
28
+ "tt",
29
+ "var",
30
+ "div",
31
+ "center",
32
+ "blockquote",
33
+ "ol",
34
+ "ul",
35
+ "dl",
36
+ "table",
37
+ "caption",
38
+ "pre",
39
+ "ruby",
40
+ "rb",
41
+ "rp",
42
+ "rt",
43
+ "rtc",
44
+ "p",
45
+ "span",
46
+ "abbr",
47
+ "dfn",
48
+ "kbd",
49
+ "samp",
50
+ "data",
51
+ "time",
52
+ "mark",
53
+ "tr",
54
+ "td",
55
+ "th",
56
+ "q",
57
+ "bdo"
58
+ ],
59
+ [
60
+ "li",
61
+ "dt",
62
+ "dd"
63
+ ],
64
+ [
65
+ "br",
66
+ "wbr",
67
+ "hr",
68
+ "meta",
69
+ "link",
70
+ "img"
71
+ ]
72
+ ],
73
+ "namespaces": {
74
+ "6": "File",
75
+ "10": "Template"
76
+ },
77
+ "nsid": {},
78
+ "parserFunction": [
79
+ {
80
+ "#language": "language",
81
+ "#special": "special",
82
+ "#speciale": "speciale",
83
+ "#tag": "tag",
84
+ "#formatdate": "formatdate",
85
+ "#invoke": "invoke",
86
+ "#while": "while",
87
+ "#dowhile": "dowhile",
88
+ "#loop": "loop",
89
+ "#forargs": "forargs",
90
+ "#fornumargs": "fornumargs",
91
+ "#if": "if",
92
+ "#ifeq": "ifeq",
93
+ "#switch": "switch",
94
+ "#ifexist": "ifexist",
95
+ "#ifexpr": "ifexpr",
96
+ "#iferror": "iferror",
97
+ "#time": "time",
98
+ "#timel": "timel",
99
+ "#expr": "expr",
100
+ "#rel2abs": "rel2abs",
101
+ "#titleparts": "titleparts",
102
+ "#categorytree": "categorytree",
103
+ "#urldecode": "urldecode",
104
+ "#choose": "choose",
105
+ "#var": "var",
106
+ "#varexists": "varexists",
107
+ "#var_final": "var_final",
108
+ "#vardefine": "vardefine",
109
+ "#vardefineecho": "vardefineecho",
110
+ "#widget": "widget",
111
+ "#regex": "regex",
112
+ "#related": "related",
113
+ "#cscore": "cscore"
114
+ },
115
+ [],
116
+ [
117
+ "msg",
118
+ "原始",
119
+ "raw"
120
+ ],
121
+ [
122
+ "替代",
123
+ "subst",
124
+ "安全替代",
125
+ "safesubst"
126
+ ]
127
+ ],
128
+ "doubleUnderscore": [
129
+ [],
130
+ []
131
+ ],
132
+ "protocol": "bitcoin:|ftp://|ftps://|geo:|git://|gopher://|http://|https://|irc://|ircs://|magnet:|mailto:|mms://|news:|nntp://|redis://|sftp://|sip:|sips:|sms:|ssh://|svn://|tel:|telnet://|urn:|worldwind://|xmpp:",
133
+ "interwiki": [],
134
+ "img": {},
135
+ "variants": []
136
+ }
@@ -611,6 +611,7 @@
611
611
  ]
612
612
  ],
613
613
  "protocol": "bitcoin:|ftp://|ftps://|geo:|git://|gopher://|http://|https://|irc://|ircs://|magnet:|mailto:|mms://|news:|nntp://|redis://|sftp://|sip:|sips:|sms:|ssh://|svn://|tel:|telnet://|urn:|worldwind://|xmpp:",
614
+ "interwiki": [],
614
615
  "img": {
615
616
  "thumbnail": "thumbnail",
616
617
  "thumb": "thumbnail",
@@ -708,6 +708,7 @@
708
708
  ]
709
709
  ],
710
710
  "protocol": "bitcoin:|ftp://|ftps://|geo:|git://|gopher://|http://|https://|irc://|ircs://|magnet:|mailto:|mms://|news:|nntp://|redis://|sftp://|sip:|sips:|sms:|ssh://|svn://|tel:|telnet://|urn:|worldwind://|xmpp:",
711
+ "interwiki": [],
711
712
  "img": {
712
713
  "thumbnail": "thumbnail",
713
714
  "thumb": "thumbnail",
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ /* eslint-disable n/no-process-exit */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ const Parser = require("../index");
7
+ const man = `
8
+ Available options:
9
+ -c, --config <path or preset config> Choose parser's configuration
10
+ -h, --help Print available options
11
+ -i, --include Parse for inclusion
12
+ -l, --lang Choose i18n language
13
+ -q, --quiet Report errors only
14
+ -s, --strict Exit when there is an error or warning
15
+ Override -q or --quiet
16
+ -v, --version Print package version
17
+ `, preset = new Set(['default', 'zhwiki', 'moegirl', 'llwiki']), { argv } = process, files = [];
18
+ let include = false, quiet = false, strict = false, exit = false, nErr = 0, nWarn = 0, option, config, lang;
19
+ /**
20
+ * throw if `-c` or `--config` option is incorrect
21
+ * @throws `Error` unrecognized config input
22
+ */
23
+ const throwOnConfig = () => {
24
+ if (!config || config.startsWith('-')) {
25
+ throw new Error('The option -c/--config must be followed by a path or a preset config');
26
+ }
27
+ else if (!config.includes('/') && !preset.has(config)) {
28
+ throw new Error(`Unrecognized preset config: ${config}`);
29
+ }
30
+ };
31
+ /**
32
+ * generate plural form if necessary
33
+ * @param n number of items
34
+ * @param word item name
35
+ */
36
+ const plural = (n, word) => `${n} ${word}${n > 1 ? 's' : ''}`;
37
+ /**
38
+ * color the severity
39
+ * @param severity problem severity
40
+ */
41
+ const coloredSeverity = (severity) => `\x1B[${severity === 'error' ? 31 : 33}m${severity}\x1B[0m`.padEnd(16);
42
+ for (let i = 2; i < argv.length; i++) {
43
+ option = argv[i];
44
+ switch (option) {
45
+ case '-c':
46
+ case '--config':
47
+ config = argv[++i];
48
+ throwOnConfig();
49
+ break;
50
+ case '-h':
51
+ case '--help':
52
+ console.log(man);
53
+ process.exit(0);
54
+ break;
55
+ case '-i':
56
+ case '--include':
57
+ include = true;
58
+ break;
59
+ case '-l':
60
+ case '--lang':
61
+ lang = argv[++i];
62
+ break;
63
+ case '-q':
64
+ case '--quiet':
65
+ quiet = true;
66
+ break;
67
+ case '-s':
68
+ case '--strict':
69
+ strict = true;
70
+ break;
71
+ case '-v':
72
+ case '--version': {
73
+ const { version } = require('../../package');
74
+ console.log(`wikilint v${version}`);
75
+ process.exit(0);
76
+ break;
77
+ }
78
+ default:
79
+ if (option.startsWith('--config=')) {
80
+ config = option.slice(9);
81
+ throwOnConfig();
82
+ break;
83
+ }
84
+ else if (option.startsWith('--lang=')) {
85
+ lang = option.slice(7);
86
+ break;
87
+ }
88
+ else if (option.startsWith('-')) {
89
+ throw new Error(`Unknown wikilint option: ${option}\n${man}`);
90
+ }
91
+ files.push(option);
92
+ }
93
+ }
94
+ if (files.length === 0) {
95
+ throw new Error('No target file is specified');
96
+ }
97
+ else if (config) {
98
+ Parser.config = config.includes('/') ? (0, path_1.resolve)(config) : `./config/${config}`;
99
+ }
100
+ if (lang) {
101
+ Parser.i18n = lang;
102
+ }
103
+ if (quiet && strict) {
104
+ quiet = false;
105
+ console.error('-s or --strict will override -q or --quiet\n');
106
+ }
107
+ for (const file of files) {
108
+ const wikitext = (0, fs_1.readFileSync)(file, 'utf8');
109
+ let problems = Parser.parse(wikitext, include).lint();
110
+ const errors = problems.filter(({ severity }) => severity === 'error'), { length: nLocalErr } = errors, nLocalWarn = problems.length - nLocalErr;
111
+ if (quiet) {
112
+ problems = errors;
113
+ }
114
+ else {
115
+ nWarn += nLocalWarn;
116
+ }
117
+ if (problems.length > 0) {
118
+ console.error('\x1B[4m%s\x1B[0m', (0, path_1.resolve)(file));
119
+ const { length: maxLineChars } = String(Math.max(...problems.map(({ startLine }) => startLine))), { length: maxColChars } = String(Math.max(...problems.map(({ startCol }) => startCol)));
120
+ for (const { message, severity, startLine, startCol } of problems) {
121
+ console.error(` ${String(startLine).padStart(maxLineChars)}:${String(startCol).padEnd(maxColChars)} ${coloredSeverity(severity)} ${message}`);
122
+ }
123
+ console.error();
124
+ }
125
+ nErr += nLocalErr;
126
+ exit ||= Boolean(nLocalErr || strict && nLocalWarn);
127
+ }
128
+ if (nErr || nWarn) {
129
+ console.error('\x1B[1;31m%s\x1B[0m\n', `✖ ${plural(nErr + nWarn, 'problem')} (${plural(nErr, 'error')}, ${plural(nWarn, 'warning')})`);
130
+ }
131
+ if (exit) {
132
+ process.exitCode = 1;
133
+ }
package/dist/index.d.ts CHANGED
@@ -1,110 +1,51 @@
1
- import AstElement = require("./lib/element.js")
2
- import AstNode = require("./lib/node.js")
3
- import AstText = require("./lib/text.js")
4
- import Title = require("./lib/title.js")
5
- import ArgToken = require("./src/arg.js")
6
- import HiddenToken = require("./src/atom/hidden.js")
7
- import AtomToken = require("./src/atom/index.js")
8
- import AttributeToken = require("./src/attribute.js")
9
- import AttributesToken = require("./src/attributes.js")
10
- import ConverterToken = require("./src/converter.js")
11
- import ConverterFlagsToken = require("./src/converterFlags.js")
12
- import ConverterRuleToken = require("./src/converterRule.js")
13
- import ExtLinkToken = require("./src/extLink.js")
14
- import GalleryToken = require("./src/gallery.js")
15
- import HasNowikiToken = require("./src/hasNowiki/index.js")
16
- import PreToken = require("./src/hasNowiki/pre.js")
17
- import HeadingToken = require("./src/heading.js")
18
- import HtmlToken = require("./src/html.js")
19
- import ImageParameterToken = require("./src/imageParameter.js")
20
- import ImagemapToken = require("./src/imagemap.js")
21
- import ImagemapLinkToken = require("./src/imagemapLink.js")
22
- import Token = require("./src/index.js")
23
- import CategoryToken = require("./src/link/category.js")
24
- import FileToken = require("./src/link/file.js")
25
- import GalleryImageToken = require("./src/link/galleryImage.js")
26
- import LinkToken = require("./src/link/index.js")
27
- import MagicLinkToken = require("./src/magicLink.js")
28
- import ChooseToken = require("./src/nested/choose.js")
29
- import ComboboxToken = require("./src/nested/combobox.js")
30
- import NestedToken = require("./src/nested/index.js")
31
- import ReferencesToken = require("./src/nested/references.js")
32
- import CommentToken = require("./src/nowiki/comment.js")
33
- import DdToken = require("./src/nowiki/dd.js")
34
- import DoubleUnderscoreToken = require("./src/nowiki/doubleUnderscore.js")
35
- import HrToken = require("./src/nowiki/hr.js")
36
- import NowikiToken = require("./src/nowiki/index.js")
37
- import ListToken = require("./src/nowiki/list.js")
38
- import NoincludeToken = require("./src/nowiki/noinclude.js")
39
- import QuoteToken = require("./src/nowiki/quote.js")
40
- import OnlyincludeToken = require("./src/onlyinclude.js")
41
- import ParamTagToken = require("./src/paramTag/index.js")
42
- import InputboxToken = require("./src/paramTag/inputbox.js")
43
- import ParameterToken = require("./src/parameter.js")
44
- import SyntaxToken = require("./src/syntax.js")
45
- import TableToken = require("./src/table/index.js")
46
- import TdToken = require("./src/table/td.js")
47
- import TrToken = require("./src/table/tr.js")
48
- import ExtToken = require("./src/tagPair/ext.js")
49
- import IncludeToken = require("./src/tagPair/include.js")
50
- import TagPairToken = require("./src/tagPair/index.js")
51
- import TranscludeToken = require("./src/transclude.js")
52
-
1
+ import type { Title } from './lib/title';
2
+ import type { Token } from './internal';
3
+ export interface Config {
4
+ ext: string[];
5
+ html: [string[], string[], string[]];
6
+ namespaces: Record<string, string>;
7
+ nsid: Record<string, number>;
8
+ parserFunction: [Record<string, string>, string[], string[], string[]];
9
+ doubleUnderscore: [string[], string[]];
10
+ protocol: string;
11
+ img: Record<string, string>;
12
+ variants: string[];
13
+ excludes?: string[];
14
+ }
15
+ export interface LintError {
16
+ message: string;
17
+ severity: 'error' | 'warning';
18
+ startIndex: number;
19
+ endIndex: number;
20
+ startLine: number;
21
+ startCol: number;
22
+ endLine: number;
23
+ endCol: number;
24
+ }
25
+ declare interface Parser {
26
+ /** @browser */
27
+ config: string | Config;
28
+ /** @browser */
29
+ i18n?: string | Record<string, string>;
30
+ /**
31
+ * 规范化页面标题
32
+ * @browser
33
+ * @param title 标题(含或不含命名空间前缀)
34
+ * @param defaultNs 命名空间
35
+ * @param include 是否嵌入
36
+ * @param halfParsed 是否是半解析状态
37
+ * @param decode 是否需要解码
38
+ * @param selfLink 是否允许selfLink
39
+ */
40
+ normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config, halfParsed?: boolean, decode?: boolean, selfLink?: boolean): Title;
41
+ /**
42
+ * 解析wikitext
43
+ * @browser
44
+ * @param include 是否嵌入
45
+ * @param maxStage 最大解析层级
46
+ */
47
+ parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config): Token;
48
+ }
49
+ declare const Parser: Parser;
53
50
  export = Parser;
54
- declare const Parser: import('./../typings');
55
-
56
- declare namespace Parser {
57
- export {
58
- AstElement,
59
- AstNode,
60
- AstText,
61
- Title,
62
- ArgToken,
63
- HiddenToken,
64
- AtomToken,
65
- AttributeToken,
66
- AttributesToken,
67
- ConverterToken,
68
- ConverterFlagsToken,
69
- ConverterRuleToken,
70
- ExtLinkToken,
71
- GalleryToken,
72
- HasNowikiToken,
73
- PreToken,
74
- HeadingToken,
75
- HtmlToken,
76
- ImageParameterToken,
77
- ImagemapToken,
78
- ImagemapLinkToken,
79
- Token,
80
- CategoryToken,
81
- FileToken,
82
- GalleryImageToken,
83
- LinkToken,
84
- MagicLinkToken,
85
- ChooseToken,
86
- ComboboxToken,
87
- NestedToken,
88
- ReferencesToken,
89
- CommentToken,
90
- DdToken,
91
- DoubleUnderscoreToken,
92
- HrToken,
93
- NowikiToken,
94
- ListToken,
95
- NoincludeToken,
96
- QuoteToken,
97
- OnlyincludeToken,
98
- ParamTagToken,
99
- InputboxToken,
100
- ParameterToken,
101
- SyntaxToken,
102
- TableToken,
103
- TdToken,
104
- TrToken,
105
- ExtToken,
106
- IncludeToken,
107
- TagPairToken,
108
- TranscludeToken,
109
- }
110
- }
51
+ export type * from './internal';
package/dist/index.js ADDED
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ /* eslint n/exports-style: 0 */
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ /**
6
+ * 从根路径require
7
+ * @param file 文件名
8
+ * @param dir 子路径
9
+ */
10
+ const rootRequire = (file, dir) => require(file.startsWith('/') ? file : `../${file.includes('/') ? '' : dir}${file}`);
11
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
12
+ const Parser = {
13
+ config: 'default',
14
+ MAX_STAGE: 11,
15
+ /** @implements */
16
+ getConfig() {
17
+ if (typeof this.config === 'string') {
18
+ this.config = rootRequire(this.config, 'config/');
19
+ return this.getConfig();
20
+ }
21
+ return { ...this.config, excludes: [] };
22
+ },
23
+ /** @implements */
24
+ msg(msg, arg = '') {
25
+ if (typeof this.i18n === 'string') {
26
+ this.i18n = rootRequire(this.i18n, 'i18n/');
27
+ return this.msg(msg, arg);
28
+ }
29
+ return (this.i18n?.[msg] ?? msg).replace('$1', arg);
30
+ },
31
+ /** @implements */
32
+ normalizeTitle(title, defaultNs = 0, include = false, config = Parser.getConfig(), halfParsed = false, decode = false, selfLink = false) {
33
+ const { Title } = require('./lib/title');
34
+ if (halfParsed) {
35
+ return new Title(title, defaultNs, config, decode, selfLink);
36
+ }
37
+ const { Token } = require('./src');
38
+ const token = this.run(() => new Token(title, config).parseOnce(0, include).parseOnce()), titleObj = new Title(String(token), defaultNs, config, decode, selfLink);
39
+ return titleObj;
40
+ },
41
+ /** @implements */
42
+ parse(wikitext, include, maxStage = Parser.MAX_STAGE, config = Parser.getConfig()) {
43
+ const { Token } = require('./src');
44
+ let token;
45
+ this.run(() => {
46
+ token = new Token(wikitext.replace(/[\0\x7F]/gu, ''), config);
47
+ try {
48
+ token.parse(maxStage, include);
49
+ }
50
+ catch (e) {
51
+ if (e instanceof Error) {
52
+ const file = path.join(__dirname, '..', 'errors', new Date().toISOString()), stage = token.getAttribute('stage');
53
+ fs.writeFileSync(file, stage === this.MAX_STAGE ? wikitext : String(token));
54
+ fs.writeFileSync(`${file}.err`, e.stack);
55
+ fs.writeFileSync(`${file}.json`, JSON.stringify({
56
+ stage, include: token.getAttribute('include'), config: this.config,
57
+ }, null, '\t'));
58
+ }
59
+ throw e;
60
+ }
61
+ });
62
+ return token;
63
+ },
64
+ /** @implements */
65
+ run(callback) {
66
+ const result = callback();
67
+ return result;
68
+ },
69
+ };
70
+ const def = {}, immutable = new Set(['MAX_STAGE']), enumerable = new Set(['config', 'normalizeTitle', 'parse']);
71
+ for (const key in Parser) {
72
+ if (immutable.has(key)) {
73
+ def[key] = { enumerable: false, writable: false };
74
+ }
75
+ else if (!enumerable.has(key)) {
76
+ def[key] = { enumerable: false };
77
+ }
78
+ }
79
+ Object.defineProperties(Parser, def);
80
+ module.exports = Parser;
@@ -0,0 +1,44 @@
1
+ export type { AstNodes, } from './lib/node';
2
+ export type * from './lib/text';
3
+ export type * from './src';
4
+ export type * from './src/onlyinclude';
5
+ export type * from './src/nowiki/noinclude';
6
+ export type * from './src/tagPair/include';
7
+ export type * from './src/nowiki/comment';
8
+ export type * from './src/atom';
9
+ export type { AttributeToken } from './src/attribute';
10
+ export type * from './src/attributes';
11
+ export type * from './src/tagPair/ext';
12
+ export type * from './src/hidden';
13
+ export type * from './src/arg';
14
+ export type * from './src/syntax';
15
+ export type * from './src/parameter';
16
+ export type * from './src/transclude';
17
+ export type * from './src/heading';
18
+ export type * from './src/html';
19
+ export type { TdToken } from './src/table/td';
20
+ export type * from './src/table/tr';
21
+ export type * from './src/table';
22
+ export type * from './src/nowiki/hr';
23
+ export type * from './src/nowiki/doubleUnderscore';
24
+ export type * from './src/link';
25
+ export type * from './src/link/category';
26
+ export type * from './src/imageParameter';
27
+ export type * from './src/link/file';
28
+ export type * from './src/link/galleryImage';
29
+ export type * from './src/nowiki/quote';
30
+ export type * from './src/magicLink';
31
+ export type * from './src/extLink';
32
+ export type * from './src/nowiki/dd';
33
+ export type * from './src/nowiki/list';
34
+ export type * from './src/converterFlags';
35
+ export type * from './src/converterRule';
36
+ export type * from './src/converter';
37
+ export type * from './src/nowiki';
38
+ export type * from './src/pre';
39
+ export type * from './src/paramTag';
40
+ export type * from './src/paramTag/inputbox';
41
+ export type * from './src/nested';
42
+ export type * from './src/gallery';
43
+ export type * from './src/imagemapLink';
44
+ export type * from './src/imagemap';