wikilint 2.1.2 → 2.1.4

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.
@@ -30,15 +30,15 @@
30
30
  "type": "string"
31
31
  }
32
32
  },
33
- "required": [
34
- "6",
35
- "10"
36
- ],
37
33
  "additionalProperties": false
38
34
  },
39
35
  "nsid": {
40
36
  "description": "namespace IDs",
41
37
  "type": "object",
38
+ "required": [
39
+ "file",
40
+ "category"
41
+ ],
42
42
  "additionalProperties": {
43
43
  "type": "integer"
44
44
  }
@@ -70,11 +70,11 @@
70
70
  "img"
71
71
  ]
72
72
  ],
73
- "namespaces": {
74
- "6": "File",
75
- "10": "Template"
73
+ "namespaces": {},
74
+ "nsid": {
75
+ "file": 6,
76
+ "category": 14
76
77
  },
77
- "nsid": {},
78
78
  "parserFunction": [
79
79
  {
80
80
  "#language": "language",
package/dist/index.d.ts CHANGED
@@ -12,11 +12,6 @@ declare interface Parser extends ParserBase {
12
12
  * @param selfLink 是否允许selfLink
13
13
  */
14
14
  normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config, halfParsed?: boolean, decode?: boolean, selfLink?: boolean): Title;
15
- /**
16
- * @override
17
- * @param include 是否嵌入
18
- * @param maxStage 最大解析层级
19
- */
20
15
  parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config): Token;
21
16
  }
22
17
  declare const Parser: Parser;
@@ -23,7 +23,6 @@ export declare abstract class AstElement extends AstNode {
23
23
  * 插入子节点
24
24
  * @param node 待插入的子节点
25
25
  * @param i 插入位置
26
- * @throws `RangeError` 不能插入祖先节点
27
26
  */
28
27
  insertAt<T extends AstNodes>(node: T, i?: number): T;
29
28
  /**
@@ -45,7 +44,6 @@ export declare abstract class AstElement extends AstNode {
45
44
  * 修改文本子节点
46
45
  * @param str 新文本
47
46
  * @param i 子节点位置
48
- * @throws `RangeError` 对应位置的子节点不是文本节点
49
47
  */
50
48
  setText(str: string, i?: number): string;
51
49
  /**
@@ -62,7 +62,6 @@ class AstElement extends node_1.AstNode {
62
62
  * 插入子节点
63
63
  * @param node 待插入的子节点
64
64
  * @param i 插入位置
65
- * @throws `RangeError` 不能插入祖先节点
66
65
  */
67
66
  insertAt(node, i = this.length) {
68
67
  const { childNodes } = this;
@@ -108,7 +107,6 @@ class AstElement extends node_1.AstNode {
108
107
  * 修改文本子节点
109
108
  * @param str 新文本
110
109
  * @param i 子节点位置
111
- * @throws `RangeError` 对应位置的子节点不是文本节点
112
110
  */
113
111
  setText(str, i = 0) {
114
112
  const oldText = this.childNodes.at(i);
package/dist/lib/text.js CHANGED
@@ -52,7 +52,8 @@ class AstText extends node_1.AstNode {
52
52
  * @param start
53
53
  */
54
54
  lint(start = this.getAbsoluteIndex()) {
55
- const { data, parentNode, nextSibling, previousSibling } = this, type = parentNode?.type, name = parentNode?.name, nextType = nextSibling?.type, previousType = previousSibling?.type, errorRegex = type === 'free-ext-link' || type === 'ext-link-url' || type === 'image-parameter' && name === 'link'
55
+ const { data, parentNode, nextSibling, previousSibling } = this;
56
+ const { type, name } = parentNode, nextType = nextSibling?.type, previousType = previousSibling?.type, errorRegex = type === 'free-ext-link' || type === 'ext-link-url' || type === 'image-parameter' && name === 'link'
56
57
  ? errorSyntaxUrl
57
58
  : errorSyntax, errors = [...data.matchAll(errorRegex)], { ext, html } = this.getRootNode().getAttribute('config');
58
59
  if (errors.length > 0) {
@@ -55,19 +55,18 @@ class HeadingToken extends index_1.Token {
55
55
  }
56
56
  /** @override */
57
57
  lint(start = this.getAbsoluteIndex()) {
58
- const errors = super.lint(start), innerStr = String(this.firstChild);
58
+ const errors = super.lint(start), { firstChild } = this, innerStr = String(firstChild);
59
59
  let refError;
60
60
  if (this.level === 1) {
61
- refError = (0, lint_1.generateForSelf)(this, { start }, '<h1>');
61
+ refError = (0, lint_1.generateForChild)(firstChild, { start }, '<h1>');
62
62
  errors.push(refError);
63
63
  }
64
64
  if (innerStr.startsWith('=') || innerStr.endsWith('=')) {
65
- refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
65
+ refError ??= (0, lint_1.generateForChild)(firstChild, { start }, '');
66
66
  errors.push({ ...refError, message: Parser.msg('unbalanced "=" in a section header') });
67
67
  }
68
68
  if (this.closest('html-attrs, table-attrs')) {
69
- refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
70
- errors.push({ ...refError, message: Parser.msg('section header in a HTML tag') });
69
+ errors.push({ ...(0, lint_1.generateForSelf)(this, { start }, ''), message: Parser.msg('section header in a HTML tag') });
71
70
  }
72
71
  return errors;
73
72
  }
@@ -17,7 +17,6 @@ export declare class Token extends AstElement {
17
17
  * @override
18
18
  * @param child 待插入的子节点
19
19
  * @param i 插入位置
20
- * @throws `RangeError` 不可插入的子节点
21
20
  */
22
21
  insertAt(child: string, i?: number): AstText;
23
22
  /** @ignore */
@@ -1,16 +1,16 @@
1
1
  import * as Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import type { LintError } from '../base';
4
- import type { AstText, CommentToken, IncludeToken, NoincludeToken } from '../internal';
4
+ import type { AstText, CommentToken, IncludeToken, NoincludeToken, TranscludeToken } from '../internal';
5
5
  /**
6
6
  * 自由外链
7
7
  * @classdesc `{childNodes: ...AstText|CommentToken|IncludeToken|NoincludeToken}`
8
8
  */
9
9
  export declare class MagicLinkToken extends Token {
10
10
  type: 'free-ext-link' | 'ext-link-url';
11
- childNodes: (AstText | CommentToken | IncludeToken | NoincludeToken)[];
12
- abstract get firstChild(): AstText | CommentToken | IncludeToken | NoincludeToken;
13
- abstract get lastChild(): AstText | CommentToken | IncludeToken | NoincludeToken;
11
+ childNodes: (AstText | CommentToken | IncludeToken | NoincludeToken | TranscludeToken)[];
12
+ abstract get firstChild(): AstText | TranscludeToken;
13
+ abstract get lastChild(): AstText | CommentToken | IncludeToken | NoincludeToken | TranscludeToken;
14
14
  /**
15
15
  * @param url 网址
16
16
  * @param doubleSlash 是否接受"//"作为协议
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.noWrap = exports.decodeHtml = exports.text = exports.escapeRegExp = exports.removeComment = exports.extUrlChar = exports.extUrlCharFirst = void 0;
4
4
  exports.extUrlCharFirst = '(?:\\[[\\da-f:.]+\\]|[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD])';
5
- exports.extUrlChar = '(?:[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD]|\\0\\d+c\\x7F)*';
5
+ exports.extUrlChar = '(?:[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD]|\\0\\d+[c!~]\\x7F)*';
6
6
  /**
7
7
  * remove half-parsed comment-like tokens
8
8
  * @param str 原字符串
@@ -26,7 +26,7 @@ exports.text = text;
26
26
  * decode HTML entities
27
27
  * @param str 原字符串
28
28
  */
29
- const decodeHtml = (str) => str.replace(/&#(\d+|x[\da-f]+);/giu, (_, code) => String.fromCodePoint(Number(`${code[0].toLowerCase() === 'x' ? '0' : ''}${code}`)));
29
+ const decodeHtml = (str) => str.replace(/&#(\d+|x[\da-f]+);/giu, (_, code) => String.fromCodePoint(Number(`${code.toLowerCase().startsWith('x') ? '0' : ''}${code}`)));
30
30
  exports.decodeHtml = decodeHtml;
31
31
  /**
32
32
  * escape newlines
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikilint",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "A Node.js linter for MediaWiki markup",
5
5
  "keywords": [
6
6
  "mediawiki",