wikiparser-node 1.16.4 → 1.16.6

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 (151) hide show
  1. package/README.md +1 -1
  2. package/bundle/bundle.es7.js +27 -27
  3. package/bundle/bundle.lsp.js +30 -30
  4. package/bundle/bundle.min.js +29 -29
  5. package/dist/addon/table.js +7 -4
  6. package/dist/addon/token.js +13 -7
  7. package/dist/addon/transclude.js +7 -5
  8. package/dist/base.d.mts +99 -30
  9. package/dist/base.d.ts +99 -30
  10. package/dist/index.d.ts +10 -4
  11. package/dist/index.js +59 -14
  12. package/dist/lib/attributes.js +2 -2
  13. package/dist/lib/element.d.ts +96 -42
  14. package/dist/lib/element.js +98 -45
  15. package/dist/lib/lsp.d.ts +64 -35
  16. package/dist/lib/lsp.js +208 -159
  17. package/dist/lib/node.d.ts +122 -53
  18. package/dist/lib/node.js +172 -75
  19. package/dist/lib/range.d.ts +83 -31
  20. package/dist/lib/range.js +83 -31
  21. package/dist/lib/ranges.d.ts +1 -1
  22. package/dist/lib/ranges.js +3 -2
  23. package/dist/lib/text.d.ts +40 -14
  24. package/dist/lib/text.js +47 -19
  25. package/dist/lib/title.d.ts +50 -16
  26. package/dist/lib/title.js +77 -36
  27. package/dist/mixin/attributesParent.d.ts +37 -21
  28. package/dist/mixin/attributesParent.js +0 -2
  29. package/dist/mixin/flagsParent.d.ts +38 -12
  30. package/dist/mixin/hidden.d.ts +0 -2
  31. package/dist/mixin/hidden.js +0 -2
  32. package/dist/mixin/magicLinkParent.d.ts +11 -5
  33. package/dist/mixin/singleLine.d.ts +0 -2
  34. package/dist/mixin/singleLine.js +3 -3
  35. package/dist/mixin/sol.d.ts +0 -2
  36. package/dist/mixin/sol.js +2 -3
  37. package/dist/mixin/syntax.d.ts +0 -2
  38. package/dist/mixin/syntax.js +0 -2
  39. package/dist/parser/braces.js +52 -20
  40. package/dist/parser/commentAndExt.js +19 -6
  41. package/dist/parser/links.js +13 -7
  42. package/dist/parser/list.js +3 -1
  43. package/dist/parser/quotes.js +22 -2
  44. package/dist/parser/redirect.js +4 -1
  45. package/dist/src/arg.d.ts +19 -9
  46. package/dist/src/arg.js +34 -15
  47. package/dist/src/atom.d.ts +5 -1
  48. package/dist/src/atom.js +5 -1
  49. package/dist/src/attribute.d.ts +26 -8
  50. package/dist/src/attribute.js +30 -11
  51. package/dist/src/attributes.d.ts +50 -22
  52. package/dist/src/attributes.js +54 -26
  53. package/dist/src/converter.d.ts +4 -2
  54. package/dist/src/converter.js +12 -9
  55. package/dist/src/converterFlags.d.ts +45 -15
  56. package/dist/src/converterFlags.js +45 -15
  57. package/dist/src/converterRule.d.ts +30 -11
  58. package/dist/src/converterRule.js +46 -16
  59. package/dist/src/extLink.d.ts +6 -2
  60. package/dist/src/extLink.js +14 -11
  61. package/dist/src/gallery.d.ts +13 -9
  62. package/dist/src/gallery.js +35 -21
  63. package/dist/src/heading.d.ts +13 -7
  64. package/dist/src/heading.js +21 -11
  65. package/dist/src/hidden.d.ts +5 -1
  66. package/dist/src/hidden.js +7 -3
  67. package/dist/src/html.d.ts +11 -5
  68. package/dist/src/html.js +16 -7
  69. package/dist/src/imageParameter.d.ts +23 -11
  70. package/dist/src/imageParameter.js +22 -10
  71. package/dist/src/imagemap.d.ts +4 -4
  72. package/dist/src/imagemap.js +9 -5
  73. package/dist/src/imagemapLink.d.ts +3 -1
  74. package/dist/src/imagemapLink.js +3 -1
  75. package/dist/src/index.d.ts +65 -20
  76. package/dist/src/index.js +111 -39
  77. package/dist/src/link/base.d.ts +14 -6
  78. package/dist/src/link/base.js +40 -17
  79. package/dist/src/link/category.d.ts +7 -2
  80. package/dist/src/link/category.js +20 -4
  81. package/dist/src/link/file.d.ts +71 -23
  82. package/dist/src/link/file.js +100 -36
  83. package/dist/src/link/galleryImage.d.ts +8 -4
  84. package/dist/src/link/galleryImage.js +15 -8
  85. package/dist/src/link/index.d.ts +12 -4
  86. package/dist/src/link/index.js +15 -5
  87. package/dist/src/link/redirectTarget.d.ts +3 -2
  88. package/dist/src/link/redirectTarget.js +5 -3
  89. package/dist/src/magicLink.d.ts +24 -11
  90. package/dist/src/magicLink.js +36 -19
  91. package/dist/src/nested.d.ts +5 -3
  92. package/dist/src/nested.js +9 -6
  93. package/dist/src/nowiki/base.d.ts +4 -2
  94. package/dist/src/nowiki/base.js +6 -5
  95. package/dist/src/nowiki/comment.d.ts +6 -2
  96. package/dist/src/nowiki/comment.js +8 -3
  97. package/dist/src/nowiki/dd.d.ts +0 -3
  98. package/dist/src/nowiki/dd.js +0 -8
  99. package/dist/src/nowiki/doubleUnderscore.d.ts +5 -1
  100. package/dist/src/nowiki/doubleUnderscore.js +5 -1
  101. package/dist/src/nowiki/index.d.ts +5 -1
  102. package/dist/src/nowiki/index.js +5 -1
  103. package/dist/src/nowiki/list.d.ts +5 -1
  104. package/dist/src/nowiki/list.js +5 -1
  105. package/dist/src/nowiki/listBase.d.ts +15 -5
  106. package/dist/src/nowiki/listBase.js +40 -9
  107. package/dist/src/nowiki/noinclude.d.ts +5 -1
  108. package/dist/src/nowiki/noinclude.js +5 -1
  109. package/dist/src/nowiki/quote.d.ts +15 -8
  110. package/dist/src/nowiki/quote.js +32 -12
  111. package/dist/src/onlyinclude.d.ts +4 -2
  112. package/dist/src/onlyinclude.js +4 -2
  113. package/dist/src/paramTag/index.d.ts +1 -1
  114. package/dist/src/paramTag/index.js +1 -1
  115. package/dist/src/parameter.d.ts +24 -12
  116. package/dist/src/parameter.js +45 -27
  117. package/dist/src/pre.d.ts +1 -1
  118. package/dist/src/pre.js +1 -1
  119. package/dist/src/redirect.d.ts +2 -0
  120. package/dist/src/redirect.js +2 -0
  121. package/dist/src/syntax.d.ts +5 -1
  122. package/dist/src/syntax.js +5 -1
  123. package/dist/src/table/base.d.ts +5 -1
  124. package/dist/src/table/base.js +10 -3
  125. package/dist/src/table/index.d.ts +134 -66
  126. package/dist/src/table/index.js +150 -81
  127. package/dist/src/table/td.d.ts +18 -10
  128. package/dist/src/table/td.js +25 -15
  129. package/dist/src/table/tr.d.ts +13 -3
  130. package/dist/src/table/tr.js +14 -6
  131. package/dist/src/table/trBase.d.ts +28 -12
  132. package/dist/src/table/trBase.js +28 -18
  133. package/dist/src/tagPair/ext.d.ts +3 -1
  134. package/dist/src/tagPair/ext.js +10 -8
  135. package/dist/src/tagPair/include.d.ts +8 -2
  136. package/dist/src/tagPair/include.js +8 -2
  137. package/dist/src/tagPair/index.d.ts +6 -2
  138. package/dist/src/tagPair/index.js +6 -2
  139. package/dist/src/transclude.d.ts +102 -33
  140. package/dist/src/transclude.js +114 -42
  141. package/dist/util/debug.js +2 -7
  142. package/dist/util/html.js +1 -18
  143. package/dist/util/string.js +7 -1
  144. package/extensions/dist/base.js +27 -16
  145. package/extensions/dist/codejar.js +2 -1
  146. package/extensions/dist/lsp.js +5 -10
  147. package/extensions/es7/base.js +27 -16
  148. package/extensions/ui.css +1 -162
  149. package/i18n/zh-hans.json +1 -1
  150. package/i18n/zh-hant.json +1 -1
  151. package/package.json +3 -3
@@ -1,14 +1,20 @@
1
1
  import type { MagicLinkToken } from '../src/magicLink';
2
2
  export interface MagicLinkParentBase {
3
- /** 协议 */
3
+ /** URL protocol / 协议 */
4
4
  protocol: string | undefined;
5
- /** 和内链保持一致 */
5
+ /** link / 链接 */
6
6
  link: string;
7
- /** 获取网址 */
7
+ /**
8
+ * Get the URL
9
+ *
10
+ * 获取网址
11
+ */
8
12
  getUrl(): URL;
9
13
  /**
10
- * 设置链接目标
11
- * @param url 网址
14
+ * Set the target of the link
15
+ *
16
+ * 设置外链目标
17
+ * @param url URL containing the protocol / 含协议的网址
12
18
  */
13
19
  setTarget(url: string): void;
14
20
  }
@@ -1,6 +1,4 @@
1
1
  /**
2
2
  * 不可包含换行符的类
3
3
  * @param strict 是否严格
4
- * @param constructor 基类
5
- * @param _ context
6
4
  */
@@ -6,8 +6,6 @@ const constants_1 = require("../util/constants");
6
6
  /**
7
7
  * 不可包含换行符的类
8
8
  * @param strict 是否严格
9
- * @param constructor 基类
10
- * @param _ context
11
9
  */
12
10
  const singleLine = (strict = true) => (constructor, _) => {
13
11
  /** 不可包含换行符的类 */
@@ -19,7 +17,9 @@ const singleLine = (strict = true) => (constructor, _) => {
19
17
  // InputboxToken
20
18
  return this.childNodes.map(child => {
21
19
  const str = child.toString(skip), { type } = child;
22
- return type === 'comment' || type === 'include' || type === 'ext' ? str : str.replaceAll('\n', ' ');
20
+ return type === 'comment' || type === 'include' || type === 'ext'
21
+ ? str
22
+ : str.replaceAll('\n', ' ');
23
23
  }).join('');
24
24
  }
25
25
  text() {
@@ -1,6 +1,4 @@
1
1
  /**
2
2
  * 只能位于行首的类
3
3
  * @param self 是否允许同类节点相邻
4
- * @param constructor 基类
5
- * @param _ context
6
4
  */
package/dist/mixin/sol.js CHANGED
@@ -6,8 +6,6 @@ const constants_1 = require("../util/constants");
6
6
  /**
7
7
  * 只能位于行首的类
8
8
  * @param self 是否允许同类节点相邻
9
- * @param constructor 基类
10
- * @param _ context
11
9
  */
12
10
  const sol = (self) => (constructor, _) => {
13
11
  /** 只能位于行首的类 */
@@ -16,7 +14,8 @@ const sol = (self) => (constructor, _) => {
16
14
  #prependNewLine() {
17
15
  const { previousVisibleSibling, parentNode, type } = this;
18
16
  if (previousVisibleSibling) {
19
- return self && previousVisibleSibling.type === type || previousVisibleSibling.toString().endsWith('\n')
17
+ return self && previousVisibleSibling.type === type
18
+ || previousVisibleSibling.toString().endsWith('\n')
20
19
  ? ''
21
20
  : '\n';
22
21
  }
@@ -3,6 +3,4 @@ export interface SyntaxBase {
3
3
  /**
4
4
  * 满足特定语法格式的Token
5
5
  * @param pattern 语法正则
6
- * @param constructor 基类
7
- * @param _ context
8
6
  */
@@ -7,8 +7,6 @@ const string_1 = require("../util/string");
7
7
  /**
8
8
  * 满足特定语法格式的Token
9
9
  * @param pattern 语法正则
10
- * @param constructor 基类
11
- * @param _ context
12
10
  */
13
11
  const syntax = (pattern) => (constructor, _) => {
14
12
  /** 满足特定语法格式的Token */
@@ -13,7 +13,24 @@ const closes = {
13
13
  '{': String.raw `\}{2,}|\|`,
14
14
  '-': String.raw `\}-`,
15
15
  '[': String.raw `\]\]`,
16
- }, openBraces = String.raw `|\{{2,}`, marks = new Map([['!', '!'], ['!!', '+'], ['(!', '{'], ['!)', '}'], ['!-', '-'], ['=', '~'], ['server', 'm']]), re = /\{\{\s*([^\s\0<>[\]{}|_#&%:.]+)\s*\}\}(?!\})/gu;
16
+ }, openBraces = String.raw `|\{{2,}`, marks = new Map([['!', '!'], ['!!', '+'], ['(!', '{'], ['!)', '}'], ['!-', '-'], ['=', '~'], ['server', 'm']]);
17
+ /**
18
+ * 获取模板或魔术字对应的字符
19
+ * @param s 模板或魔术字名
20
+ */
21
+ const getSymbol = (s) => {
22
+ const name = (0, string_1.removeComment)(s).trim().toLowerCase();
23
+ if (marks.has(name)) {
24
+ return marks.get(name); // 标记{{!}}等
25
+ }
26
+ else if (/^(?:filepath|(?:full|canonical)urle?):./u.test(name)) {
27
+ return 'm';
28
+ }
29
+ else if (/^#vardefine:./u.test(name)) {
30
+ return 'n';
31
+ }
32
+ return 't';
33
+ };
17
34
  /**
18
35
  * 解析花括号
19
36
  * @param wikitext
@@ -22,11 +39,32 @@ const closes = {
22
39
  * @throws TranscludeToken.constructor()
23
40
  */
24
41
  const parseBraces = (wikitext, config, accum) => {
25
- const source = String.raw `${config.excludes?.includes('heading') ? '' : String.raw `^((?:\0\d+[cno]\x7F)*)={1,6}|`}\[\[|-\{(?!\{)`, { parserFunction: [, , , subst] } = config, stack = [];
26
- wikitext = wikitext.replace(re, (m, p1) => {
27
- // @ts-expect-error abstract class
28
- new transclude_1.TranscludeToken(m.slice(2, -2), [], config, accum);
29
- return `\0${accum.length - 2}${marks.get(p1.toLowerCase()) ?? 't'}\x7F`;
42
+ const source = String.raw `${config.excludes?.includes('heading') ? '' : String.raw `^((?:\0\d+[cno]\x7F)*)={1,6}|`}\[\[|-\{(?!\{)`, { parserFunction: [, , , subst] } = config, stack = [], linkStack = [];
43
+ /**
44
+ * 恢复内链
45
+ * @param s 不含内链的字符串
46
+ */
47
+ const restore = (s) => s.replace(/\0(\d+)\x7F/gu, (_, p1) => linkStack[p1]);
48
+ wikitext = wikitext.replace(/\{\{([^\n{}[]*)\}\}(?!\})|\[\[[^\n[\]{]*\]\]/gu, (m, p1) => {
49
+ if (p1 !== undefined) {
50
+ try {
51
+ const { length } = accum, parts = p1.split('|');
52
+ // @ts-expect-error abstract class
53
+ new transclude_1.TranscludeToken(parts[0], parts.slice(1).map(part => {
54
+ const i = part.indexOf('=');
55
+ return i === -1 ? [part] : [part.slice(0, i), part.slice(i + 1)];
56
+ }), config, accum);
57
+ return `\0${length}${getSymbol(parts[0])}\x7F`;
58
+ }
59
+ catch (e) {
60
+ /* istanbul ignore if */
61
+ if (!(e instanceof SyntaxError) || e.message !== 'Invalid template name') {
62
+ throw e;
63
+ }
64
+ }
65
+ }
66
+ linkStack.push(m);
67
+ return `\0${linkStack.length - 1}\x7F`;
30
68
  });
31
69
  const lastBraces = wikitext.lastIndexOf('}}') - wikitext.length;
32
70
  let moreBraces = lastBraces + wikitext.length !== -1;
@@ -34,7 +72,8 @@ const parseBraces = (wikitext, config, accum) => {
34
72
  /^((?:\0\d+[cno]\x7F)*)={1,6}|\[\[|-\{(?!\{)|\{{2,}|\n(?!(?:[^\S\n]|\0\d+[cn]\x7F)*\n)|[|=]|\}{2,}|\}-|\]\]/gmu;
35
73
  let regex = new RegExp(source + (moreBraces ? openBraces : ''), 'gmu'), mt = regex.exec(wikitext), lastIndex;
36
74
  while (mt
37
- || lastIndex !== undefined && lastIndex <= wikitext.length && stack[stack.length - 1]?.[0]?.startsWith('=')) {
75
+ || lastIndex !== undefined && lastIndex <= wikitext.length
76
+ && stack[stack.length - 1]?.[0]?.startsWith('=')) {
38
77
  if (mt?.[1]) {
39
78
  const [, { length }] = mt;
40
79
  mt[0] = mt[0].slice(length);
@@ -46,7 +85,7 @@ const parseBraces = (wikitext, config, accum) => {
46
85
  * @param text wikitext全文
47
86
  */
48
87
  const push = (text) => {
49
- parts[parts.length - 1].push(text.slice(topPos, curIndex));
88
+ parts[parts.length - 1].push(restore(text.slice(topPos, curIndex)));
50
89
  };
51
90
  if (syntax === ']]' || syntax === '}-') { // 情形1:闭合内链或转换
52
91
  lastIndex = curIndex + 2;
@@ -60,6 +99,7 @@ const parseBraces = (wikitext, config, accum) => {
60
99
  if (rmt) {
61
100
  wikitext = `${wikitext.slice(0, index)}\0${accum.length}h\x7F${wikitext.slice(curIndex)}`;
62
101
  lastIndex = index + 4 + String(accum.length).length;
102
+ rmt[2] = restore(rmt[2]);
63
103
  // @ts-expect-error abstract class
64
104
  new heading_1.HeadingToken(rmt[1].length, rmt.slice(2), config, accum);
65
105
  }
@@ -84,7 +124,8 @@ const parseBraces = (wikitext, config, accum) => {
84
124
  const argParts = parts.map(part => part.join('=')), str = argParts.length > 1 && (0, string_1.removeComment)(argParts[1]).trim();
85
125
  // @ts-expect-error abstract class
86
126
  new arg_1.ArgToken(argParts, config, accum);
87
- if (str && str.endsWith(':') && subst.includes(str.slice(0, -1).toLowerCase())) {
127
+ if (str && str.endsWith(':')
128
+ && subst.includes(str.slice(0, -1).toLowerCase())) {
88
129
  ch = 's';
89
130
  }
90
131
  }
@@ -92,16 +133,7 @@ const parseBraces = (wikitext, config, accum) => {
92
133
  try {
93
134
  // @ts-expect-error abstract class
94
135
  new transclude_1.TranscludeToken(parts[0][0], parts.slice(1), config, accum);
95
- const name = (0, string_1.removeComment)(parts[0][0]).trim();
96
- if (marks.has(name.toLowerCase())) {
97
- ch = marks.get(name.toLowerCase()); // 标记{{!}}等
98
- }
99
- else if (/^(?:filepath|(?:full|canonical)urle?):./iu.test(name)) {
100
- ch = 'm';
101
- }
102
- else if (/^#vardefine:./iu.test(name)) {
103
- ch = 'n';
104
- }
136
+ ch = getSymbol(parts[0][0]);
105
137
  }
106
138
  catch (e) {
107
139
  /* istanbul ignore else */
@@ -147,7 +179,7 @@ const parseBraces = (wikitext, config, accum) => {
147
179
  regex.lastIndex = lastIndex;
148
180
  mt = regex.exec(wikitext);
149
181
  }
150
- return wikitext;
182
+ return restore(wikitext);
151
183
  };
152
184
  exports.parseBraces = parseBraces;
153
185
  constants_1.parsers['parseBraces'] = __filename;
@@ -9,7 +9,24 @@ const comment_1 = require("../src/nowiki/comment");
9
9
  /* NOT FOR BROWSER */
10
10
  const constants_1 = require("../util/constants");
11
11
  /* NOT FOR BROWSER END */
12
- const onlyincludeLeft = '<onlyinclude>', onlyincludeRight = '</onlyinclude>', { length } = onlyincludeLeft;
12
+ const onlyincludeLeft = '<onlyinclude>', onlyincludeRight = '</onlyinclude>', { length } = onlyincludeLeft, regexInclude = new WeakMap(), regexNoinclude = new WeakMap();
13
+ /**
14
+ * 获取正则表达式
15
+ * @param ext 扩展标签
16
+ * @param includeOnly 是否嵌入
17
+ */
18
+ const getRegex = (ext, includeOnly) => {
19
+ const regex = includeOnly ? regexInclude : regexNoinclude;
20
+ if (regex.has(ext)) {
21
+ return regex.get(ext);
22
+ }
23
+ const noincludeRegex = includeOnly ? 'includeonly' : '(?:no|only)include', includeRegex = includeOnly ? 'noinclude' : 'includeonly';
24
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
25
+ /<!--[\s\S]*?(?:-->|$)|<foo(?:\s[^>]*)?\/?>|<\/foo\s*>|<(bar)(\s[^>]*?)?(?:\/>|>([\s\S]*?)<\/(\1\s*)>)|<(baz)(\s[^>]*?)?(?:\/>|>([\s\S]*?)(?:<\/(baz\s*)>|$))/giu;
26
+ const re = new RegExp(String.raw `<!--[\s\S]*?(?:-->|$)|<${noincludeRegex}(?:\s[^>]*)?/?>|</${noincludeRegex}\s*>|<(${ext.join('|')})(\s[^>]*?)?(?:/>|>([\s\S]*?)</(\1\s*)>)|<(${includeRegex})(\s[^>]*?)?(?:/>|>([\s\S]*?)(?:</(${includeRegex}\s*)>|$))`, 'giu');
27
+ regex.set(ext, re);
28
+ return re;
29
+ };
13
30
  /**
14
31
  * 更新`<onlyinclude>`和`</onlyinclude>`的位置
15
32
  * @param wikitext
@@ -55,11 +72,7 @@ const parseCommentAndExt = (wikitext, config, accum, includeOnly) => {
55
72
  return str;
56
73
  }
57
74
  }
58
- const ext = config.ext.join('|'), noincludeRegex = includeOnly ? 'includeonly' : '(?:no|only)include', includeRegex = includeOnly ? 'noinclude' : 'includeonly';
59
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
60
- /<!--[\s\S]*?(?:-->|$)|<foo(?:\s[^>]*)?\/?>|<\/foo\s*>|<(bar)(\s[^>]*?)?(?:\/>|>([\s\S]*?)<\/(\1\s*)>)|<(baz)(\s[^>]*?)?(?:\/>|>([\s\S]*?)(?:<\/(baz\s*)>|$))/giu;
61
- const /** Never cached due to the possibility of nested extension tags */ regex = new RegExp(String.raw `<!--[\s\S]*?(?:-->|$)|<${noincludeRegex}(?:\s[^>]*)?/?>|</${noincludeRegex}\s*>|<(${ext})(\s[^>]*?)?(?:/>|>([\s\S]*?)</(\1\s*)>)|<(${includeRegex})(\s[^>]*?)?(?:/>|>([\s\S]*?)(?:</(${includeRegex}\s*)>|$))`, 'giu');
62
- return wikitext.replace(regex, (substr, name, attr, inner, closing, include, includeAttr, includeInner, includeClosing) => {
75
+ return wikitext.replace(getRegex(config.ext, includeOnly), (substr, name, attr, inner, closing, include, includeAttr, includeInner, includeClosing) => {
63
76
  const l = accum.length;
64
77
  let ch = 'n';
65
78
  if (name) {
@@ -16,8 +16,9 @@ const regexImg = /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(\||\0\d+!\x7F)([\s\S]*)$/u;
16
16
  * @param wikitext
17
17
  * @param config
18
18
  * @param accum
19
+ * @param tidy 是否整理链接
19
20
  */
20
- const parseLinks = (wikitext, config, accum) => {
21
+ const parseLinks = (wikitext, config, accum, tidy) => {
21
22
  /^\s*(?:ftp:\/\/|\/\/)/iu; // eslint-disable-line @typescript-eslint/no-unused-expressions
22
23
  config.regexLinks ??= new RegExp(String.raw `^\s*(?:${config.protocol}|//)`, 'iu');
23
24
  const regex = true // eslint-disable-line no-constant-condition, @typescript-eslint/no-unnecessary-condition
@@ -50,13 +51,16 @@ const parseLinks = (wikitext, config, accum) => {
50
51
  s += `[[${x}`;
51
52
  continue;
52
53
  }
53
- const title = index_1.default.normalizeTitle(link, 0, false, config, true, true, true), { ns, valid, interwiki } = title;
54
+ const { ns, valid,
55
+ /* NOT FOR BROWSER */
56
+ interwiki, } = index_1.default.normalizeTitle(link, 0, false, config, true, true, true, true);
54
57
  if (!valid) {
55
58
  s += `[[${x}`;
56
59
  continue;
57
60
  }
58
61
  else if (mightBeImg) {
59
- if (interwiki || ns !== 6) {
62
+ if (ns !== 6
63
+ || interwiki) {
60
64
  s += `[[${x}`;
61
65
  continue;
62
66
  }
@@ -77,20 +81,22 @@ const parseLinks = (wikitext, config, accum) => {
77
81
  break;
78
82
  }
79
83
  }
80
- text = (0, exports.parseLinks)(text, config, accum);
84
+ text = (0, exports.parseLinks)(text, config, accum, tidy);
81
85
  if (!found) {
82
86
  s += `[[${link}${delimiter}${text}`;
83
87
  continue;
84
88
  }
85
89
  }
86
- text &&= (0, quotes_1.parseQuotes)(text, config, accum);
90
+ text &&= (0, quotes_1.parseQuotes)(text, config, accum, tidy);
87
91
  let SomeLinkToken = index_2.LinkToken;
88
92
  if (!force) {
89
- if (!interwiki && ns === 6) {
93
+ if (ns === 6
94
+ && !interwiki) {
90
95
  text &&= (0, externalLinks_1.parseExternalLinks)(text, config, accum, true);
91
96
  SomeLinkToken = file_1.FileToken;
92
97
  }
93
- else if (!interwiki && ns === 14) {
98
+ else if (ns === 14
99
+ && !interwiki) {
94
100
  SomeLinkToken = category_1.CategoryToken;
95
101
  }
96
102
  }
@@ -33,7 +33,9 @@ const parseList = (wikitext, state, config, accum) => {
33
33
  }
34
34
  }
35
35
  state.lastPrefix = prefix2;
36
- let text = comment + parts.map((_, i) => `\0${accum.length + i}d\x7F`).join('') + wikitext.slice(total.length);
36
+ let text = comment
37
+ + parts.map((_, i) => `\0${accum.length + i}d\x7F`).join('')
38
+ + wikitext.slice(total.length);
37
39
  for (const part of parts) {
38
40
  // @ts-expect-error abstract class
39
41
  new list_1.ListToken(part, config, accum);
@@ -10,8 +10,9 @@ const constants_1 = require("../util/constants");
10
10
  * @param wikitext
11
11
  * @param config
12
12
  * @param accum
13
+ * @param tidy 是否整理
13
14
  */
14
- const parseQuotes = (wikitext, config, accum) => {
15
+ const parseQuotes = (wikitext, config, accum, tidy) => {
15
16
  const arr = wikitext.split(/('{2,})/u), { length } = arr;
16
17
  if (length === 1) {
17
18
  return wikitext;
@@ -58,11 +59,30 @@ const parseQuotes = (wikitext, config, accum) => {
58
59
  arr[i - 1] += `'`;
59
60
  }
60
61
  }
62
+ /* NOT FOR BROWSER */
63
+ let bold = true, italic = true;
64
+ /* NOT FOR BROWSER END */
61
65
  for (let i = 1; i < length; i += 2) {
66
+ /* NOT FOR BROWSER */
67
+ const n = arr[i].length, isBold = n !== 2, isItalic = n !== 3;
68
+ if (isBold) {
69
+ bold = !bold;
70
+ }
71
+ if (isItalic) {
72
+ italic = !italic;
73
+ }
74
+ /* NOT FOR BROWSER END */
62
75
  // @ts-expect-error abstract class
63
- new quote_1.QuoteToken(arr[i], config, accum);
76
+ new quote_1.QuoteToken(arr[i], { bold: isBold && bold, italic: isItalic && italic }, config, accum);
64
77
  arr[i] = `\0${accum.length - 1}q\x7F`;
65
78
  }
79
+ /* NOT FOR BROWSER */
80
+ if (tidy && (!bold || !italic)) {
81
+ // @ts-expect-error abstract class
82
+ new quote_1.QuoteToken((bold ? '' : "'''") + (italic ? '' : "''"), { bold: !bold, italic: !italic }, config, accum);
83
+ arr.push(`\0${accum.length - 1}q\x7F`);
84
+ }
85
+ /* NOT FOR BROWSER END */
66
86
  return arr.join('');
67
87
  };
68
88
  exports.parseQuotes = parseQuotes;
@@ -17,7 +17,10 @@ const parseRedirect = (text, config, accum) => {
17
17
  /^(\s*)((?:#redirect|#重定向)\s*(?::\s*)?)\[\[([^\n|\]]+)(\|.*?)?\]\](\s*)/iu;
18
18
  config.regexRedirect ??= new RegExp(String.raw `^(\s*)((?:${config.redirection.join('|')})\s*(?::\s*)?)\[\[([^\n|\]]+)(\|.*?)?\]\](\s*)`, 'iu');
19
19
  const mt = config.regexRedirect.exec(text);
20
- if (mt && index_1.default.normalizeTitle(mt[3], 0, false, config, true, true).valid) {
20
+ if (mt
21
+ && index_1.default
22
+ .normalizeTitle(mt[3], 0, false, config, true, true, true)
23
+ .valid) {
21
24
  text = `\0${accum.length}o\x7F${text.slice(mt[0].length)}`;
22
25
  // @ts-expect-error abstract class
23
26
  new redirect_1.RedirectToken(...mt.slice(1), config, accum);
package/dist/src/arg.d.ts CHANGED
@@ -2,10 +2,12 @@ import Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { AtomToken } from './atom';
4
4
  import { HiddenToken } from './hidden';
5
- import type { LintError } from '../base';
5
+ import type { LintError, AST } from '../base';
6
6
  /**
7
+ * argument wrapped in `{{{}}}`
8
+ *
7
9
  * `{{{}}}`包裹的参数
8
- * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
10
+ * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken[]]}`
9
11
  */
10
12
  export declare abstract class ArgToken extends Token {
11
13
  #private;
@@ -17,33 +19,41 @@ export declare abstract class ArgToken extends Token {
17
19
  abstract get firstElementChild(): AtomToken;
18
20
  abstract get lastElementChild(): Token;
19
21
  get type(): 'arg';
20
- /** 预设值 */
22
+ /** default value / 预设值 */
21
23
  get default(): string | false;
22
24
  set default(value: string | false);
23
25
  /** @param parts 以'|'分隔的各部分 */
24
26
  constructor(parts: readonly string[], config?: Parser.Config, accum?: Token[]);
25
27
  cloneNode(): this;
26
- /** 移除无效部分 */
28
+ /**
29
+ * Remove redundant parts
30
+ *
31
+ * 移除无效部分
32
+ */
27
33
  removeRedundant(): void;
28
34
  /**
29
35
  * @override
30
- * @param i 移除位置
36
+ * @param i position of the child node / 移除位置
31
37
  */
32
38
  removeAt(i: number): Token;
33
39
  /**
34
40
  * @override
35
- * @param token 待插入的子节点
36
- * @param i 插入位置
41
+ * @param token node to be inserted / 待插入的子节点
42
+ * @param i position to be inserted at / 插入位置
37
43
  */
38
44
  insertAt<T extends Token>(token: T, i?: number): T;
39
45
  /**
46
+ * Set the argument name
47
+ *
40
48
  * 设置参数名
41
- * @param name 新参数名
49
+ * @param name new argument name / 新参数名
42
50
  */
43
51
  setName(name: string): void;
44
52
  /**
53
+ * Set the default value
54
+ *
45
55
  * 设置预设值
46
- * @param value 预设值
56
+ * @param value default value / 预设值
47
57
  */
48
58
  setDefault(value: string | false): void;
49
59
  }
package/dist/src/arg.js CHANGED
@@ -11,18 +11,19 @@ const hidden_1 = require("./hidden");
11
11
  /* NOT FOR BROWSER */
12
12
  const constants_1 = require("../util/constants");
13
13
  const debug_1 = require("../util/debug");
14
- const html_1 = require("../util/html");
15
14
  /* NOT FOR BROWSER END */
16
15
  /**
16
+ * argument wrapped in `{{{}}}`
17
+ *
17
18
  * `{{{}}}`包裹的参数
18
- * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
19
+ * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken[]]}`
19
20
  */
20
21
  class ArgToken extends index_2.Token {
21
22
  /* NOT FOR BROWSER END */
22
23
  get type() {
23
24
  return 'arg';
24
25
  }
25
- /** 预设值 */
26
+ /** default value / 预设值 */
26
27
  get default() {
27
28
  return this.childNodes[1]?.text() ?? false;
28
29
  }
@@ -75,11 +76,13 @@ class ArgToken extends index_2.Token {
75
76
  }
76
77
  /** 设置name */
77
78
  #setName() {
78
- this.setAttribute('name', this.firstChild.toString(true).trim());
79
+ // eslint-disable-next-line no-unused-labels
80
+ LSP: this.setAttribute('name', this.firstChild.toString(true).trim());
79
81
  }
80
82
  /** @private */
81
83
  afterBuild() {
82
- this.#setName();
84
+ // eslint-disable-next-line no-unused-labels
85
+ LSP: this.#setName();
83
86
  super.afterBuild();
84
87
  /* NOT FOR BROWSER */
85
88
  const /** @implements */ argListener = ({ prevTarget }) => {
@@ -122,6 +125,12 @@ class ArgToken extends index_2.Token {
122
125
  print() {
123
126
  return super.print({ pre: '{{{', post: '}}}', sep: '|' });
124
127
  }
128
+ /** @private */
129
+ json(_, start = this.getAbsoluteIndex()) {
130
+ const json = super.json(undefined, start);
131
+ json['default'] = this.default;
132
+ return json;
133
+ }
125
134
  /* NOT FOR BROWSER */
126
135
  cloneNode() {
127
136
  const [name, ...cloned] = this.cloneChildNodes();
@@ -133,7 +142,11 @@ class ArgToken extends index_2.Token {
133
142
  return token;
134
143
  });
135
144
  }
136
- /** 移除无效部分 */
145
+ /**
146
+ * Remove redundant parts
147
+ *
148
+ * 移除无效部分
149
+ */
137
150
  removeRedundant() {
138
151
  debug_1.Shadow.run(() => {
139
152
  for (let i = this.length - 1; i > 1; i--) {
@@ -143,7 +156,7 @@ class ArgToken extends index_2.Token {
143
156
  }
144
157
  /**
145
158
  * @override
146
- * @param i 移除位置
159
+ * @param i position of the child node / 移除位置
147
160
  */
148
161
  removeAt(i) {
149
162
  if (i === 1) {
@@ -153,8 +166,8 @@ class ArgToken extends index_2.Token {
153
166
  }
154
167
  /**
155
168
  * @override
156
- * @param token 待插入的子节点
157
- * @param i 插入位置
169
+ * @param token node to be inserted / 待插入的子节点
170
+ * @param i position to be inserted at / 插入位置
158
171
  */
159
172
  insertAt(token, i = this.length) {
160
173
  i += i < 0 ? this.length : 0;
@@ -174,23 +187,29 @@ class ArgToken extends index_2.Token {
174
187
  return token;
175
188
  }
176
189
  /**
190
+ * Set the argument name
191
+ *
177
192
  * 设置参数名
178
- * @param name 新参数名
193
+ * @param name new argument name / 新参数名
179
194
  */
180
195
  setName(name) {
181
- const { childNodes } = index_1.default.parse(name, this.getAttribute('include'), 2, this.getAttribute('config'));
196
+ const { childNodes } = index_1.default
197
+ .parse(name, this.getAttribute('include'), 2, this.getAttribute('config'));
182
198
  this.firstChild.replaceChildren(...childNodes);
183
199
  }
184
200
  /**
201
+ * Set the default value
202
+ *
185
203
  * 设置预设值
186
- * @param value 预设值
204
+ * @param value default value / 预设值
187
205
  */
188
206
  setDefault(value) {
189
207
  if (value === false) {
190
208
  this.removeAt(1);
191
209
  return;
192
210
  }
193
- const root = index_1.default.parse(value, this.getAttribute('include'), undefined, this.getAttribute('config')), { childNodes: [, oldDefault] } = this;
211
+ const root = index_1.default
212
+ .parse(value, this.getAttribute('include'), undefined, this.getAttribute('config')), { childNodes: [, oldDefault] } = this;
194
213
  if (oldDefault) {
195
214
  oldDefault.replaceChildren(...root.childNodes);
196
215
  }
@@ -202,10 +221,10 @@ class ArgToken extends index_2.Token {
202
221
  /** @private */
203
222
  toHtmlInternal(opt) {
204
223
  if (this.length === 1) {
205
- const html = (0, html_1.font)(this, this.toString());
224
+ const html = this.toString();
206
225
  return opt?.nowrap ? html.replaceAll('\n', ' ') : html;
207
226
  }
208
- return (0, html_1.font)(this, this.childNodes[1].toHtmlInternal(opt));
227
+ return this.childNodes[1].toHtmlInternal(opt);
209
228
  }
210
229
  }
211
230
  exports.ArgToken = ArgToken;
@@ -2,7 +2,11 @@ import { Token } from './index';
2
2
  import type { Config } from '../base';
3
3
  declare const atomTypes: readonly ["arg-name", "attr-key", "attr-value", "ext-attr-dirty", "html-attr-dirty", "table-attr-dirty", "converter-flag", "converter-rule-variant", "converter-rule-to", "converter-rule-from", "invoke-function", "invoke-module", "template-name", "link-target", "param-line"];
4
4
  declare type AtomTypes = typeof atomTypes[number];
5
- /** 不会被继续解析的plain Token */
5
+ /**
6
+ * plain Token that will not be parsed further
7
+ *
8
+ * 不会被继续解析的plain Token
9
+ */
6
10
  export declare class AtomToken extends Token {
7
11
  #private;
8
12
  get type(): AtomTypes;
package/dist/src/atom.js CHANGED
@@ -23,7 +23,11 @@ const atomTypes = [
23
23
  'link-target',
24
24
  'param-line',
25
25
  ];
26
- /** 不会被继续解析的plain Token */
26
+ /**
27
+ * plain Token that will not be parsed further
28
+ *
29
+ * 不会被继续解析的plain Token
30
+ */
27
31
  class AtomToken extends index_1.Token {
28
32
  #type;
29
33
  get type() {