wikiparser-node 0.3.0 → 0.3.1

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.
@@ -55,8 +55,8 @@ class Layout extends Array {
55
55
  class TableToken extends TrToken {
56
56
  type = 'table';
57
57
 
58
- static openingPattern = /^(?:{\||{{{\s*!\s*}}|{{\s*\(!\s*}})$/;
59
- static closingPattern = /^\n[^\S\n]*(?:\|}|{{\s*!\s*}}}|{{\s*!\)\s*}})$/;
58
+ static openingPattern = /^(?:\{\||\{\{\{\s*!\s*\}\}|\{\{\s*\(!\s*\}\})$/;
59
+ static closingPattern = /^\n[^\S\n]*(?:\|\}|\{\{\s*!\s*\}\}\}|\{\{\s*!\)\s*\}\})$/;
60
60
 
61
61
  /**
62
62
  * @param {string} syntax
package/src/table/td.js CHANGED
@@ -69,7 +69,8 @@ class TdToken extends fixedToken(TrToken) {
69
69
  return result;
70
70
  }
71
71
 
72
- static openingPattern = /^(?:\n[\S\n]*(?:[|!]|\|\+|{{\s*!\s*}}\+?)|(?:\||{{\s*!\s*}}){2}|!!|{{\s*!!\s*}})$/;
72
+ static openingPattern
73
+ = /^(?:\n[\S\n]*(?:[|!]|\|\+|\{\{\s*!\s*\}\}\+?)|(?:\||\{\{\s*!\s*\}\}){2}|!!|\{\{\s*!!\s*\}\})$/;
73
74
 
74
75
  getRowCount = undefined;
75
76
  getNthCol = undefined;
@@ -81,9 +82,9 @@ class TdToken extends fixedToken(TrToken) {
81
82
  * @param {accum} accum
82
83
  */
83
84
  constructor(syntax, inner, config = Parser.getConfig(), accum = []) {
84
- let innerSyntax = inner?.match(/\||\x00\d+!\x7f/),
85
+ let innerSyntax = /\||\0\d+!\x7f/.exec(inner),
85
86
  attr = innerSyntax ? inner.slice(0, innerSyntax.index) : '';
86
- if (/\[\[|-{/.test(attr)) {
87
+ if (/\[\[|-\{/.test(attr)) {
87
88
  innerSyntax = null;
88
89
  attr = '';
89
90
  }
@@ -155,7 +156,7 @@ class TdToken extends fixedToken(TrToken) {
155
156
  }
156
157
 
157
158
  afterBuild() {
158
- if (this.#innerSyntax.includes('\x00')) {
159
+ if (this.#innerSyntax.includes('\0')) {
159
160
  this.#innerSyntax = this.buildFromStr(this.#innerSyntax).map(String).join('');
160
161
  }
161
162
  return this;
package/src/table/tr.js CHANGED
@@ -13,7 +13,7 @@ const attributeParent = require('../../mixin/attributeParent'),
13
13
  class TrToken extends attributeParent(Token, 1) {
14
14
  type = 'tr';
15
15
 
16
- static openingPattern = /^\n[^\S\n]*(?:\|-+|{{\s*!\s*}}-+|{{\s*!-\s*}}-*)$/;
16
+ static openingPattern = /^\n[^\S\n]*(?:\|-+|\{\{\s*!\s*\}\}-+|\{\{\s*!-\s*\}\}-*)$/;
17
17
 
18
18
  /**
19
19
  * @param {string} syntax
package/src/transclude.js CHANGED
@@ -59,7 +59,7 @@ class TranscludeToken extends Token {
59
59
  isSensitive = sensitive.includes(name);
60
60
  if (isSensitive || insensitive.includes(name.toLowerCase())) {
61
61
  this.setAttribute('name', name.toLowerCase().replace(/^#/, '')).type = 'magic-word';
62
- const pattern = new RegExp(`^\\s*${name}\\s*$`, isSensitive ? '' : 'i'),
62
+ const pattern = RegExp(`^\\s*${name}\\s*$`, isSensitive ? '' : 'i'),
63
63
  token = new SyntaxToken(magicWord, pattern, 'magic-word-name', config, accum, {
64
64
  'Stage-1': ':', '!ExtToken': '',
65
65
  });
@@ -85,7 +85,7 @@ class TranscludeToken extends Token {
85
85
  }
86
86
  if (this.type === 'template') {
87
87
  const [name] = removeComment(title).split('#');
88
- if (/\x00\d+[eh!+-]\x7f|[<>[\]{}]/.test(name)) {
88
+ if (/\0\d+[eh!+-]\x7f|[<>[\]{}]/.test(name)) {
89
89
  accum.pop();
90
90
  throw new SyntaxError(`非法的模板名称:${name}`);
91
91
  }
@@ -123,7 +123,7 @@ class TranscludeToken extends Token {
123
123
  }
124
124
 
125
125
  afterBuild() {
126
- if (this.name.includes('\x00')) {
126
+ if (this.name.includes('\0')) {
127
127
  this.setAttribute('name', text(this.buildFromStr(this.name)));
128
128
  }
129
129
  if (this.matches('template, magic-word#invoke')) {
@@ -470,7 +470,9 @@ class TranscludeToken extends Token {
470
470
  } else if (this.childNodes.length < 2) {
471
471
  throw new Error('尚未指定模块名称!');
472
472
  }
473
- const root = Parser.parse(`{{#invoke:M|${func}}}`, this.getAttribute('include'), 2, this.getAttribute('config')),
473
+ const root = Parser.parse(
474
+ `{{#invoke:M|${func}}}`, this.getAttribute('include'), 2, this.getAttribute('config'),
475
+ ),
474
476
  {childNodes: {length}, firstElementChild} = root;
475
477
  if (length !== 1 || !firstElementChild?.matches('magic-word#invoke')
476
478
  || firstElementChild.childNodes.length !== 3
@@ -553,8 +555,8 @@ class TranscludeToken extends Token {
553
555
  continue;
554
556
  } else if (aggressive && (anonCount ? /\D\d+$/ : /(?:^|\D)\d+$/).test(key)) {
555
557
  let /** @type {number} */ last;
556
- const str = key.slice(0, -key.match(/\d+$/)[0].length),
557
- regex = new RegExp(`^${escapeRegExp(str)}\\d+$`),
558
+ const str = key.slice(0, -/(?<!\d)\d+$/.exec(key)[0].length),
559
+ regex = RegExp(`^${escapeRegExp(str)}\\d+$`),
558
560
  series = this.getAllArgs().filter(({name}) => regex.test(name)),
559
561
  ordered = series.every(({name}, i) => {
560
562
  const j = Number(name.slice(str.length)),
@@ -595,7 +597,7 @@ class TranscludeToken extends Token {
595
597
  */
596
598
  escapeTables() {
597
599
  const count = this.hasDuplicatedArgs();
598
- if (!/\n\s*:*\s*{\|.*\n\s*\|}/s.test(this.text()) || !count) {
600
+ if (!/\n[^\S\n]*(?::+\s*)?\{\|[^\n]*\n\s*(?:\S[^\n]*\n\s*)*\|\}/.test(this.text()) || !count) {
599
601
  return this;
600
602
  }
601
603
  const stripped = this.toString().slice(2, -2),
package/util/debug.js CHANGED
@@ -17,7 +17,7 @@ const externalUse = (name, proxy = false) => {
17
17
  if (!proxy && require('..').running) {
18
18
  return false;
19
19
  }
20
- const regex = new RegExp(`^${
20
+ const regex = RegExp(`^${
21
21
  proxy ? 'Proxy' : 'new \\w*Token$|^(?:AstNode|AstElement|\\w*Token)'
22
22
  }\\.(?!${name}$)`);
23
23
  try {
package/util/string.js CHANGED
@@ -3,7 +3,7 @@
3
3
  /**
4
4
  * optionally convert to lower cases
5
5
  * @param {string} val
6
- * @param {boolean} i
6
+ * @param {string|undefined} i
7
7
  */
8
8
  const toCase = (val, i) => i ? val.toLowerCase() : val;
9
9
 
@@ -11,7 +11,7 @@ const toCase = (val, i) => i ? val.toLowerCase() : val;
11
11
  * remove half-parsed comment-like tokens
12
12
  * @param {string} str
13
13
  */
14
- const removeComment = str => str.replace(/\x00\d+c\x7f/g, '');
14
+ const removeComment = str => str.replace(/\0\d+c\x7f/g, '');
15
15
 
16
16
  /** @param {string} str */
17
17
  const ucfirst = str => str && `${str[0].toUpperCase()}${str.slice(1)}`;
@@ -35,7 +35,7 @@ const explode = (start, end, separator, str) => {
35
35
  if (str === undefined) {
36
36
  return [];
37
37
  }
38
- const regex = new RegExp(`${[start, end, separator].map(escapeRegExp).join('|')}`, 'g'),
38
+ const regex = RegExp(`${[start, end, separator].map(escapeRegExp).join('|')}`, 'g'),
39
39
  /** @type {string[]} */ exploded = [];
40
40
  let mt = regex.exec(str),
41
41
  depth = 0,
@@ -69,7 +69,7 @@ const normalizeSpace = (token = '', separator = '') => {
69
69
  .join(separator);
70
70
  };
71
71
 
72
- const extUrlChar = '(?:[\\d.]+|\\[[\\da-f:.]+\\]|[^[\\]<>"\\x00-\\x20\\x7f\\p{Zs}\\ufffd])'
73
- + '(?:[^[\\]<>"\\x00-\\x20\\x7f\\p{Zs}\\ufffd]|\\x00\\d+c\\x7f)*';
72
+ const extUrlChar = '(?:\\[[\\da-f:.]+\\]|[^[\\]<>"\\0-\\x1f\\x7f\\p{Zs}\\ufffd])'
73
+ + '(?:[^[\\]<>"\\0-\\x1f\\x7f\\p{Zs}\\ufffd]|\\0\\d+c\\x7f)*';
74
74
 
75
75
  module.exports = {toCase, removeComment, ucfirst, escapeRegExp, text, explode, noWrap, normalizeSpace, extUrlChar};