wikiparser-node 1.13.1 → 1.13.2

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 (46) hide show
  1. package/bundle/bundle.min.js +37 -0
  2. package/dist/addon/token.js +2 -2
  3. package/dist/base.d.ts +0 -1
  4. package/dist/index.js +5 -0
  5. package/dist/mixin/singleLine.d.ts +1 -0
  6. package/dist/mixin/singleLine.js +10 -2
  7. package/dist/parser/braces.js +5 -5
  8. package/dist/parser/commentAndExt.js +1 -1
  9. package/dist/parser/converter.js +4 -2
  10. package/dist/parser/externalLinks.js +2 -2
  11. package/dist/parser/hrAndDoubleUnderscore.js +2 -1
  12. package/dist/parser/links.js +4 -2
  13. package/dist/parser/magicLinks.js +2 -2
  14. package/dist/parser/redirect.js +2 -1
  15. package/dist/src/attributes.d.ts +12 -10
  16. package/dist/src/gallery.d.ts +8 -6
  17. package/dist/src/gallery.js +0 -1
  18. package/dist/src/imagemap.d.ts +8 -6
  19. package/dist/src/imagemap.js +1 -2
  20. package/dist/src/imagemapLink.js +1 -1
  21. package/dist/src/index.d.ts +1 -2
  22. package/dist/src/index.js +1 -0
  23. package/dist/src/link/galleryImage.js +1 -1
  24. package/dist/src/nested.d.ts +10 -9
  25. package/dist/src/nested.js +28 -23
  26. package/dist/src/paramTag/index.d.ts +1 -1
  27. package/dist/src/paramTag/index.js +37 -20
  28. package/dist/src/paramTag/inputbox.d.ts +1 -1
  29. package/dist/src/paramTag/inputbox.js +5 -17
  30. package/dist/src/pre.d.ts +8 -6
  31. package/dist/src/pre.js +0 -1
  32. package/dist/src/table/base.js +1 -1
  33. package/dist/src/table/index.d.ts +1 -0
  34. package/dist/src/table/index.js +0 -1
  35. package/dist/src/tagPair/ext.d.ts +2 -1
  36. package/dist/src/tagPair/ext.js +8 -6
  37. package/dist/src/transclude.d.ts +8 -6
  38. package/dist/src/transclude.js +10 -1
  39. package/extensions/dist/base.js +163 -0
  40. package/extensions/dist/codejar.js +53 -0
  41. package/extensions/dist/editor.js +159 -0
  42. package/extensions/dist/highlight.js +30 -0
  43. package/extensions/dist/lint.js +72 -0
  44. package/extensions/editor.css +59 -0
  45. package/extensions/ui.css +162 -0
  46. package/package.json +8 -1
@@ -9,7 +9,6 @@ const noinclude_1 = require("./nowiki/noinclude");
9
9
  const debug_1 = require("../util/debug");
10
10
  const constants_1 = require("../util/constants");
11
11
  const html_1 = require("../util/html");
12
- /* NOT FOR BROWSER END */
13
12
  /**
14
13
  * gallery标签
15
14
  * @classdesc `{childNodes: ...(GalleryImageToken|NoincludeToken|AstText)}`
@@ -5,21 +5,22 @@ import { GalleryImageToken } from './link/galleryImage';
5
5
  import { ImagemapLinkToken } from './imagemapLink';
6
6
  import type { LintError } from '../base';
7
7
  import type { AstText, AttributesToken, ExtToken, AstNodes } from '../internal';
8
+ declare type Child = GalleryImageToken | NoincludeToken;
8
9
  /**
9
10
  * `<imagemap>`
10
11
  * @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
11
12
  */
12
13
  export declare abstract class ImagemapToken extends Token {
13
14
  readonly name: 'imagemap';
14
- readonly childNodes: readonly (GalleryImageToken | NoincludeToken | ImagemapLinkToken | AstText)[];
15
- abstract get firstChild(): NoincludeToken | GalleryImageToken | undefined;
16
- abstract get lastChild(): GalleryImageToken | NoincludeToken | ImagemapLinkToken | AstText | undefined;
15
+ readonly childNodes: readonly (Child | ImagemapLinkToken | AstText)[];
16
+ abstract get firstChild(): Child | undefined;
17
+ abstract get lastChild(): Child | ImagemapLinkToken | AstText | undefined;
17
18
  abstract get nextSibling(): undefined;
18
19
  abstract get previousSibling(): AttributesToken;
19
20
  abstract get parentNode(): ExtToken | undefined;
20
- abstract get children(): (GalleryImageToken | NoincludeToken | ImagemapLinkToken)[];
21
- abstract get firstElementChild(): NoincludeToken | GalleryImageToken | undefined;
22
- abstract get lastElementChild(): GalleryImageToken | NoincludeToken | ImagemapLinkToken | undefined;
21
+ abstract get children(): (Child | ImagemapLinkToken)[];
22
+ abstract get firstElementChild(): Child | undefined;
23
+ abstract get lastElementChild(): Child | ImagemapLinkToken | undefined;
23
24
  abstract get nextElementSibling(): undefined;
24
25
  abstract get previousElementSibling(): AttributesToken;
25
26
  abstract get parentElement(): ExtToken | undefined;
@@ -45,3 +46,4 @@ export declare abstract class ImagemapToken extends Token {
45
46
  removeAt(i: number): AstNodes;
46
47
  cloneNode(): this;
47
48
  }
49
+ export {};
@@ -12,7 +12,6 @@ const imagemapLink_1 = require("./imagemapLink");
12
12
  /* NOT FOR BROWSER */
13
13
  const constants_1 = require("../util/constants");
14
14
  const singleLine_1 = require("../mixin/singleLine");
15
- /* NOT FOR BROWSER END */
16
15
  /**
17
16
  * `<imagemap>`
18
17
  * @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
@@ -34,7 +33,7 @@ class ImagemapToken extends index_2.Token {
34
33
  if (!inner) {
35
34
  return;
36
35
  }
37
- const lines = inner.split('\n'), protocols = new Set(config.protocol.split('|')), SingleLineNoincludeToken = (0, singleLine_1.singleLine)(noinclude_1.NoincludeToken);
36
+ const lines = inner.split('\n'), protocols = new Set(config.protocol.split('|')), SingleLineNoincludeToken = (0, singleLine_1.singleLine)()(noinclude_1.NoincludeToken);
38
37
  let first = true, error = false;
39
38
  for (const line of lines) {
40
39
  const trimmed = line.trim();
@@ -50,7 +50,7 @@ const singleLine_1 = require("../mixin/singleLine");
50
50
  * @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
51
51
  */
52
52
  let ImagemapLinkToken = (() => {
53
- let _classDecorators = [fixed_1.fixedToken, singleLine_1.singleLine];
53
+ let _classDecorators = [fixed_1.fixedToken, (0, singleLine_1.singleLine)()];
54
54
  let _classDescriptor;
55
55
  let _classExtraInitializers = [];
56
56
  let _classThis;
@@ -8,7 +8,6 @@ import { Ranges } from '../lib/ranges';
8
8
  import { AstRange } from '../lib/range';
9
9
  import type { Range } from '../lib/ranges';
10
10
  import type { CaretPosition } from '../lib/node';
11
- export type TagToken = IncludeToken | ExtToken | HtmlToken;
12
11
  /**
13
12
  * 所有节点的基类
14
13
  * @classdesc `{childNodes: ...(AstText|Token)}`
@@ -59,7 +58,7 @@ export declare class Token extends AstElement {
59
58
  createElement(tagName: string, options?: {
60
59
  selfClosing?: boolean;
61
60
  closing?: boolean;
62
- }): TagToken;
61
+ }): IncludeToken | ExtToken | HtmlToken;
63
62
  /**
64
63
  * 创建纯文本节点
65
64
  * @param data 文本内容
package/dist/src/index.js CHANGED
@@ -55,6 +55,7 @@ const assert = require("assert/strict");
55
55
  const html_1 = require("../util/html");
56
56
  const ranges_1 = require("../lib/ranges");
57
57
  const range_1 = require("../lib/range");
58
+ /* NOT FOR BROWSER */
58
59
  /**
59
60
  * 可接受的Token类型
60
61
  * @param value 可接受的Token类型
@@ -45,7 +45,7 @@ const singleLine_1 = require("../../mixin/singleLine");
45
45
  const imageParameter_1 = require("../imageParameter");
46
46
  /** 图库图片 */
47
47
  let GalleryImageToken = (() => {
48
- let _classDecorators = [singleLine_1.singleLine];
48
+ let _classDecorators = [(0, singleLine_1.singleLine)()];
49
49
  let _classDescriptor;
50
50
  let _classExtraInitializers = [];
51
51
  let _classThis;
@@ -2,9 +2,9 @@ import Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { ExtToken } from './tagPair/ext';
4
4
  import { NoincludeToken } from './nowiki/noinclude';
5
- import { CommentToken } from './nowiki/comment';
6
5
  import type { LintError } from '../base';
7
- import type { AttributesToken } from './attributes';
6
+ import type { CommentToken, AttributesToken, IncludeToken, ArgToken, TranscludeToken } from '../internal';
7
+ declare type Child = ExtToken | NoincludeToken | CommentToken | IncludeToken | ArgToken | TranscludeToken;
8
8
  /**
9
9
  * 嵌套式的扩展标签
10
10
  * @classdesc `{childNodes: ...ExtToken|NoincludeToken|CommentToken}`
@@ -12,15 +12,15 @@ import type { AttributesToken } from './attributes';
12
12
  export declare abstract class NestedToken extends Token {
13
13
  #private;
14
14
  readonly name: string;
15
- readonly childNodes: readonly (ExtToken | NoincludeToken | CommentToken)[];
16
- abstract get firstChild(): ExtToken | NoincludeToken | CommentToken | undefined;
17
- abstract get lastChild(): ExtToken | NoincludeToken | CommentToken | undefined;
15
+ readonly childNodes: readonly Child[];
16
+ abstract get firstChild(): Child | undefined;
17
+ abstract get lastChild(): Child | undefined;
18
18
  abstract get nextSibling(): undefined;
19
19
  abstract get previousSibling(): AttributesToken;
20
20
  abstract get parentNode(): ExtToken | undefined;
21
- abstract get children(): (ExtToken | NoincludeToken | CommentToken)[];
22
- abstract get firstElementChild(): ExtToken | NoincludeToken | CommentToken | undefined;
23
- abstract get lastElementChild(): ExtToken | NoincludeToken | CommentToken | undefined;
21
+ abstract get children(): Child[];
22
+ abstract get firstElementChild(): Child | undefined;
23
+ abstract get lastElementChild(): Child | undefined;
24
24
  abstract get previousElementSibling(): AttributesToken;
25
25
  abstract get nextElementSibling(): undefined;
26
26
  abstract get parentElement(): ExtToken | undefined;
@@ -29,7 +29,7 @@ export declare abstract class NestedToken extends Token {
29
29
  * @param regex 内层正则
30
30
  * @param tags 内层标签名
31
31
  */
32
- constructor(wikitext: string | undefined, regex: RegExp, tags: readonly string[], config?: Parser.Config, accum?: Token[]);
32
+ constructor(wikitext: string | undefined, regex: RegExp | boolean, tags: readonly string[], config?: Parser.Config, accum?: Token[]);
33
33
  /**
34
34
  * @override
35
35
  * @param token 待插入的子节点
@@ -38,3 +38,4 @@ export declare abstract class NestedToken extends Token {
38
38
  insertAt<T extends Token>(token: T, i?: number): T;
39
39
  cloneNode(): this;
40
40
  }
41
+ export {};
@@ -3,21 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NestedToken = void 0;
4
4
  const lint_1 = require("../util/lint");
5
5
  const rect_1 = require("../lib/rect");
6
+ const commentAndExt_1 = require("../parser/commentAndExt");
7
+ const braces_1 = require("../parser/braces");
6
8
  const index_1 = require("../index");
7
9
  const index_2 = require("./index");
8
10
  const ext_1 = require("./tagPair/ext");
9
11
  const noinclude_1 = require("./nowiki/noinclude");
10
- const comment_1 = require("./nowiki/comment");
11
12
  /* NOT FOR BROWSER */
12
13
  const debug_1 = require("../util/debug");
13
14
  const constants_1 = require("../util/constants");
14
- /* NOT FOR BROWSER END */
15
+ const childTypes = new Set(['comment', 'include', 'arg', 'template', 'magic-word']);
15
16
  /**
16
17
  * 嵌套式的扩展标签
17
18
  * @classdesc `{childNodes: ...ExtToken|NoincludeToken|CommentToken}`
18
19
  */
19
20
  class NestedToken extends index_2.Token {
20
- /* NOT FOR BROWSER */
21
21
  #tags;
22
22
  #regex;
23
23
  /* NOT FOR BROWSER END */
@@ -29,41 +29,46 @@ class NestedToken extends index_2.Token {
29
29
  * @param tags 内层标签名
30
30
  */
31
31
  constructor(wikitext, regex, tags, config = index_1.default.getConfig(), accum = []) {
32
- wikitext = wikitext?.replace(regex, (comment, name, attr, inner, closing) => {
33
- const str = `\0${accum.length + 1}${name ? 'e' : 'c'}\x7F`;
34
- if (name) {
35
- // @ts-expect-error abstract class
36
- new ext_1.ExtToken(name, attr, inner, closing, config, accum);
37
- }
38
- else {
39
- const closed = comment.endsWith('-->');
32
+ if (typeof regex === 'boolean') {
33
+ const placeholder = Symbol('InputboxToken'), { length } = accum;
34
+ accum.push(placeholder);
35
+ wikitext &&= (0, commentAndExt_1.parseCommentAndExt)(wikitext, config, accum, regex);
36
+ wikitext &&= (0, braces_1.parseBraces)(wikitext, config, accum);
37
+ accum.splice(length, 1);
38
+ }
39
+ else {
40
+ wikitext &&= wikitext.replace(regex, (_, name, attr, inner, closing) => {
41
+ const str = `\0${accum.length + 1}e\x7F`;
40
42
  // @ts-expect-error abstract class
41
- new comment_1.CommentToken(comment.slice(4, closed ? -3 : undefined), closed, config, accum);
42
- }
43
- return str;
44
- }).replace(/(^|\0\d+[cne]\x7F)([^\0]+)(?=$|\0\d+[cne]\x7F)/gu, (_, lead, substr) => {
43
+ new ext_1.ExtToken(name, attr, inner, closing, config, false, accum);
44
+ return str;
45
+ });
46
+ }
47
+ wikitext &&= wikitext.replace(/(^|\0\d+.\x7F)([^\0]+)(?=$|\0\d+.\x7F)/gu, (_, lead, substr) => {
45
48
  // @ts-expect-error abstract class
46
49
  new noinclude_1.NoincludeToken(substr, config, accum);
47
50
  return `${lead}\0${accum.length}n\x7F`;
48
51
  });
49
- super(wikitext, config, accum, {
50
- NoincludeToken: ':', ExtToken: ':',
51
- });
52
- /* NOT FOR BROWSER */
52
+ super(wikitext, config, accum, typeof regex === 'boolean' ? { 'Stage-2': ':', '!HeadingToken': '' } : { NoincludeToken: ':', ExtToken: ':' });
53
53
  this.#tags = [...tags];
54
54
  this.#regex = regex;
55
55
  }
56
56
  /** @private */
57
57
  lint(start = this.getAbsoluteIndex(), re) {
58
- const rect = new rect_1.BoundingRect(this, start);
58
+ const rect = new rect_1.BoundingRect(this, start), noinclude = this.#regex ? 'includeonly' : 'noinclude', regex = typeof this.#regex === 'boolean'
59
+ ? new RegExp(String.raw `^(?:<${noinclude}(?:\s[^>]*)?/?>|</${noinclude}\s*>)$`, 'iu')
60
+ : /^<!--.*-->$/su;
59
61
  return [
60
62
  ...super.lint(start, re),
61
63
  ...this.childNodes.filter(child => {
62
- if (child.type === 'ext' || child.type === 'comment') {
64
+ if (child.type === 'ext') {
65
+ return !this.#tags.includes(child.name);
66
+ }
67
+ else if (childTypes.has(child.type)) {
63
68
  return false;
64
69
  }
65
70
  const str = child.toString().trim();
66
- return str && !/^<!--.*-->$/su.test(str);
71
+ return str && !regex.test(str);
67
72
  }).map(child => {
68
73
  const e = (0, lint_1.generateForChild)(child, rect, 'no-ignored', index_1.default.msg('invalid content in <$1>', this.name));
69
74
  e.suggestions = [
@@ -89,7 +94,7 @@ class NestedToken extends index_2.Token {
89
94
  * @param i 插入位置
90
95
  */
91
96
  insertAt(token, i) {
92
- if (typeof token !== 'string' && token.type === 'ext' && !this.#tags.includes(token.name)) {
97
+ if (!debug_1.Shadow.running && token.type === 'ext' && !this.#tags.includes(token.name)) {
93
98
  this.constructorError(`can only have ${this.#tags.join(' or ')} tags as child nodes`);
94
99
  }
95
100
  return super.insertAt(token, i);
@@ -23,6 +23,6 @@ export declare abstract class ParamTagToken extends Token {
23
23
  abstract get parentElement(): ExtToken | undefined;
24
24
  get type(): 'ext-inner';
25
25
  /** @class */
26
- constructor(wikitext?: string, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
26
+ constructor(include: boolean, wikitext?: string, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
27
27
  cloneNode(): this;
28
28
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ParamTagToken = void 0;
4
4
  const lint_1 = require("../../util/lint");
5
5
  const rect_1 = require("../../lib/rect");
6
+ const commentAndExt_1 = require("../../parser/commentAndExt");
6
7
  const index_1 = require("../../index");
7
8
  const index_2 = require("../index");
8
9
  const atom_1 = require("../atom");
@@ -21,16 +22,20 @@ class ParamTagToken extends index_2.Token {
21
22
  return 'ext-inner';
22
23
  }
23
24
  /** @class */
24
- constructor(wikitext, config = index_1.default.getConfig(), accum = [], acceptable = {}) {
25
+ constructor(include, wikitext, config = index_1.default.getConfig(), accum = [], acceptable) {
25
26
  super(undefined, config, accum, {
26
27
  AtomToken: ':',
27
28
  });
28
29
  if (wikitext) {
29
- const SingleLineAtomToken = (0, singleLine_1.singleLine)(atom_1.AtomToken);
30
- this.append(...wikitext.split('\n').map(line => new SingleLineAtomToken(line, 'param-line', config, accum, {
31
- AstText: ':', ...acceptable,
30
+ const SingleLineAtomToken = (0, singleLine_1.singleLine)(!acceptable)(atom_1.AtomToken);
31
+ this.append(...wikitext.split('\n')
32
+ .map(line => acceptable ? line : (0, commentAndExt_1.parseCommentAndExt)(line, config, accum, include))
33
+ .map(line => new SingleLineAtomToken(line, 'param-line', config, accum, {
34
+ 'Stage-1': ':', ...acceptable,
32
35
  })));
33
36
  }
37
+ accum.splice(accum.indexOf(this), 1);
38
+ accum.push(this);
34
39
  }
35
40
  /** @private */
36
41
  toString(skip) {
@@ -46,21 +51,33 @@ class ParamTagToken extends index_2.Token {
46
51
  }
47
52
  /** @private */
48
53
  lint(start = this.getAbsoluteIndex()) {
49
- const rect = new rect_1.BoundingRect(this, start);
50
- return this.childNodes.filter(child => {
51
- const childNodes = child.childNodes.filter(({ type }) => type !== 'comment'), i = childNodes.findIndex(({ type }) => type !== 'text'), str = childNodes.slice(0, i >= 0 ? i : undefined).map(String).join('');
52
- return str && !(i >= 0 ? /^[a-z]+(?:\[\])?\s*(?:=|$)/iu : /^[a-z]+(?:\[\])?\s*=/iu).test(str);
53
- }).map(child => {
54
- const e = (0, lint_1.generateForChild)(child, rect, 'no-ignored', index_1.default.msg('invalid parameter of <$1>', this.name));
55
- e.suggestions = [
56
- {
57
- desc: 'remove',
58
- range: [e.startIndex, e.endIndex],
59
- text: '',
60
- },
61
- ];
62
- return e;
63
- });
54
+ const rect = new rect_1.BoundingRect(this, start), msg = index_1.default.msg('invalid parameter of <$1>', this.name), errors = [];
55
+ for (const child of this.childNodes) {
56
+ const grandChildren = child.childNodes
57
+ .filter(({ type }) => type !== 'comment' && type !== 'include' && type !== 'noinclude');
58
+ if (grandChildren.some(({ type }) => type === 'ext')) {
59
+ errors.push((0, lint_1.generateForChild)(child, rect, 'no-ignored', msg));
60
+ }
61
+ else {
62
+ const i = grandChildren.findIndex(({ type }) => type !== 'text'), str = grandChildren.slice(0, i >= 0 ? i : undefined).map(String).join('');
63
+ if (str && !(i >= 0 ? /^[a-z]+(?:\[\])?\s*(?:=|$)/iu : /^[a-z]+(?:\[\])?\s*=/iu).test(str)) {
64
+ const e = (0, lint_1.generateForChild)(child, rect, 'no-ignored', msg);
65
+ e.suggestions = [
66
+ {
67
+ desc: 'remove',
68
+ range: [e.startIndex, e.endIndex],
69
+ text: '',
70
+ },
71
+ ];
72
+ errors.push(e);
73
+ }
74
+ else {
75
+ errors.push(...child.lint(start, false));
76
+ }
77
+ }
78
+ start += child.toString().length + 1;
79
+ }
80
+ return errors;
64
81
  }
65
82
  /** @private */
66
83
  print() {
@@ -70,7 +87,7 @@ class ParamTagToken extends index_2.Token {
70
87
  cloneNode() {
71
88
  const cloned = this.cloneChildNodes();
72
89
  return debug_1.Shadow.run(() => {
73
- const C = this.constructor, token = new C(undefined, this.getAttribute('config'));
90
+ const C = this.constructor, token = new C(this.getAttribute('include'), undefined, this.getAttribute('config'));
74
91
  token.append(...cloned);
75
92
  return token;
76
93
  });
@@ -4,5 +4,5 @@ import type { Token } from '../index';
4
4
  /** `<inputbox>` */
5
5
  export declare abstract class InputboxToken extends ParamTagToken {
6
6
  /** @class */
7
- constructor(wikitext?: string, config?: Parser.Config, accum?: Token[]);
7
+ constructor(include: boolean, wikitext?: string, config?: Parser.Config, accum?: Token[]);
8
8
  }
@@ -1,36 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InputboxToken = void 0;
4
+ const commentAndExt_1 = require("../../parser/commentAndExt");
4
5
  const braces_1 = require("../../parser/braces");
5
6
  const index_1 = require("../../index");
6
7
  const index_2 = require("./index");
7
- const comment_1 = require("../nowiki/comment");
8
8
  /* NOT FOR BROWSER */
9
9
  const constants_1 = require("../../util/constants");
10
10
  /* NOT FOR BROWSER END */
11
- /**
12
- * 解析注释
13
- * @param wikitext 维基文本
14
- * @param config
15
- * @param accum
16
- */
17
- const parseComment = (wikitext, config, accum) => wikitext.replace(/<!--.*?(?:-->|$)/gsu, comment => {
18
- const str = `\0${accum.length + 1}c\x7F`, closed = comment.endsWith('-->');
19
- // @ts-expect-error abstract class
20
- new comment_1.CommentToken(comment.slice(4, closed ? -3 : undefined), closed, config, accum);
21
- return str;
22
- });
23
11
  /** `<inputbox>` */
24
12
  class InputboxToken extends index_2.ParamTagToken {
25
13
  /** @class */
26
- constructor(wikitext, config = index_1.default.getConfig(), accum = []) {
27
- wikitext &&= parseComment(wikitext, config, accum);
14
+ constructor(include, wikitext, config = index_1.default.getConfig(), accum = []) {
28
15
  const placeholder = Symbol('InputboxToken'), { length } = accum;
29
16
  accum.push(placeholder);
17
+ wikitext &&= (0, commentAndExt_1.parseCommentAndExt)(wikitext, config, accum, include);
30
18
  wikitext &&= (0, braces_1.parseBraces)(wikitext, config, accum);
31
19
  accum.splice(length, 1);
32
- super(wikitext, config, accum, {
33
- CommentToken: ':', ArgToken: ':', TranscludeToken: ':',
20
+ super(include, wikitext, config, accum, {
21
+ ArgToken: ':', TranscludeToken: ':',
34
22
  });
35
23
  }
36
24
  }
package/dist/src/pre.d.ts CHANGED
@@ -3,21 +3,22 @@ import { Token } from './index';
3
3
  import { NoincludeToken } from './nowiki/noinclude';
4
4
  import type { LintError } from '../base';
5
5
  import type { AstText, AttributesToken, ExtToken, ConverterToken } from '../internal';
6
+ declare type Child = NoincludeToken | ConverterToken;
6
7
  /**
7
8
  * `<pre>`
8
9
  * @classdesc `{childNodes: [...AstText|NoincludeToken|ConverterToken]}`
9
10
  */
10
11
  export declare abstract class PreToken extends Token {
11
12
  readonly name: 'pre';
12
- readonly childNodes: readonly (AstText | NoincludeToken | ConverterToken)[];
13
- abstract get firstChild(): AstText | NoincludeToken | ConverterToken | undefined;
14
- abstract get lastChild(): AstText | NoincludeToken | ConverterToken | undefined;
13
+ readonly childNodes: readonly (AstText | Child)[];
14
+ abstract get firstChild(): AstText | Child | undefined;
15
+ abstract get lastChild(): AstText | Child | undefined;
15
16
  abstract get nextSibling(): undefined;
16
17
  abstract get previousSibling(): AttributesToken;
17
18
  abstract get parentNode(): ExtToken | undefined;
18
- abstract get children(): (NoincludeToken | ConverterToken)[];
19
- abstract get firstElementChild(): NoincludeToken | ConverterToken | undefined;
20
- abstract get lastElementChild(): NoincludeToken | ConverterToken | undefined;
19
+ abstract get children(): Child[];
20
+ abstract get firstElementChild(): Child | undefined;
21
+ abstract get lastElementChild(): Child | undefined;
21
22
  abstract get previousElementSibling(): AttributesToken;
22
23
  abstract get nextElementSibling(): undefined;
23
24
  abstract get parentElement(): ExtToken | undefined;
@@ -26,3 +27,4 @@ export declare abstract class PreToken extends Token {
26
27
  constructor(wikitext?: string, config?: Parser.Config, accum?: Token[]);
27
28
  cloneNode(): this;
28
29
  }
30
+ export {};
package/dist/src/pre.js CHANGED
@@ -7,7 +7,6 @@ const index_2 = require("./index");
7
7
  const noinclude_1 = require("./nowiki/noinclude");
8
8
  /* NOT FOR BROWSER */
9
9
  const debug_1 = require("../util/debug");
10
- /* NOT FOR BROWSER END */
11
10
  /**
12
11
  * `<pre>`
13
12
  * @classdesc `{childNodes: [...AstText|NoincludeToken|ConverterToken]}`
@@ -31,7 +31,7 @@ class TableBaseToken extends (0, attributesParent_1.attributesParent)(1)(index_2
31
31
  * @param type 节点类型
32
32
  * @param attr 表格属性
33
33
  */
34
- constructor(pattern, syntax, type, attr, config = index_1.default.getConfig(), accum = [], acceptable = {}) {
34
+ constructor(pattern, syntax, type, attr, config = index_1.default.getConfig(), accum = [], acceptable) {
35
35
  super(undefined, config, accum, acceptable);
36
36
  this.append(new syntax_1.SyntaxToken(syntax, pattern, 'table-syntax', config, accum, {
37
37
  'Stage-1': ':', '!ExtToken': '', TranscludeToken: ':',
@@ -13,6 +13,7 @@ export interface TableRenderedCoords {
13
13
  }
14
14
  export interface TableToken extends SyntaxBase {
15
15
  }
16
+ export type TableTokens = TableToken | TrToken | TdToken;
16
17
  /**
17
18
  * 是否是行尾
18
19
  * @param {Token} cell 表格单元格
@@ -11,7 +11,6 @@ const syntax_1 = require("../syntax");
11
11
  const html_1 = require("../../util/html");
12
12
  const constants_1 = require("../../util/constants");
13
13
  const string_1 = require("../../util/string");
14
- /* NOT FOR BROWSER END */
15
14
  const closingPattern = /^\n[^\S\n]*(?:\|\}|\{\{\s*!\s*\}\}\}|\{\{\s*!\)\s*\}\})$/u;
16
15
  /**
17
16
  * 是否是行尾
@@ -20,10 +20,11 @@ export declare abstract class ExtToken extends TagPairToken {
20
20
  get type(): 'ext';
21
21
  /**
22
22
  * @param name 标签名
23
+ * @param include 是否嵌入
23
24
  * @param attr 标签属性
24
25
  * @param inner 内部wikitext
25
26
  * @param closed 是否封闭
26
27
  */
27
- constructor(name: string, attr?: string, inner?: string, closed?: string, config?: Parser.Config, accum?: Token[]);
28
+ constructor(name: string, attr?: string, inner?: string, closed?: string, config?: Parser.Config, include?: boolean, accum?: Token[]);
28
29
  cloneNode(): this;
29
30
  }
@@ -89,11 +89,12 @@ let ExtToken = (() => {
89
89
  }
90
90
  /**
91
91
  * @param name 标签名
92
+ * @param include 是否嵌入
92
93
  * @param attr 标签属性
93
94
  * @param inner 内部wikitext
94
95
  * @param closed 是否封闭
95
96
  */
96
- constructor(name, attr, inner, closed, config = index_1.default.getConfig(), accum = []) {
97
+ constructor(name, attr, inner, closed, config = index_1.default.getConfig(), include = false, accum = []) {
97
98
  const lcName = name.toLowerCase(),
98
99
  // @ts-expect-error abstract class
99
100
  attrToken = new attributes_1.AttributesToken(!attr || attr.trimStart() !== attr ? attr : ` ${attr}`, 'ext-attrs', lcName, config, accum), newConfig = { ...config, ext: del(config.ext, lcName), excludes: [...config.excludes ?? []] };
@@ -121,17 +122,18 @@ let ExtToken = (() => {
121
122
  break;
122
123
  case 'dynamicpagelist':
123
124
  // @ts-expect-error abstract class
124
- innerToken = new index_4.ParamTagToken(inner, newConfig, accum);
125
+ innerToken = new index_4.ParamTagToken(include, inner, newConfig, accum);
125
126
  break;
126
127
  case 'inputbox':
127
128
  newConfig.excludes.push('heading');
128
129
  // @ts-expect-error abstract class
129
- innerToken = new inputbox_1.InputboxToken(inner, newConfig, accum);
130
+ innerToken = new inputbox_1.InputboxToken(include, inner, newConfig, accum);
130
131
  break;
131
132
  case 'references': {
132
133
  const { NestedToken } = require('../nested');
134
+ newConfig.excludes.push('heading');
133
135
  // @ts-expect-error abstract class
134
- innerToken = new NestedToken(inner, /<!--.*?(?:-->|$)|<(ref)(\s[^>]*?)?(?:\/>|>(.*?)<\/(ref\s*)>)/gisu, ['ref'], newConfig, accum);
136
+ innerToken = new NestedToken(inner, include, ['ref'], newConfig, accum);
135
137
  break;
136
138
  }
137
139
  case 'choose': {
@@ -186,10 +188,10 @@ let ExtToken = (() => {
186
188
  }
187
189
  /* NOT FOR BROWSER */
188
190
  cloneNode() {
189
- const inner = this.lastChild.cloneNode(), tags = this.getAttribute('tags'), config = this.getAttribute('config'), attr = this.firstChild.toString();
191
+ const inner = this.lastChild.cloneNode(), tags = this.getAttribute('tags'), config = this.getAttribute('config'), include = this.getAttribute('include'), closed = this.selfClosing ? undefined : tags[1], attr = this.firstChild.toString();
190
192
  return debug_1.Shadow.run(() => {
191
193
  // @ts-expect-error abstract class
192
- const token = new ExtToken(tags[0], attr, '', this.selfClosing ? undefined : tags[1], config);
194
+ const token = new ExtToken(tags[0], attr, '', closed, config, include);
193
195
  token.lastChild.safeReplaceWith(inner);
194
196
  return token;
195
197
  });
@@ -4,6 +4,7 @@ import { ParameterToken } from './parameter';
4
4
  import { AtomToken } from './atom';
5
5
  import { SyntaxToken } from './syntax';
6
6
  import type { LintError } from '../base';
7
+ declare type Child = AtomToken | SyntaxToken;
7
8
  /**
8
9
  * 模板或魔术字
9
10
  * @classdesc `{childNodes: [AtomToken|SyntaxToken, ...AtomToken, ...ParameterToken]}`
@@ -12,12 +13,12 @@ export declare abstract class TranscludeToken extends Token {
12
13
  #private;
13
14
  readonly modifier: string;
14
15
  readonly name: string;
15
- readonly childNodes: readonly [AtomToken | SyntaxToken, ...ParameterToken[]] | readonly [SyntaxToken, AtomToken, AtomToken, ...ParameterToken[]];
16
- abstract get firstChild(): AtomToken | SyntaxToken;
17
- abstract get lastChild(): AtomToken | SyntaxToken | ParameterToken;
18
- abstract get children(): [AtomToken | SyntaxToken, ...ParameterToken[]] | [SyntaxToken, AtomToken, AtomToken, ...ParameterToken[]];
19
- abstract get firstElementChild(): AtomToken | SyntaxToken;
20
- abstract get lastElementChild(): AtomToken | SyntaxToken | ParameterToken;
16
+ readonly childNodes: readonly [Child, ...ParameterToken[]] | readonly [SyntaxToken, AtomToken, AtomToken, ...ParameterToken[]];
17
+ abstract get firstChild(): Child;
18
+ abstract get lastChild(): Child | ParameterToken;
19
+ abstract get children(): [Child, ...ParameterToken[]] | [SyntaxToken, AtomToken, AtomToken, ...ParameterToken[]];
20
+ abstract get firstElementChild(): Child;
21
+ abstract get lastElementChild(): Child | ParameterToken;
21
22
  get type(): 'template' | 'magic-word';
22
23
  /** 是否存在重复参数 */
23
24
  get duplication(): boolean;
@@ -157,3 +158,4 @@ export declare abstract class TranscludeToken extends Token {
157
158
  */
158
159
  escapeTables(): TranscludeToken;
159
160
  }
161
+ export {};
@@ -21,7 +21,6 @@ const insensitiveVars = new Set([
21
21
  ]);
22
22
  /* NOT FOR BROWSER */
23
23
  const basicMagicWords = new Map([['=', '='], ['!', '|']]);
24
- /* NOT FOR BROWSER END */
25
24
  /**
26
25
  * 模板或魔术字
27
26
  * @classdesc `{childNodes: [AtomToken|SyntaxToken, ...AtomToken, ...ParameterToken]}`
@@ -53,6 +52,12 @@ class TranscludeToken extends index_2.Token {
53
52
  * @throws `SyntaxError` 非法的模板名称
54
53
  */
55
54
  constructor(title, parts, config = index_1.default.getConfig(), accum = []) {
55
+ let heading;
56
+ const m = /^(?:\s|\0\d+[cn]\x7F)*\0(\d+)h\x7F(?:\s|\0\d+[cn]\x7F)*/u.exec(title);
57
+ if (m) {
58
+ heading = Number(m[1]);
59
+ title = title.replace(`\0${heading}h\x7F`, accum[heading].toString().replace(/^\n/u, ''));
60
+ }
56
61
  super(undefined, config, accum, {
57
62
  AtomToken: 0, SyntaxToken: 0, ParameterToken: '1:',
58
63
  });
@@ -112,6 +117,10 @@ class TranscludeToken extends index_2.Token {
112
117
  });
113
118
  super.insertAt(token);
114
119
  }
120
+ if (typeof heading === 'number') {
121
+ // @ts-expect-error sparse array
122
+ accum[heading] = undefined;
123
+ }
115
124
  const templateLike = this.isTemplate();
116
125
  let i = 1;
117
126
  for (const [j, part] of parts.entries()) {