wikiparser-node 1.22.0 → 1.23.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 (51) hide show
  1. package/bundle/bundle-es8.min.js +22 -22
  2. package/bundle/bundle-lsp.min.js +26 -26
  3. package/bundle/bundle.min.js +22 -22
  4. package/config/default.json +2 -0
  5. package/config/minimum.json +1 -0
  6. package/config/moegirl.json +2 -0
  7. package/dist/index.d.ts +1 -1
  8. package/dist/lib/document.js +1 -1
  9. package/dist/lib/element.d.ts +3 -57
  10. package/dist/lib/element.js +12 -122
  11. package/dist/lib/lsp.js +26 -9
  12. package/dist/lib/node.d.ts +3 -8
  13. package/dist/lib/node.js +16 -22
  14. package/dist/lib/range.d.ts +90 -4
  15. package/dist/lib/range.js +602 -391
  16. package/dist/lib/text.js +1 -1
  17. package/dist/lib/title.js +1 -1
  18. package/dist/mixin/attributesParent.js +2 -12
  19. package/dist/mixin/elementLike.d.ts +65 -0
  20. package/dist/mixin/elementLike.js +93 -0
  21. package/dist/mixin/fixed.js +2 -3
  22. package/dist/mixin/gapped.js +2 -2
  23. package/dist/mixin/hidden.js +2 -2
  24. package/dist/mixin/multiLine.js +2 -2
  25. package/dist/mixin/noEscape.js +2 -2
  26. package/dist/mixin/nodeLike.d.ts +17 -0
  27. package/dist/mixin/nodeLike.js +29 -0
  28. package/dist/mixin/padded.js +2 -1
  29. package/dist/mixin/readOnly.js +3 -1
  30. package/dist/mixin/singleLine.js +2 -1
  31. package/dist/mixin/sol.js +2 -2
  32. package/dist/mixin/syntax.js +2 -2
  33. package/dist/parser/selector.js +14 -9
  34. package/dist/src/atom.d.ts +1 -1
  35. package/dist/src/html.d.ts +8 -0
  36. package/dist/src/html.js +20 -0
  37. package/dist/src/index.d.ts +1 -1
  38. package/dist/src/index.js +2 -1
  39. package/dist/src/link/galleryImage.js +1 -1
  40. package/dist/src/nested.js +1 -1
  41. package/dist/src/paramTag/index.d.ts +1 -1
  42. package/dist/src/syntax.d.ts +1 -1
  43. package/dist/src/table/base.d.ts +1 -1
  44. package/dist/src/table/index.d.ts +0 -1
  45. package/dist/src/table/index.js +1 -1
  46. package/dist/src/transclude.js +1 -1
  47. package/dist/util/debug.js +2 -0
  48. package/dist/util/sharable.js +1 -1
  49. package/dist/util/sharable.mjs +1 -1
  50. package/extensions/dist/base.js +1 -1
  51. package/package.json +2 -3
package/dist/lib/text.js CHANGED
@@ -202,7 +202,7 @@ let AstText = (() => {
202
202
  const { type, name, parentNode: grandparent } = parentNode;
203
203
  if (type === 'attr-value') {
204
204
  const { name: grandName, tag } = grandparent;
205
- if (tag === 'ref' && (grandName === 'name' || grandName === 'extends' || grandName === 'follow')
205
+ if (tag === 'ref' && (grandName === 'name' || grandName === 'follow')
206
206
  || grandName === 'group' && (tag === 'ref' || tag === 'references')
207
207
  || tag === 'choose' && (grandName === 'before' || grandName === 'after')) {
208
208
  return [];
package/dist/lib/title.js CHANGED
@@ -275,7 +275,7 @@ class Title {
275
275
  autoConvert() {
276
276
  const { conversionTable } = this;
277
277
  if (conversionTable.size > 0) {
278
- const regex = new RegExp([...conversionTable.keys()].sort().reverse().map(string_1.escapeRegExp).join('|'), 'gu');
278
+ const regex = new RegExp([...conversionTable.keys()].sort((a, b) => b.localeCompare(a)).map(string_1.escapeRegExp).join('|'), 'gu');
279
279
  this.main = this.main.replace(regex, p => conversionTable.get(p));
280
280
  }
281
281
  }
@@ -9,28 +9,24 @@ const constants_1 = require("../util/constants");
9
9
  * @param i AttributesToken子节点的位置
10
10
  */
11
11
  const attributesParent = (i = 0) => (constructor) => {
12
- /** 子节点含有AttributesToken的类 */
12
+ /* eslint-disable jsdoc/require-jsdoc */
13
13
  class AttributesParent extends constructor {
14
14
  /* NOT FOR BROWSER */
15
- /** @implements */
16
15
  get attributes() {
17
16
  return this.#getAttributesChild().attributes;
18
17
  }
19
18
  set attributes(attributes) {
20
19
  this.#getAttributesChild().attributes = attributes;
21
20
  }
22
- /** @implements */
23
21
  get className() {
24
22
  return this.#getAttributesChild().className;
25
23
  }
26
24
  set className(className) {
27
25
  this.#getAttributesChild().className = className;
28
26
  }
29
- /** @implements */
30
27
  get classList() {
31
28
  return this.#getAttributesChild().classList;
32
29
  }
33
- /** @implements */
34
30
  get id() {
35
31
  return this.#getAttributesChild().id;
36
32
  }
@@ -42,39 +38,33 @@ const attributesParent = (i = 0) => (constructor) => {
42
38
  #getAttributesChild() {
43
39
  return this.childNodes[i];
44
40
  }
45
- /** @implements */
46
41
  hasAttr(key) {
47
42
  return this.#getAttributesChild().hasAttr(key);
48
43
  }
49
- /** @implements */
50
44
  getAttr(key) {
51
45
  return this.#getAttributesChild().getAttr(key);
52
46
  }
53
47
  /* NOT FOR BROWSER */
54
- /** @implements */
55
48
  getAttrNames() {
56
49
  return this.#getAttributesChild().getAttrNames();
57
50
  }
58
- /** @implements */
59
51
  getAttrs() {
60
52
  return this.#getAttributesChild().getAttrs();
61
53
  }
62
54
  setAttr(keyOrProp, value) {
63
55
  this.#getAttributesChild().setAttr(keyOrProp, value);
64
56
  }
65
- /** @implements */
66
57
  removeAttr(key) {
67
58
  this.#getAttributesChild().removeAttr(key);
68
59
  }
69
- /** @implements */
70
60
  toggleAttr(key, force) {
71
61
  this.#getAttributesChild().toggleAttr(key, force);
72
62
  }
73
- /** @implements */
74
63
  css(key, value) {
75
64
  return this.#getAttributesChild().css(key, value);
76
65
  }
77
66
  }
67
+ /* eslint-enable jsdoc/require-jsdoc */
78
68
  (0, debug_1.mixin)(AttributesParent, constructor);
79
69
  return AttributesParent;
80
70
  };
@@ -0,0 +1,65 @@
1
+ import type { AstNodes, Token } from '../internal';
2
+ declare type ElementConstructor = abstract new (...args: any[]) => {
3
+ readonly childNodes: readonly AstNodes[];
4
+ detach?: () => void;
5
+ };
6
+ export interface ElementLike {
7
+ /** all child elements / 全部非文本子节点 */
8
+ readonly children: Token[];
9
+ /** first child element / 首位非文本子节点 */
10
+ readonly firstElementChild: Token | undefined;
11
+ /** last child element / 末位非文本子节点 */
12
+ readonly lastElementChild: Token | undefined;
13
+ /** number of child elements / 非文本子节点总数 */
14
+ readonly childElementCount: number;
15
+ /**
16
+ * Get the first descendant that matches the selector
17
+ *
18
+ * 符合选择器的第一个后代节点
19
+ * @param selector selector / 选择器
20
+ */
21
+ querySelector<T = Token>(selector: string): T | undefined;
22
+ /**
23
+ * Get all descendants that match the selector
24
+ *
25
+ * 符合选择器的所有后代节点
26
+ * @param selector selector / 选择器
27
+ */
28
+ querySelectorAll<T = Token>(selector: string): T[];
29
+ /**
30
+ * Get all descendants of the types
31
+ *
32
+ * 类型选择器
33
+ * @param types token types / 节点类型
34
+ */
35
+ getElementByTypes<T = Token>(types: string): T | undefined;
36
+ /**
37
+ * Get the first descendant with the id
38
+ *
39
+ * id选择器
40
+ * @param id id名
41
+ */
42
+ getElementById<T = Token>(id: string): T | undefined;
43
+ /**
44
+ * Get all descendants with the class
45
+ *
46
+ * 类选择器
47
+ * @param className class name / 类名之一
48
+ */
49
+ getElementsByClassName<T = Token>(className: string): T[];
50
+ /**
51
+ * Get all descendants with the tag name
52
+ *
53
+ * 标签名选择器
54
+ * @param tag tag name / 标签名
55
+ */
56
+ getElementsByTagName<T = Token>(tag: string): T[];
57
+ /**
58
+ * Escape `=` and `|`
59
+ *
60
+ * 转义 `=` 和 `|`
61
+ * @since v1.18.3
62
+ */
63
+ escape(): void;
64
+ }
65
+ /** @ignore */
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.elementLike = void 0;
4
+ const debug_1 = require("../util/debug");
5
+ const selector_1 = require("../parser/selector");
6
+ /* NOT FOR BROWSER */
7
+ const constants_1 = require("../util/constants");
8
+ const element_1 = require("../lib/element");
9
+ /** @ignore */
10
+ const elementLike = (constructor) => {
11
+ /* eslint-disable jsdoc/require-jsdoc */
12
+ class ElementLike extends constructor {
13
+ /* NOT FOR BROWSER */
14
+ get children() {
15
+ return this.childNodes.filter((child) => child.type !== 'text');
16
+ }
17
+ get firstElementChild() {
18
+ return this.childNodes.find((child) => child.type !== 'text');
19
+ }
20
+ get lastElementChild() {
21
+ return this.childNodes.findLast((child) => child.type !== 'text');
22
+ }
23
+ get childElementCount() {
24
+ return this.children.length;
25
+ }
26
+ /* NOT FOR BROWSER END */
27
+ #getCondition(selector) {
28
+ return (0, selector_1.getCondition)(selector,
29
+ // eslint-disable-next-line unicorn/no-negated-condition, @stylistic/operator-linebreak
30
+ !(this instanceof element_1.AstElement) ?
31
+ undefined : // eslint-disable-line @stylistic/operator-linebreak
32
+ this);
33
+ }
34
+ getElementBy(condition) {
35
+ for (const child of this.childNodes) {
36
+ if (child.type === 'text') {
37
+ continue;
38
+ }
39
+ else if (condition(child)) {
40
+ return child;
41
+ }
42
+ const descendant = child.getElementBy(condition);
43
+ if (descendant) {
44
+ return descendant;
45
+ }
46
+ }
47
+ return undefined;
48
+ }
49
+ querySelector(selector) {
50
+ return this.getElementBy(this.#getCondition(selector));
51
+ }
52
+ getElementsBy(condition, descendants = []) {
53
+ for (const child of this.childNodes) {
54
+ if (child.type === 'text') {
55
+ continue;
56
+ }
57
+ else if (condition(child)) {
58
+ descendants.push(child);
59
+ }
60
+ child.getElementsBy(condition, descendants);
61
+ }
62
+ return descendants;
63
+ }
64
+ querySelectorAll(selector) {
65
+ return this.getElementsBy(this.#getCondition(selector));
66
+ }
67
+ /* NOT FOR BROWSER */
68
+ getElementByTypes(types) {
69
+ const typeSet = new Set(types.split(',').map(str => str.trim()));
70
+ return this.getElementBy((({ type }) => typeSet.has(type)));
71
+ }
72
+ getElementById(id) {
73
+ return this.getElementBy((token => 'id' in token && token.id === id));
74
+ }
75
+ getElementsByClassName(className) {
76
+ return this.getElementsBy((token => 'classList' in token && token.classList.has(className)));
77
+ }
78
+ getElementsByTagName(tag) {
79
+ return this.getElementsBy((({ type, name }) => name === tag && (type === 'html' || type === 'ext')));
80
+ }
81
+ escape() {
82
+ for (const child of this.childNodes) {
83
+ child.escape();
84
+ }
85
+ this.detach?.();
86
+ }
87
+ }
88
+ /* eslint-enable jsdoc/require-jsdoc */
89
+ (0, debug_1.mixin)(ElementLike, constructor);
90
+ return ElementLike;
91
+ };
92
+ exports.elementLike = elementLike;
93
+ constants_1.mixins['elementLike'] = __filename;
@@ -8,13 +8,11 @@ const constants_1 = require("../util/constants");
8
8
  * @ignore
9
9
  */
10
10
  const fixedToken = (constructor) => {
11
- /** 不可增删子节点的类 */
11
+ /* eslint-disable jsdoc/require-jsdoc */
12
12
  class FixedToken extends constructor {
13
- /** @private */
14
13
  get fixed() {
15
14
  return true;
16
15
  }
17
- /** @override */
18
16
  removeAt() {
19
17
  this.constructorError('cannot remove child nodes');
20
18
  }
@@ -24,6 +22,7 @@ const fixedToken = (constructor) => {
24
22
  : this.constructorError('cannot insert child nodes');
25
23
  }
26
24
  }
25
+ /* eslint-enable jsdoc/require-jsdoc */
27
26
  (0, debug_1.mixin)(FixedToken, constructor);
28
27
  return FixedToken;
29
28
  };
@@ -10,13 +10,13 @@ const constants_1 = require("../util/constants");
10
10
  * @param gap
11
11
  */
12
12
  const gapped = (gap = 1) => (constructor) => {
13
- /** 不可增删子节点的类 */
13
+ /* eslint-disable jsdoc/require-jsdoc */
14
14
  class GappedToken extends constructor {
15
- /** @private */
16
15
  getGaps() {
17
16
  return gap;
18
17
  }
19
18
  }
19
+ /* eslint-enable jsdoc/require-jsdoc */
20
20
  (0, debug_1.mixin)(GappedToken, constructor);
21
21
  return GappedToken;
22
22
  };
@@ -46,7 +46,7 @@ const cached_1 = require("./cached");
46
46
  * @param html 是否覆写 toHtml 方法
47
47
  */
48
48
  const hiddenToken = (linter = true, html = true) => (constructor) => {
49
- /** 解析后不可见的类 */
49
+ /* eslint-disable jsdoc/require-jsdoc */
50
50
  let AnyHiddenToken = (() => {
51
51
  let _classSuper = constructor;
52
52
  let _instanceExtraInitializers = [];
@@ -67,7 +67,6 @@ const hiddenToken = (linter = true, html = true) => (constructor) => {
67
67
  return linter ? [] : super.lint(start);
68
68
  }
69
69
  /* NOT FOR BROWSER */
70
- /** @private */
71
70
  dispatchEvent() {
72
71
  //
73
72
  }
@@ -80,6 +79,7 @@ const hiddenToken = (linter = true, html = true) => (constructor) => {
80
79
  }
81
80
  };
82
81
  })();
82
+ /* eslint-enable jsdoc/require-jsdoc */
83
83
  (0, debug_1.mixin)(AnyHiddenToken, constructor);
84
84
  return AnyHiddenToken;
85
85
  };
@@ -10,7 +10,7 @@ const constants_1 = require("../util/constants");
10
10
  * @ignore
11
11
  */
12
12
  const multiLine = (constructor) => {
13
- /** 不可包含换行符的类 */
13
+ /* eslint-disable jsdoc/require-jsdoc */
14
14
  class MultiLineToken extends constructor {
15
15
  toString(skip) {
16
16
  return super.toString(skip, '\n');
@@ -18,7 +18,6 @@ const multiLine = (constructor) => {
18
18
  text() {
19
19
  return super.text('\n').replace(/\n\s*\n/gu, '\n');
20
20
  }
21
- /** @private */
22
21
  getGaps() {
23
22
  return 1;
24
23
  }
@@ -26,6 +25,7 @@ const multiLine = (constructor) => {
26
25
  return super.print({ sep: '\n' });
27
26
  }
28
27
  }
28
+ /* eslint-enable jsdoc/require-jsdoc */
29
29
  (0, debug_1.mixin)(MultiLineToken, constructor);
30
30
  return MultiLineToken;
31
31
  };
@@ -8,13 +8,13 @@ const constants_1 = require("../util/constants");
8
8
  * @ignore
9
9
  */
10
10
  const noEscape = (constructor) => {
11
- /** 不可包含换行符的类 */
11
+ /* eslint-disable jsdoc/require-jsdoc */
12
12
  class NoEscapeToken extends constructor {
13
- /** @private */
14
13
  escape() {
15
14
  //
16
15
  }
17
16
  }
17
+ /* eslint-enable jsdoc/require-jsdoc */
18
18
  (0, debug_1.mixin)(NoEscapeToken, constructor);
19
19
  return NoEscapeToken;
20
20
  };
@@ -0,0 +1,17 @@
1
+ import type { Dimension } from '../lib/node';
2
+ import type { AstNodes } from '../internal';
3
+ declare type NodeConstructor = abstract new (...args: any[]) => {
4
+ readonly childNodes: readonly AstNodes[];
5
+ getDimension(): Dimension;
6
+ };
7
+ export interface NodeLike {
8
+ /** first child node / 首位子节点 */
9
+ readonly firstChild: AstNodes | undefined;
10
+ /** last child node / 末位子节点 */
11
+ readonly lastChild: AstNodes | undefined;
12
+ /** number of lines / 行数 */
13
+ readonly offsetHeight: number;
14
+ /** number of columns of the last line / 最后一行的列数 */
15
+ readonly offsetWidth: number;
16
+ }
17
+ /** @ignore */
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nodeLike = void 0;
4
+ const debug_1 = require("../util/debug");
5
+ /* NOT FOR BROWSER */
6
+ const constants_1 = require("../util/constants");
7
+ /** @ignore */
8
+ const nodeLike = (constructor) => {
9
+ /* eslint-disable jsdoc/require-jsdoc */
10
+ class NodeLike extends constructor {
11
+ get firstChild() {
12
+ return this.childNodes[0];
13
+ }
14
+ get lastChild() {
15
+ return this.childNodes[this.childNodes.length - 1];
16
+ }
17
+ get offsetHeight() {
18
+ return this.getDimension().height;
19
+ }
20
+ get offsetWidth() {
21
+ return this.getDimension().width;
22
+ }
23
+ }
24
+ /* eslint-enable jsdoc/require-jsdoc */
25
+ (0, debug_1.mixin)(NodeLike, constructor);
26
+ return NodeLike;
27
+ };
28
+ exports.nodeLike = nodeLike;
29
+ constants_1.mixins['nodeLike'] = __filename;
@@ -11,12 +11,13 @@ const constants_1 = require("../util/constants");
11
11
  * @param padding.length
12
12
  */
13
13
  const padded = ({ length }) => (constructor) => {
14
- /** 不可增删子节点的类 */
14
+ /* eslint-disable jsdoc/require-jsdoc */
15
15
  class PaddedToken extends constructor {
16
16
  getAttribute(key) {
17
17
  return key === 'padding' ? length : super.getAttribute(key);
18
18
  }
19
19
  }
20
+ /* eslint-enable jsdoc/require-jsdoc */
20
21
  (0, debug_1.mixin)(PaddedToken, constructor);
21
22
  return PaddedToken;
22
23
  };
@@ -19,7 +19,9 @@ const readOnly = (readonly = false) =>
19
19
  index_1.default.viewOnly = readonly;
20
20
  }
21
21
  const result = method.apply(this, args);
22
- index_1.default.viewOnly = viewOnly;
22
+ if (!debug_1.Shadow.running) {
23
+ index_1.default.viewOnly = viewOnly;
24
+ }
23
25
  return result;
24
26
  };
25
27
  exports.readOnly = readOnly;
@@ -8,7 +8,7 @@ const constants_1 = require("../util/constants");
8
8
  * @param strict 是否严格
9
9
  */
10
10
  const singleLine = (strict = true) => (constructor) => {
11
- /** 不可包含换行符的类 */
11
+ /* eslint-disable jsdoc/require-jsdoc */
12
12
  class SingleLineToken extends constructor {
13
13
  toString(skip) {
14
14
  if (strict) {
@@ -26,6 +26,7 @@ const singleLine = (strict = true) => (constructor) => {
26
26
  return super.text().replaceAll('\n', ' ');
27
27
  }
28
28
  }
29
+ /* eslint-enable jsdoc/require-jsdoc */
29
30
  (0, debug_1.mixin)(SingleLineToken, constructor);
30
31
  return SingleLineToken;
31
32
  };
package/dist/mixin/sol.js CHANGED
@@ -8,9 +8,8 @@ const constants_1 = require("../util/constants");
8
8
  * @param self 是否允许同类节点相邻
9
9
  */
10
10
  const sol = (self) => (constructor) => {
11
- /** 只能位于行首的类 */
11
+ /* eslint-disable jsdoc/require-jsdoc */
12
12
  class SolToken extends constructor {
13
- /** @implements */
14
13
  #prependNewLine() {
15
14
  const { previousVisibleSibling, parentNode, type } = this;
16
15
  if (previousVisibleSibling) {
@@ -37,6 +36,7 @@ const sol = (self) => (constructor) => {
37
36
  return this.#prependNewLine() + super.text();
38
37
  }
39
38
  }
39
+ /* eslint-enable jsdoc/require-jsdoc */
40
40
  (0, debug_1.mixin)(SolToken, constructor);
41
41
  return SolToken;
42
42
  };
@@ -9,9 +9,8 @@ const string_1 = require("../util/string");
9
9
  * @param pattern 语法正则
10
10
  */
11
11
  const syntax = (pattern) => (constructor) => {
12
- /** 满足特定语法格式的Token */
12
+ /* eslint-disable jsdoc/require-jsdoc */
13
13
  class SyntaxToken extends constructor {
14
- /** @class */
15
14
  constructor(...args) {
16
15
  super(...args); // eslint-disable-line @typescript-eslint/no-unsafe-argument
17
16
  if (pattern) {
@@ -37,6 +36,7 @@ const syntax = (pattern) => (constructor) => {
37
36
  }
38
37
  }
39
38
  }
39
+ /* eslint-enable jsdoc/require-jsdoc */
40
40
  (0, debug_1.mixin)(SyntaxToken, constructor);
41
41
  return SyntaxToken;
42
42
  };
@@ -15,8 +15,8 @@ const attributes_1 = require("../lib/attributes");
15
15
  */
16
16
  const basic = (selector, type, name) => {
17
17
  if (selector.includes('#')) {
18
- const [t, ...names] = selector.split('#');
19
- return (!t || t === type) && names.every(n => n === name);
18
+ const i = selector.indexOf('#');
19
+ return (i === 0 || selector.slice(0, i) === type) && selector.slice(i + 1) === name;
20
20
  }
21
21
  return !selector || selector === type;
22
22
  };
@@ -168,6 +168,9 @@ const matches = (token, step, scope, has) => {
168
168
  case ':optional':
169
169
  return isProtected(token) === false;
170
170
  case ':scope':
171
+ if (!scope) {
172
+ throw new SyntaxError('The :scope pseudo-selector must be used with an element node.');
173
+ }
171
174
  return token === scope;
172
175
  default:
173
176
  return basic(selector, type, name);
@@ -450,12 +453,14 @@ const checkToken = (selector, scope, has) => (token) => {
450
453
  * @param scope 作用对象
451
454
  * @param has `:has()`伪选择器
452
455
  */
453
- const getCondition = (selector, scope, has) => (
454
- /* eslint-disable @stylistic/operator-linebreak */
455
- /[^a-z\-,#\s]|(?<![\s,])\s+(?![\s,])/u.test(selector.trim()) ?
456
- checkToken(selector, scope, has) :
457
- ({ type, name }) => selector.split(',').some(str => basic(str.trim(), type, name))
458
- /* eslint-enable @stylistic/operator-linebreak */
459
- );
456
+ const getCondition = (selector, scope, has) => {
457
+ /* NOT FOR BROWSER */
458
+ if (/[^a-z\-,#\s]|(?<![\s,])\s+(?![\s,])/u.test(selector.trim())) {
459
+ return checkToken(selector, scope, has);
460
+ }
461
+ /* NOT FOR BROWSER END */
462
+ const parts = selector.split(',');
463
+ return (({ type, name }) => parts.some(str => basic(str.trim(), type, name)));
464
+ };
460
465
  exports.getCondition = getCondition;
461
466
  constants_1.parsers['parseSelector'] = __filename;
@@ -12,7 +12,7 @@ export declare class AtomToken extends Token {
12
12
  get type(): AtomTypes;
13
13
  set type(value: AtomTypes);
14
14
  /** @class */
15
- constructor(wikitext: string | undefined, type: AtomTypes, config?: Config, accum?: Token[], acceptable?: Acceptable);
15
+ constructor(wikitext: string | undefined, type: AtomTypes, config?: Config, accum?: Token[], acceptable?: WikiParserAcceptable);
16
16
  cloneNode(): this;
17
17
  }
18
18
  export {};
@@ -2,6 +2,7 @@ import { Token } from './index';
2
2
  import type { Config, LintError, AST } from '../base';
3
3
  import type { AttributesParentBase } from '../mixin/attributesParent';
4
4
  import type { AttributesToken } from '../internal';
5
+ import type { AstRange } from '../lib/range';
5
6
  export interface HtmlToken extends AttributesParentBase {
6
7
  }
7
8
  /**
@@ -57,4 +58,11 @@ export declare abstract class HtmlToken extends Token {
57
58
  * @throws `Error` 无法修复无效自封闭标签
58
59
  */
59
60
  fix(): void;
61
+ /**
62
+ * Get the range of the HTML tag pair
63
+ *
64
+ * 获取HTML标签对的范围
65
+ * @since v1.23.0
66
+ */
67
+ getRange(): AstRange | undefined;
60
68
  }
package/dist/src/html.js CHANGED
@@ -401,6 +401,26 @@ let HtmlToken = (() => {
401
401
  }
402
402
  return result;
403
403
  }
404
+ /**
405
+ * Get the range of the HTML tag pair
406
+ *
407
+ * 获取HTML标签对的范围
408
+ * @since v1.23.0
409
+ */
410
+ getRange() {
411
+ const { closing, selfClosing, name } = this, { html: [, selfClosingTags, voidTags] } = this.getAttribute('config');
412
+ if (voidTags.includes(name) || selfClosing && selfClosingTags.includes(name)) {
413
+ return undefined;
414
+ }
415
+ const matched = this.findMatchingTag();
416
+ if (!matched) {
417
+ return undefined;
418
+ }
419
+ const range = this.createRange();
420
+ range.setStartAfter(closing ? matched : this);
421
+ range.setEndBefore(closing ? this : matched);
422
+ return range;
423
+ }
404
424
  };
405
425
  return HtmlToken = _classThis;
406
426
  })();
@@ -18,7 +18,7 @@ export declare class Token extends AstElement {
18
18
  get type(): TokenTypes;
19
19
  set type(value: TokenTypes);
20
20
  /** @class */
21
- constructor(wikitext?: string, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
21
+ constructor(wikitext?: string, config?: Parser.Config, accum?: Token[], acceptable?: WikiParserAcceptable);
22
22
  /**
23
23
  * @override
24
24
  * @param child node to be inserted / 待插入的子节点
package/dist/src/index.js CHANGED
@@ -463,7 +463,8 @@ let Token = (() => {
463
463
  break;
464
464
  /* NOT FOR BROWSER */
465
465
  case 'acceptable':
466
- this.#acceptable = value && (() => getAcceptable(value));
466
+ this.#acceptable = value
467
+ && (() => getAcceptable(value));
467
468
  break;
468
469
  case 'include':
469
470
  this.#include = value;
@@ -94,7 +94,7 @@ let GalleryImageToken = (() => {
94
94
  if (text !== undefined) {
95
95
  const { length } = accum;
96
96
  token = new index_2.Token(text, config, accum);
97
- for (let n = 1; n < constants_1.MAX_STAGE; n++) {
97
+ for (let n = 0; n < constants_1.MAX_STAGE - 1; n++) {
98
98
  token.parseOnce();
99
99
  }
100
100
  accum.splice(length, 1);
@@ -85,7 +85,7 @@ let NestedToken = (() => {
85
85
  */
86
86
  constructor(wikitext, regex, tags, config, accum = []) {
87
87
  if (typeof regex === 'boolean') {
88
- const placeholder = Symbol('InputboxToken'), { length } = accum;
88
+ const placeholder = Symbol('NestedToken'), { length } = accum;
89
89
  accum.push(placeholder);
90
90
  wikitext &&= (0, commentAndExt_1.parseCommentAndExt)(wikitext, config, accum, regex);
91
91
  wikitext &&= (0, braces_1.parseBraces)(wikitext, config, accum);
@@ -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(include: boolean, wikitext?: string, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
26
+ constructor(include: boolean, wikitext?: string, config?: Parser.Config, accum?: Token[], acceptable?: WikiParserAcceptable);
27
27
  cloneNode(): this;
28
28
  }
@@ -16,7 +16,7 @@ export declare class SyntaxToken extends Token {
16
16
  * @class
17
17
  * @param pattern 语法正则
18
18
  */
19
- constructor(wikitext: string | undefined, pattern: RegExp, type: SyntaxTypes, config?: Config, accum?: Token[], acceptable?: Acceptable);
19
+ constructor(wikitext: string | undefined, pattern: RegExp, type: SyntaxTypes, config?: Config, accum?: Token[], acceptable?: WikiParserAcceptable);
20
20
  cloneNode(): this;
21
21
  }
22
22
  export {};