wikilint 2.0.0-beta.2 → 2.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 (60) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +16 -16
  3. package/dist/lib/element.d.ts +1 -0
  4. package/dist/lib/element.js +7 -7
  5. package/dist/lib/node.d.ts +1 -0
  6. package/dist/lib/node.js +13 -13
  7. package/dist/lib/text.js +1 -1
  8. package/dist/lib/title.js +2 -1
  9. package/dist/mixin/flagsParent.js +14 -0
  10. package/dist/mixin/magicLinkParent.js +14 -0
  11. package/dist/parser/braces.js +3 -1
  12. package/dist/parser/links.js +1 -1
  13. package/dist/src/arg.js +4 -4
  14. package/dist/src/attribute.d.ts +1 -4
  15. package/dist/src/attribute.js +8 -16
  16. package/dist/src/attributes.d.ts +2 -2
  17. package/dist/src/attributes.js +4 -3
  18. package/dist/src/converter.d.ts +7 -2
  19. package/dist/src/converter.js +4 -3
  20. package/dist/src/converterFlags.js +2 -2
  21. package/dist/src/extLink.d.ts +7 -2
  22. package/dist/src/extLink.js +8 -6
  23. package/dist/src/gallery.d.ts +1 -0
  24. package/dist/src/gallery.js +10 -3
  25. package/dist/src/heading.js +6 -4
  26. package/dist/src/html.js +5 -3
  27. package/dist/src/imageParameter.js +9 -8
  28. package/dist/src/imagemap.js +4 -3
  29. package/dist/src/index.js +7 -9
  30. package/dist/src/link/base.js +15 -16
  31. package/dist/src/link/category.d.ts +2 -2
  32. package/dist/src/link/category.js +2 -2
  33. package/dist/src/link/galleryImage.js +10 -10
  34. package/dist/src/link/index.d.ts +1 -1
  35. package/dist/src/magicLink.js +3 -2
  36. package/dist/src/nested.js +2 -2
  37. package/dist/src/nowiki/base.d.ts +2 -0
  38. package/dist/src/nowiki/base.js +4 -0
  39. package/dist/src/nowiki/comment.js +3 -3
  40. package/dist/src/nowiki/doubleUnderscore.js +3 -3
  41. package/dist/src/nowiki/index.js +2 -2
  42. package/dist/src/onlyinclude.js +5 -6
  43. package/dist/src/paramTag/index.js +2 -2
  44. package/dist/src/parameter.js +10 -5
  45. package/dist/src/pre.js +4 -3
  46. package/dist/src/table/index.d.ts +1 -8
  47. package/dist/src/table/index.js +7 -12
  48. package/dist/src/table/td.d.ts +0 -4
  49. package/dist/src/table/td.js +3 -3
  50. package/dist/src/table/trBase.d.ts +0 -2
  51. package/dist/src/table/trBase.js +0 -5
  52. package/dist/src/tagPair/ext.js +3 -1
  53. package/dist/src/tagPair/index.js +5 -5
  54. package/dist/src/transclude.d.ts +2 -2
  55. package/dist/src/transclude.js +33 -18
  56. package/dist/util/constants.js +4 -0
  57. package/dist/util/debug.js +11 -0
  58. package/i18n/zh-hans.json +2 -0
  59. package/i18n/zh-hant.json +2 -0
  60. package/package.json +2 -2
package/dist/index.d.ts CHANGED
@@ -24,7 +24,7 @@ export interface LintError {
24
24
  }
25
25
  declare interface Parser {
26
26
  config: string | Config;
27
- i18n?: string | Record<string, string>;
27
+ i18n: string | Record<string, string> | undefined;
28
28
  /**
29
29
  * 规范化页面标题
30
30
  * @param title 标题(含或不含命名空间前缀)
package/dist/index.js CHANGED
@@ -2,6 +2,8 @@
2
2
  /* eslint n/exports-style: 0 */
3
3
  const fs = require("fs");
4
4
  const path = require("path");
5
+ const debug_1 = require("./util/debug");
6
+ const constants_1 = require("./util/constants");
5
7
  /**
6
8
  * 从根路径require
7
9
  * @param file 文件名
@@ -11,14 +13,17 @@ const rootRequire = (file, dir) => require(file.startsWith('/') ? file : `../${f
11
13
  // eslint-disable-next-line @typescript-eslint/no-redeclare
12
14
  const Parser = {
13
15
  config: 'default',
14
- MAX_STAGE: 11,
16
+ i18n: undefined,
15
17
  /** @implements */
16
18
  getConfig() {
17
19
  if (typeof this.config === 'string') {
18
20
  this.config = rootRequire(this.config, 'config/');
19
21
  return this.getConfig();
20
22
  }
21
- return { ...this.config, excludes: [] };
23
+ return {
24
+ ...this.config,
25
+ excludes: [],
26
+ };
22
27
  },
23
28
  /** @implements */
24
29
  msg(msg, arg = '') {
@@ -35,14 +40,14 @@ const Parser = {
35
40
  return new Title(title, defaultNs, config, decode, selfLink);
36
41
  }
37
42
  const { Token } = require('./src/index');
38
- const token = this.run(() => new Token(title, config).parseOnce(0, include).parseOnce()), titleObj = new Title(String(token), defaultNs, config, decode, selfLink);
43
+ const token = debug_1.Shadow.run(() => new Token(title, config).parseOnce(0, include).parseOnce()), titleObj = new Title(String(token), defaultNs, config, decode, selfLink);
39
44
  return titleObj;
40
45
  },
41
46
  /** @implements */
42
- parse(wikitext, include, maxStage = Parser.MAX_STAGE, config = Parser.getConfig()) {
47
+ parse(wikitext, include, maxStage = constants_1.MAX_STAGE, config = Parser.getConfig()) {
43
48
  const { Token } = require('./src/index');
44
49
  let token;
45
- this.run(() => {
50
+ debug_1.Shadow.run(() => {
46
51
  token = new Token(wikitext.replace(/[\0\x7F]/gu, ''), config);
47
52
  try {
48
53
  token.parse(maxStage, include);
@@ -50,7 +55,7 @@ const Parser = {
50
55
  catch (e) {
51
56
  if (e instanceof Error) {
52
57
  const file = path.join(__dirname, '..', 'errors', new Date().toISOString()), stage = token.getAttribute('stage');
53
- fs.writeFileSync(file, stage === this.MAX_STAGE ? wikitext : String(token));
58
+ fs.writeFileSync(file, stage === constants_1.MAX_STAGE ? wikitext : String(token));
54
59
  fs.writeFileSync(`${file}.err`, e.stack);
55
60
  fs.writeFileSync(`${file}.json`, JSON.stringify({
56
61
  stage, include: token.getAttribute('include'), config: this.config,
@@ -61,18 +66,13 @@ const Parser = {
61
66
  });
62
67
  return token;
63
68
  },
64
- /** @implements */
65
- run(callback) {
66
- const result = callback();
67
- return result;
68
- },
69
69
  };
70
- const def = {}, immutable = new Set(['MAX_STAGE']), enumerable = new Set(['config', 'normalizeTitle', 'parse']);
70
+ const def = {}, enumerable = new Set([
71
+ 'normalizeTitle',
72
+ 'parse',
73
+ ]);
71
74
  for (const key in Parser) {
72
- if (immutable.has(key)) {
73
- def[key] = { enumerable: false, writable: false };
74
- }
75
- else if (!enumerable.has(key)) {
75
+ if (!enumerable.has(key)) {
76
76
  def[key] = { enumerable: false };
77
77
  }
78
78
  }
@@ -4,6 +4,7 @@ import type { AstNodes, Token } from '../internal';
4
4
  /** 类似HTMLElement */
5
5
  export declare abstract class AstElement extends AstNode {
6
6
  name?: string;
7
+ data: undefined;
7
8
  /** 子节点总数 */
8
9
  get length(): number;
9
10
  /**
@@ -22,7 +22,6 @@ const lintIgnoredExt = new Set([
22
22
  ]);
23
23
  /** 类似HTMLElement */
24
24
  class AstElement extends node_1.AstNode {
25
- name;
26
25
  /** 子节点总数 */
27
26
  get length() {
28
27
  return this.childNodes.length;
@@ -38,15 +37,15 @@ class AstElement extends node_1.AstNode {
38
37
  normalize() {
39
38
  const { childNodes } = this;
40
39
  for (let i = childNodes.length - 1; i >= 0; i--) {
41
- const cur = childNodes[i], prev = childNodes[i - 1];
42
- if (cur.type !== 'text' || this.getGaps(i - 1)) {
40
+ const { type, data } = childNodes[i], prev = childNodes[i - 1];
41
+ if (type !== 'text' || this.getGaps(i - 1)) {
43
42
  //
44
43
  }
45
- else if (cur.data === '') {
44
+ else if (data === '') {
46
45
  childNodes.splice(i, 1);
47
46
  }
48
47
  else if (prev?.type === 'text') {
49
- prev.setAttribute('data', prev.data + cur.data);
48
+ prev.setAttribute('data', prev.data + data);
50
49
  childNodes.splice(i, 1);
51
50
  }
52
51
  }
@@ -112,7 +111,8 @@ class AstElement extends node_1.AstNode {
112
111
  * @throws `RangeError` 对应位置的子节点不是文本节点
113
112
  */
114
113
  setText(str, i = 0) {
115
- const oldText = this.childNodes.at(i), { data } = oldText;
114
+ const oldText = this.childNodes.at(i);
115
+ const { data } = oldText;
116
116
  oldText.replaceData(str);
117
117
  return data;
118
118
  }
@@ -131,7 +131,7 @@ class AstElement extends node_1.AstNode {
131
131
  return [];
132
132
  }
133
133
  const errors = [];
134
- for (let i = 0, cur = start + this.getPadding(); i < this.length; i++) {
134
+ for (let i = 0, cur = start + this.getAttribute('padding'); i < this.length; i++) {
135
135
  const child = this.childNodes[i];
136
136
  errors.push(...child.lint(cur));
137
137
  cur += String(child).length + this.getGaps(i);
@@ -17,6 +17,7 @@ export interface CaretPosition {
17
17
  export declare abstract class AstNode {
18
18
  #private;
19
19
  type: TokenTypes | 'text';
20
+ data?: string | undefined;
20
21
  readonly childNodes: AstNodes[];
21
22
  /** 首位子节点 */
22
23
  get firstChild(): AstNodes | undefined;
package/dist/lib/node.js CHANGED
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AstNode = void 0;
4
4
  /** 类似Node */
5
5
  class AstNode {
6
- type;
7
6
  childNodes = [];
8
7
  #parentNode;
9
8
  /** 首位子节点 */
@@ -37,12 +36,11 @@ class AstNode {
37
36
  return this.#getDimension().width;
38
37
  }
39
38
  /** @private */
40
- hasAttribute(key) {
41
- return key in this;
42
- }
43
- /** @private */
44
39
  getAttribute(key) {
45
- return this.hasAttribute(key)
40
+ if (key === 'padding') {
41
+ return 0;
42
+ }
43
+ return key in this
46
44
  // @ts-expect-error noImplicitAny
47
45
  ? String(this[key])
48
46
  : undefined;
@@ -73,18 +71,20 @@ class AstNode {
73
71
  const str = String(this);
74
72
  if (index >= -str.length && index <= str.length) {
75
73
  const lines = str.slice(0, index).split('\n');
76
- return { top: lines.length - 1, left: lines.at(-1).length };
74
+ return {
75
+ top: lines.length - 1,
76
+ left: lines.at(-1).length,
77
+ };
77
78
  }
78
79
  return undefined;
79
80
  }
80
81
  /** 获取行数和最后一行的列数 */
81
82
  #getDimension() {
82
83
  const lines = String(this).split('\n');
83
- return { height: lines.length, width: lines.at(-1).length };
84
- }
85
- /** @private */
86
- getPadding() {
87
- return 0;
84
+ return {
85
+ height: lines.length,
86
+ width: lines.at(-1).length,
87
+ };
88
88
  }
89
89
  /** @private */
90
90
  getGaps(i) {
@@ -102,7 +102,7 @@ class AstNode {
102
102
  * @param parent 父节点
103
103
  */
104
104
  const getIndex = (end, parent) => childNodes.slice(0, end).reduce((acc, cur, i) => acc + String(cur).length + parent.getGaps(i), 0)
105
- + parent.getPadding();
105
+ + parent.getAttribute('padding');
106
106
  if (j === undefined) {
107
107
  const { parentNode } = this;
108
108
  if (parentNode) {
package/dist/lib/text.js CHANGED
@@ -33,7 +33,7 @@ const errorSyntax = /https?:\/\/|\{+|\}+|\[{2,}|\[(?![^[]*\])|(?<=^|\])([^[]*?)\
33
33
  /** 文本节点 */
34
34
  class AstText extends node_1.AstNode {
35
35
  type = 'text';
36
- data;
36
+ data = '';
37
37
  /** @param text 包含文本 */
38
38
  constructor(text) {
39
39
  super();
package/dist/lib/title.js CHANGED
@@ -47,7 +47,8 @@ class Title {
47
47
  fragment = title.slice(i + 1).trimEnd();
48
48
  title = title.slice(0, i).trim();
49
49
  }
50
- this.valid = Boolean(title || selfLink && fragment !== undefined)
50
+ this.valid = Boolean(title
51
+ || selfLink && fragment !== undefined)
51
52
  && !/\0\d+[eh!+-]\x7F|[<>[\]{}|]|%[\da-f]{2}/iu.test(title);
52
53
  this.fragment = fragment;
53
54
  }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.flagsParent = void 0;
4
+ /**
5
+ * ConverterToken
6
+ * @param constructor 基类
7
+ */
8
+ const flagsParent = (constructor) => {
9
+ /** 子节点含有ConverterFlagsToken的类 */
10
+ class FlagsParent extends constructor {
11
+ }
12
+ return FlagsParent;
13
+ };
14
+ exports.flagsParent = flagsParent;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.magicLinkParent = void 0;
4
+ /**
5
+ * ExtLinkToken
6
+ * @param constructor 基类
7
+ */
8
+ const magicLinkParent = (constructor) => {
9
+ /** 子节点含有MagicLinkParent的类 */
10
+ class MagicLinkParent extends constructor {
11
+ }
12
+ return MagicLinkParent;
13
+ };
14
+ exports.magicLinkParent = magicLinkParent;
@@ -16,7 +16,9 @@ const arg_1 = require("../src/arg");
16
16
  const parseBraces = (wikitext, config = Parser.getConfig(), accum = []) => {
17
17
  const source = `${config.excludes?.includes('heading') ? '' : '^(\0\\d+c\x7F)*={1,6}|'}\\[\\[|\\{{2,}|-\\{(?!\\{)`, { parserFunction: [, , , subst] } = config, stack = [], closes = { '=': '\n', '{': '\\}{2,}|\\|', '-': '\\}-', '[': '\\]\\]' }, marks = new Map([['!', '!'], ['!!', '+'], ['(!', '{'], ['!)', '}'], ['!-', '-'], ['=', '~']]);
18
18
  let regex = new RegExp(source, 'gmu'), mt = regex.exec(wikitext), moreBraces = wikitext.includes('}}'), lastIndex;
19
- while (mt || lastIndex !== undefined && lastIndex <= wikitext.length && stack.at(-1)?.[0]?.startsWith('=')) {
19
+ while (mt
20
+ || lastIndex !== undefined && lastIndex <= wikitext.length
21
+ && stack.at(-1)?.[0]?.startsWith('=')) {
20
22
  if (mt?.[1]) {
21
23
  const [, { length }] = mt;
22
24
  mt[0] = mt[0].slice(length);
@@ -41,7 +41,7 @@ const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
41
41
  s += `[[${x}`;
42
42
  continue;
43
43
  }
44
- const title = Parser.normalizeTitle(link, 0, false, config, true, true, true), { ns, valid } = title;
44
+ const title = Parser.normalizeTitle(link, 0, false, config, true, true, true), { ns, valid, } = title;
45
45
  if (!valid) {
46
46
  s += `[[${x}`;
47
47
  continue;
package/dist/src/arg.js CHANGED
@@ -46,12 +46,12 @@ class ArgToken extends index_1.Token {
46
46
  return `{{{${(0, string_1.text)(this.childNodes.slice(0, 2), '|')}}}}`;
47
47
  }
48
48
  /** @private */
49
- getPadding() {
50
- return 3;
49
+ getAttribute(key) {
50
+ return key === 'padding' ? 3 : super.getAttribute(key);
51
51
  }
52
52
  /** @private */
53
- getGaps(i) {
54
- return i < this.length - 1 ? 1 : 0;
53
+ getGaps() {
54
+ return 1;
55
55
  }
56
56
  /** @override */
57
57
  lint(start = this.getAbsoluteIndex()) {
@@ -12,6 +12,7 @@ export declare class AttributeToken extends Token {
12
12
  #private;
13
13
  type: AttributeTypes;
14
14
  name: string;
15
+ tag: string;
15
16
  childNodes: [AtomToken, Token];
16
17
  abstract get firstChild(): AtomToken;
17
18
  abstract get lastChild(): Token;
@@ -20,10 +21,6 @@ export declare class AttributeToken extends Token {
20
21
  abstract get previousSibling(): AtomToken | this | undefined;
21
22
  /** 引号是否匹配 */
22
23
  get balanced(): boolean;
23
- /** 标签名 */
24
- get tag(): string;
25
- /** getValue()的getter */
26
- get value(): string | true;
27
24
  /**
28
25
  * @param type 标签类型
29
26
  * @param tag 标签名
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AttributeToken = void 0;
4
4
  const lint_1 = require("../util/lint");
5
5
  const string_1 = require("../util/string");
6
+ const constants_1 = require("../util/constants");
6
7
  const Parser = require("../index");
7
8
  const index_1 = require("./index");
8
9
  const atom_1 = require("./atom");
@@ -119,19 +120,10 @@ const commonHtmlAttrs = new Set([
119
120
  class AttributeToken extends index_1.Token {
120
121
  #equal;
121
122
  #quotes;
122
- #tag;
123
123
  /** 引号是否匹配 */
124
124
  get balanced() {
125
125
  return !this.#equal || this.#quotes[0] === this.#quotes[1];
126
126
  }
127
- /** 标签名 */
128
- get tag() {
129
- return this.#tag;
130
- }
131
- /** getValue()的getter */
132
- get value() {
133
- return this.getValue();
134
- }
135
127
  /**
136
128
  * @param type 标签类型
137
129
  * @param tag 标签名
@@ -146,7 +138,7 @@ class AttributeToken extends index_1.Token {
146
138
  if (key === 'title' || tag === 'img' && key === 'alt') {
147
139
  valueToken = new index_1.Token(value, config, accum, {});
148
140
  valueToken.type = 'attr-value';
149
- valueToken.setAttribute('stage', Parser.MAX_STAGE - 1);
141
+ valueToken.setAttribute('stage', constants_1.MAX_STAGE - 1);
150
142
  }
151
143
  else if (tag === 'gallery' && key === 'caption') {
152
144
  const newConfig = {
@@ -174,7 +166,7 @@ class AttributeToken extends index_1.Token {
174
166
  this.append(keyToken, valueToken);
175
167
  this.#equal = equal;
176
168
  this.#quotes = quotes;
177
- this.#tag = tag;
169
+ this.tag = tag;
178
170
  this.setAttribute('name', (0, string_1.removeComment)(key).trim().toLowerCase());
179
171
  }
180
172
  /** @private */
@@ -183,7 +175,7 @@ class AttributeToken extends index_1.Token {
183
175
  this.#equal = this.buildFromStr(this.#equal, 'string');
184
176
  }
185
177
  if (this.parentNode) {
186
- this.#tag = this.parentNode.name;
178
+ this.setAttribute('tag', this.parentNode.name);
187
179
  }
188
180
  this.setAttribute('name', this.firstChild.text().trim().toLowerCase());
189
181
  }
@@ -199,12 +191,12 @@ class AttributeToken extends index_1.Token {
199
191
  return this.#equal ? `${super.text(`${this.#equal.trim()}"`)}"` : this.firstChild.text();
200
192
  }
201
193
  /** @private */
202
- getGaps(i) {
203
- return this.#equal && i === 0 ? this.#equal.length + (this.#quotes[0]?.length ?? 0) : 0;
194
+ getGaps() {
195
+ return this.#equal ? this.#equal.length + (this.#quotes[0]?.length ?? 0) : 0;
204
196
  }
205
197
  /** @override */
206
198
  lint(start = this.getAbsoluteIndex()) {
207
- const errors = super.lint(start), { balanced, firstChild, lastChild, type, name, value } = this, tag = this.#tag;
199
+ const errors = super.lint(start), { balanced, firstChild, lastChild, type, name, tag } = this, value = this.getValue();
208
200
  let rect;
209
201
  if (!balanced) {
210
202
  const root = this.getRootNode();
@@ -217,7 +209,7 @@ class AttributeToken extends index_1.Token {
217
209
  });
218
210
  }
219
211
  if (extAttrs[tag] && !extAttrs[tag].has(name)
220
- || (type !== 'ext-attr' && !/\{\{[^{]+\}\}/u.test(name) || tag in htmlAttrs)
212
+ || (type === 'ext-attr' ? tag in htmlAttrs : !/\{\{[^{]+\}\}/u.test(name))
221
213
  && !htmlAttrs[tag]?.has(name) && !/^(?:xmlns:[\w:.-]+|data-[^:]*)$/u.test(name)
222
214
  && (tag === 'meta' || tag === 'link' || !commonHtmlAttrs.has(name))) {
223
215
  rect ??= { start, ...this.getRootNode().posFromIndex(start) };
@@ -26,14 +26,14 @@ export declare class AttributesToken extends Token {
26
26
  * 所有指定属性名的AttributeToken
27
27
  * @param key 属性名
28
28
  */
29
- getAttrTokens(key: string): AttributeToken[];
29
+ getAttrTokens(key?: string): AttributeToken[];
30
30
  /**
31
31
  * 指定属性名的最后一个AttributeToken
32
32
  * @param key 属性名
33
33
  */
34
34
  getAttrToken(key: string): AttributeToken | undefined;
35
35
  /**
36
- * 获取标签属性
36
+ * 获取指定属性
37
37
  * @param key 属性键
38
38
  */
39
39
  getAttr(key: string): string | true | undefined;
@@ -66,17 +66,18 @@ class AttributesToken extends index_1.Token {
66
66
  * @param key 属性名
67
67
  */
68
68
  getAttrTokens(key) {
69
- return this.childNodes.filter(child => child instanceof attribute_1.AttributeToken && child.name === key.toLowerCase().trim());
69
+ return this.childNodes.filter(child => child instanceof attribute_1.AttributeToken && (!key || child.name === key.toLowerCase().trim()));
70
70
  }
71
71
  /**
72
72
  * 指定属性名的最后一个AttributeToken
73
73
  * @param key 属性名
74
74
  */
75
75
  getAttrToken(key) {
76
- return this.getAttrTokens(key).at(-1);
76
+ const tokens = this.getAttrTokens(key);
77
+ return tokens.at(-1);
77
78
  }
78
79
  /**
79
- * 获取标签属性
80
+ * 获取指定属性
80
81
  * @param key 属性键
81
82
  */
82
83
  getAttr(key) {
@@ -2,14 +2,18 @@ import * as Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { ConverterFlagsToken } from './converterFlags';
4
4
  import { ConverterRuleToken } from './converterRule';
5
+ declare const ConverterToken_base: (abstract new (...args: any[]) => {
6
+ readonly firstChild: Parser.ConverterFlagsToken;
7
+ toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
8
+ text(separator?: string | undefined): string;
9
+ }) & typeof Parser.Token;
5
10
  /**
6
11
  * 转换
7
12
  * @classdesc `{childNodes: [ConverterFlagsToken, ...ConverterRuleToken]}`
8
13
  */
9
- export declare class ConverterToken extends Token {
14
+ export declare class ConverterToken extends ConverterToken_base {
10
15
  readonly type = "converter";
11
16
  childNodes: [ConverterFlagsToken, ...ConverterRuleToken[]];
12
- abstract get firstChild(): ConverterFlagsToken;
13
17
  abstract get lastChild(): ConverterFlagsToken | ConverterRuleToken;
14
18
  /**
15
19
  * @param flags 转换类型标记
@@ -19,3 +23,4 @@ export declare class ConverterToken extends Token {
19
23
  /** @override */
20
24
  text(): string;
21
25
  }
26
+ export {};
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConverterToken = void 0;
4
4
  const string_1 = require("../util/string");
5
+ const flagsParent_1 = require("../mixin/flagsParent");
5
6
  const Parser = require("../index");
6
7
  const index_1 = require("./index");
7
8
  const converterFlags_1 = require("./converterFlags");
@@ -10,7 +11,7 @@ const converterRule_1 = require("./converterRule");
10
11
  * 转换
11
12
  * @classdesc `{childNodes: [ConverterFlagsToken, ...ConverterRuleToken]}`
12
13
  */
13
- class ConverterToken extends index_1.Token {
14
+ class ConverterToken extends (0, flagsParent_1.flagsParent)(index_1.Token) {
14
15
  type = 'converter';
15
16
  /**
16
17
  * @param flags 转换类型标记
@@ -38,8 +39,8 @@ class ConverterToken extends index_1.Token {
38
39
  return `-{${flags.text()}|${(0, string_1.text)(rules, ';')}}-`;
39
40
  }
40
41
  /** @private */
41
- getPadding() {
42
- return 2;
42
+ getAttribute(key) {
43
+ return key === 'padding' ? 2 : super.getAttribute(key);
43
44
  }
44
45
  /** @private */
45
46
  getGaps(i) {
@@ -31,8 +31,8 @@ class ConverterFlagsToken extends index_1.Token {
31
31
  return super.text(';');
32
32
  }
33
33
  /** @private */
34
- getGaps(i) {
35
- return i < this.length - 1 ? 1 : 0;
34
+ getGaps() {
35
+ return 1;
36
36
  }
37
37
  /** 获取未知的转换类型标记 */
38
38
  getUnknownFlags() {
@@ -1,15 +1,19 @@
1
1
  import * as Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { MagicLinkToken } from './magicLink';
4
+ declare const ExtLinkToken_base: (abstract new (...args: any[]) => {
5
+ readonly firstChild: Parser.MagicLinkToken;
6
+ toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
7
+ text(separator?: string | undefined): string;
8
+ }) & typeof Parser.Token;
4
9
  /**
5
10
  * 外链
6
11
  * @classdesc `{childNodes: [MagicLinkToken, ?Token]}`
7
12
  */
8
- export declare class ExtLinkToken extends Token {
13
+ export declare class ExtLinkToken extends ExtLinkToken_base {
9
14
  #private;
10
15
  readonly type = "ext-link";
11
16
  childNodes: [MagicLinkToken] | [MagicLinkToken, Token];
12
- abstract get firstChild(): MagicLinkToken;
13
17
  abstract get lastChild(): Token;
14
18
  /**
15
19
  * @param url 网址
@@ -20,3 +24,4 @@ export declare class ExtLinkToken extends Token {
20
24
  /** @override */
21
25
  text(): string;
22
26
  }
27
+ export {};
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ExtLinkToken = void 0;
4
+ const constants_1 = require("../util/constants");
5
+ const magicLinkParent_1 = require("../mixin/magicLinkParent");
4
6
  const Parser = require("../index");
5
7
  const index_1 = require("./index");
6
8
  const magicLink_1 = require("./magicLink");
@@ -8,7 +10,7 @@ const magicLink_1 = require("./magicLink");
8
10
  * 外链
9
11
  * @classdesc `{childNodes: [MagicLinkToken, ?Token]}`
10
12
  */
11
- class ExtLinkToken extends index_1.Token {
13
+ class ExtLinkToken extends (0, magicLinkParent_1.magicLinkParent)(index_1.Token) {
12
14
  type = 'ext-link';
13
15
  #space;
14
16
  /**
@@ -23,7 +25,7 @@ class ExtLinkToken extends index_1.Token {
23
25
  if (text) {
24
26
  const inner = new index_1.Token(text, config, accum, {});
25
27
  inner.type = 'ext-link-text';
26
- inner.setAttribute('stage', Parser.MAX_STAGE - 1);
28
+ inner.setAttribute('stage', constants_1.MAX_STAGE - 1);
27
29
  this.insertAt(inner);
28
30
  }
29
31
  }
@@ -39,12 +41,12 @@ class ExtLinkToken extends index_1.Token {
39
41
  return `[${super.text(' ')}]`;
40
42
  }
41
43
  /** @private */
42
- getPadding() {
43
- return 1;
44
+ getAttribute(key) {
45
+ return key === 'padding' ? 1 : super.getAttribute(key);
44
46
  }
45
47
  /** @private */
46
- getGaps(i) {
47
- return i === 0 ? this.#space.length : 0;
48
+ getGaps() {
49
+ return this.#space.length;
48
50
  }
49
51
  }
50
52
  exports.ExtLinkToken = ExtLinkToken;
@@ -9,6 +9,7 @@ import type { AstText, AttributesToken, ExtToken } from '../internal';
9
9
  * @classdesc `{childNodes: ...(GalleryImageToken|HiddenToken|AstText)}`
10
10
  */
11
11
  export declare class GalleryToken extends Token {
12
+ #private;
12
13
  readonly type = "ext-inner";
13
14
  name: 'gallery';
14
15
  childNodes: (GalleryImageToken | HiddenToken | AstText)[];
@@ -23,7 +23,7 @@ class GalleryToken extends index_1.Token {
23
23
  continue;
24
24
  }
25
25
  const [, file, alt] = matches;
26
- if (this.normalizeTitle(file, 6, true, true).valid) {
26
+ if (this.#checkFile(file)) {
27
27
  super.insertAt(new galleryImage_1.GalleryImageToken('gallery', file, alt, config, accum));
28
28
  }
29
29
  else {
@@ -31,6 +31,13 @@ class GalleryToken extends index_1.Token {
31
31
  }
32
32
  }
33
33
  }
34
+ /**
35
+ * 检查文件名是否有效
36
+ * @param file 文件名
37
+ */
38
+ #checkFile(file) {
39
+ return this.normalizeTitle(file, 6, true, true).valid;
40
+ }
34
41
  /** @private */
35
42
  toString(omit) {
36
43
  return super.toString(omit, '\n');
@@ -40,8 +47,8 @@ class GalleryToken extends index_1.Token {
40
47
  return super.text('\n').replace(/\n\s*\n/gu, '\n');
41
48
  }
42
49
  /** @private */
43
- getGaps(i) {
44
- return i < this.length - 1 ? 1 : 0;
50
+ getGaps() {
51
+ return 1;
45
52
  }
46
53
  /** @override */
47
54
  lint(start = this.getAbsoluteIndex()) {
@@ -43,12 +43,14 @@ class HeadingToken extends index_1.Token {
43
43
  return `${equals}${this.firstChild.text()}${equals}`;
44
44
  }
45
45
  /** @private */
46
- getPadding() {
47
- return super.getPadding() + this.level;
46
+ getAttribute(key) {
47
+ return key === 'padding'
48
+ ? super.getAttribute('padding') + this.level
49
+ : super.getAttribute(key);
48
50
  }
49
51
  /** @private */
50
- getGaps(i) {
51
- return i === 0 ? this.level : 0;
52
+ getGaps() {
53
+ return this.level;
52
54
  }
53
55
  /** @override */
54
56
  lint(start = this.getAbsoluteIndex()) {