wikiparser-node 1.6.0 → 1.6.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.
@@ -86,6 +86,9 @@ class Ranges extends Array {
86
86
  this.push(ele);
87
87
  continue;
88
88
  }
89
+ else if (typeof ele === 'string' && !ele.trim()) {
90
+ continue;
91
+ }
89
92
  const number = Number(ele);
90
93
  if (Number.isInteger(number)) {
91
94
  this.push(number);
@@ -37,9 +37,9 @@ function validate(key, val, config, halfParsed = false, ext) {
37
37
  case 'manualthumb':
38
38
  return true;
39
39
  case 'page':
40
- return (ext === 'djvu' || ext === 'djv') && Number(value) > 0;
40
+ return (ext === 'djvu' || ext === 'djv' || ext === 'pdf') && Number(value) > 0;
41
41
  default:
42
- return !Number.isNaN(Number(value));
42
+ return Boolean(value) && !isNaN(value);
43
43
  }
44
44
  }
45
45
  /** 图片参数 */
package/dist/src/index.js CHANGED
@@ -156,7 +156,7 @@ class Token extends element_1.AstElement {
156
156
  if (i % 2 === 0) {
157
157
  return new text_1.AstText(s);
158
158
  }
159
- else if (Number.isNaN(Number(s.slice(-1)))) {
159
+ else if (isNaN(s.slice(-1))) {
160
160
  return this.#accum[Number(s.slice(0, -1))];
161
161
  }
162
162
  throw new Error(`解析错误!未正确标记的 Token:${s}`);
@@ -98,7 +98,7 @@ class LinkBaseToken extends index_2.Token {
98
98
  /** @private */
99
99
  setAttribute(key, value) {
100
100
  if (key === 'bracket') {
101
- this.#bracket = Boolean(value);
101
+ this.#bracket = value;
102
102
  }
103
103
  else if (key === 'title') {
104
104
  this.#title = value;
@@ -196,7 +196,7 @@ class LinkBaseToken extends index_2.Token {
196
196
  * @param link 链接目标
197
197
  */
198
198
  setTarget(link) {
199
- const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(String(link), this.getAttribute('include'), 2, config), token = debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'link-target', config, [], {
199
+ const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(link, this.getAttribute('include'), 2, config), token = debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'link-target', config, [], {
200
200
  'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '',
201
201
  }));
202
202
  token.append(...childNodes);
@@ -94,7 +94,11 @@ class TableToken extends trBase_1.TrBaseToken {
94
94
  }
95
95
  }
96
96
  if (j < length) {
97
- errors.push((0, lint_1.generateForChild)(this.getNthRow(j), { start }, 'table-layout', 'inconsistent table layout', 'warning'));
97
+ const e = (0, lint_1.generateForChild)(this.getNthRow(j), { start }, 'table-layout', 'inconsistent table layout', 'warning');
98
+ e.startIndex++;
99
+ e.startLine++;
100
+ e.startCol = 0;
101
+ errors.push(e);
98
102
  }
99
103
  }
100
104
  return errors;
@@ -231,7 +231,7 @@ let TdToken = (() => {
231
231
  getAttr(key) {
232
232
  const value = super.getAttr(key);
233
233
  key = key.toLowerCase().trim();
234
- return (key === 'rowspan' || key === 'colspan' ? Number(value) || 1 : value);
234
+ return (key === 'rowspan' || key === 'colspan' ? parseInt(value) || 1 : value);
235
235
  }
236
236
  /** @override */
237
237
  print() {
@@ -290,10 +290,10 @@ let TdToken = (() => {
290
290
  getAttrs() {
291
291
  const attr = super.getAttrs();
292
292
  if ('rowspan' in attr) {
293
- attr.rowspan = Number(attr.rowspan);
293
+ attr.rowspan = parseInt(attr.rowspan);
294
294
  }
295
295
  if ('colspan' in attr) {
296
- attr.colspan = Number(attr.colspan);
296
+ attr.colspan = parseInt(attr.colspan);
297
297
  }
298
298
  return attr;
299
299
  }
@@ -326,7 +326,7 @@ class TranscludeToken extends index_2.Token {
326
326
  this.#args.set(keyStr, args);
327
327
  }
328
328
  /* NOT FOR BROWSER */
329
- if (exact && !Number.isNaN(Number(keyStr))) {
329
+ if (exact && keyStr.trim() && !isNaN(keyStr)) {
330
330
  args = new Set([...args].filter(({ anon }) => typeof key === 'number' === anon));
331
331
  }
332
332
  else if (copy) {
@@ -634,7 +634,7 @@ class TranscludeToken extends index_2.Token {
634
634
  values.set(val, [arg]);
635
635
  }
636
636
  }
637
- let noMoreAnon = anonCount === 0 || Number.isNaN(Number(key));
637
+ let noMoreAnon = anonCount === 0 || !key.trim() || isNaN(key);
638
638
  const emptyArgs = values.get('') ?? [], duplicatedArgs = [...values].filter(([val, { length }]) => val && length > 1).flatMap(([, curArgs]) => {
639
639
  const anonIndex = noMoreAnon ? -1 : curArgs.findIndex(({ anon }) => anon);
640
640
  if (anonIndex !== -1) {
@@ -82,7 +82,7 @@ const undo = (e, data) => {
82
82
  }
83
83
  break;
84
84
  default:
85
- throw new RangeError(`无法撤销未知类型的事件:${String(type)}`);
85
+ throw new RangeError(`无法撤销未知类型的事件:${type}`);
86
86
  }
87
87
  };
88
88
  exports.undo = undo;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikiparser-node",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "A Node.js parser for MediaWiki markup with AST",
5
5
  "keywords": [
6
6
  "mediawiki",