wikiparser-node 1.18.4 → 1.20.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.
- package/README.md +3 -0
- package/bundle/bundle-es7.min.js +25 -32
- package/bundle/bundle-lsp.min.js +26 -99
- package/bundle/bundle.min.js +25 -32
- package/config/default.json +49 -3
- package/config/minimum.json +5 -1
- package/data/ext/math.json +660 -0
- package/dist/addon/table.js +24 -5
- package/dist/addon/transclude.js +5 -5
- package/dist/base.d.mts +4 -3
- package/dist/base.d.ts +4 -3
- package/dist/bin/config.js +26 -8
- package/dist/index.d.ts +2 -2
- package/dist/index.js +10 -1
- package/dist/internal.d.ts +2 -0
- package/dist/lib/document.d.ts +5 -0
- package/dist/lib/document.js +31 -2
- package/dist/lib/element.js +15 -21
- package/dist/lib/lsp.js +104 -42
- package/dist/lib/node.js +21 -24
- package/dist/lib/text.js +3 -4
- package/dist/lib/title.js +2 -1
- package/dist/mixin/attributesParent.js +1 -1
- package/dist/mixin/fixed.d.ts +1 -2
- package/dist/mixin/fixed.js +2 -3
- package/dist/mixin/gapped.d.ts +4 -0
- package/dist/mixin/gapped.js +24 -0
- package/dist/mixin/hidden.js +1 -1
- package/dist/mixin/multiLine.d.ts +4 -0
- package/dist/mixin/multiLine.js +33 -0
- package/dist/mixin/noEscape.js +1 -1
- package/dist/mixin/padded.d.ts +5 -0
- package/dist/mixin/padded.js +24 -0
- package/dist/mixin/singleLine.js +1 -1
- package/dist/mixin/sol.js +1 -1
- package/dist/mixin/syntax.js +3 -3
- package/dist/parser/braces.js +9 -13
- package/dist/parser/commentAndExt.js +18 -2
- package/dist/parser/magicLinks.js +2 -2
- package/dist/parser/selector.js +5 -2
- package/dist/src/arg.js +10 -13
- package/dist/src/atom.js +2 -7
- package/dist/src/attribute.js +6 -6
- package/dist/src/attributes.js +8 -12
- package/dist/src/commented.d.ts +26 -0
- package/dist/src/commented.js +52 -0
- package/dist/src/converter.js +3 -6
- package/dist/src/converterFlags.js +266 -223
- package/dist/src/converterRule.d.ts +2 -2
- package/dist/src/converterRule.js +2 -2
- package/dist/src/extLink.d.ts +2 -3
- package/dist/src/extLink.js +222 -175
- package/dist/src/gallery.d.ts +4 -5
- package/dist/src/gallery.js +177 -144
- package/dist/src/heading.js +11 -11
- package/dist/src/hidden.js +2 -7
- package/dist/src/imageParameter.d.ts +2 -2
- package/dist/src/imageParameter.js +13 -10
- package/dist/src/imagemap.d.ts +2 -2
- package/dist/src/imagemap.js +155 -123
- package/dist/src/imagemapLink.d.ts +2 -2
- package/dist/src/index.js +51 -27
- package/dist/src/link/base.d.ts +2 -3
- package/dist/src/link/base.js +13 -15
- package/dist/src/link/file.d.ts +2 -3
- package/dist/src/link/file.js +3 -3
- package/dist/src/link/galleryImage.d.ts +2 -3
- package/dist/src/link/galleryImage.js +7 -13
- package/dist/src/magicLink.js +7 -9
- package/dist/src/nested.d.ts +2 -2
- package/dist/src/nested.js +4 -7
- package/dist/src/nowiki/comment.js +2 -5
- package/dist/src/nowiki/doubleUnderscore.js +2 -5
- package/dist/src/nowiki/index.d.ts +2 -2
- package/dist/src/nowiki/index.js +2 -1
- package/dist/src/onlyinclude.js +6 -13
- package/dist/src/paramTag/index.d.ts +2 -2
- package/dist/src/paramTag/index.js +102 -66
- package/dist/src/paramTag/inputbox.js +9 -4
- package/dist/src/parameter.d.ts +4 -5
- package/dist/src/parameter.js +13 -13
- package/dist/src/pre.d.ts +4 -5
- package/dist/src/pre.js +8 -17
- package/dist/src/syntax.d.ts +1 -1
- package/dist/src/syntax.js +2 -7
- package/dist/src/table/base.d.ts +2 -2
- package/dist/src/table/base.js +8 -8
- package/dist/src/table/index.js +1 -1
- package/dist/src/table/td.d.ts +3 -3
- package/dist/src/table/td.js +9 -9
- package/dist/src/table/tr.d.ts +2 -2
- package/dist/src/tagPair/ext.js +39 -32
- package/dist/src/tagPair/index.d.ts +1 -1
- package/dist/src/tagPair/index.js +2 -5
- package/dist/src/tagPair/translate.d.ts +38 -0
- package/dist/src/tagPair/translate.js +129 -0
- package/dist/src/transclude.js +6 -7
- package/dist/util/html.js +16 -4
- package/dist/util/lint.js +17 -30
- package/dist/util/sharable.js +29 -1
- package/dist/util/sharable.mjs +31 -3
- package/dist/util/string.js +14 -1
- package/extensions/dist/base.js +1 -1
- package/extensions/dist/lsp.js +13 -2
- package/extensions/typings.d.ts +2 -2
- package/package.json +9 -7
- package/extensions/es7/base.js +0 -320
- package/extensions/es7/lint.js +0 -97
package/dist/src/table/td.js
CHANGED
|
@@ -41,13 +41,13 @@ exports.createTd = exports.TdToken = void 0;
|
|
|
41
41
|
const lint_1 = require("../../util/lint");
|
|
42
42
|
const constants_1 = require("../../util/constants");
|
|
43
43
|
const rect_1 = require("../../lib/rect");
|
|
44
|
-
const index_1 =
|
|
45
|
-
const index_2 = require("../index");
|
|
44
|
+
const index_1 = require("../index");
|
|
46
45
|
const base_1 = require("./base");
|
|
47
46
|
/* NOT FOR BROWSER */
|
|
48
47
|
const debug_1 = require("../../util/debug");
|
|
49
48
|
const string_1 = require("../../util/string");
|
|
50
49
|
const fixed_1 = require("../../mixin/fixed");
|
|
50
|
+
const index_2 = __importDefault(require("../../index"));
|
|
51
51
|
/* NOT FOR BROWSER END */
|
|
52
52
|
/**
|
|
53
53
|
* `<td>`, `<th>` or `<caption>`
|
|
@@ -104,14 +104,14 @@ let TdToken = (() => {
|
|
|
104
104
|
return this.lastChild.text().trim();
|
|
105
105
|
}
|
|
106
106
|
set innerText(text) {
|
|
107
|
-
this.lastChild.replaceChildren(...
|
|
107
|
+
this.lastChild.replaceChildren(...index_2.default.parse(text, true, undefined, this.getAttribute('config')).childNodes);
|
|
108
108
|
}
|
|
109
109
|
/* NOT FOR BROWSER END */
|
|
110
110
|
/**
|
|
111
111
|
* @param syntax 单元格语法
|
|
112
112
|
* @param inner 内部wikitext
|
|
113
113
|
*/
|
|
114
|
-
constructor(syntax, inner, config
|
|
114
|
+
constructor(syntax, inner, config, accum = []) {
|
|
115
115
|
let innerSyntax = /\||\0\d+!\x7F/u.exec(inner ?? ''), attr = innerSyntax ? inner.slice(0, innerSyntax.index) : '';
|
|
116
116
|
if (/\[\[|-\{/u.test(attr)) {
|
|
117
117
|
innerSyntax = null;
|
|
@@ -121,7 +121,7 @@ let TdToken = (() => {
|
|
|
121
121
|
if (innerSyntax) {
|
|
122
122
|
[this.#innerSyntax] = innerSyntax;
|
|
123
123
|
}
|
|
124
|
-
const innerToken = new
|
|
124
|
+
const innerToken = new index_1.Token(inner?.slice((innerSyntax?.index ?? NaN) + this.#innerSyntax.length), config, accum);
|
|
125
125
|
innerToken.type = 'td-inner';
|
|
126
126
|
innerToken.setAttribute('stage', 4);
|
|
127
127
|
this.insertAt(innerToken);
|
|
@@ -160,7 +160,7 @@ let TdToken = (() => {
|
|
|
160
160
|
/* NOT FOR BROWSER */
|
|
161
161
|
const str = previousSibling.lastChild.toString();
|
|
162
162
|
result.escape ||= esc;
|
|
163
|
-
result.correction = str.includes('\n') && debug_1.Shadow.run(() => new
|
|
163
|
+
result.correction = str.includes('\n') && debug_1.Shadow.run(() => new index_1.Token(str, this.getAttribute('config'))
|
|
164
164
|
.parseOnce(0, this.getAttribute('include'))
|
|
165
165
|
.parseOnce()
|
|
166
166
|
.parseOnce()
|
|
@@ -250,7 +250,7 @@ let TdToken = (() => {
|
|
|
250
250
|
}
|
|
251
251
|
getAttr(key) {
|
|
252
252
|
const value = super.getAttr(key);
|
|
253
|
-
key =
|
|
253
|
+
key = (0, string_1.trimLc)(key);
|
|
254
254
|
return (key === 'rowspan' || key === 'colspan' ? parseInt(value) || 1 : value);
|
|
255
255
|
}
|
|
256
256
|
/** @private */
|
|
@@ -322,7 +322,7 @@ let TdToken = (() => {
|
|
|
322
322
|
}
|
|
323
323
|
return;
|
|
324
324
|
}
|
|
325
|
-
const key =
|
|
325
|
+
const key = (0, string_1.trimLc)(keyOrProp);
|
|
326
326
|
let v;
|
|
327
327
|
if (typeof value === 'number' && (key === 'rowspan' || key === 'colspan')) {
|
|
328
328
|
v = value === 1 ? false : String(value);
|
|
@@ -367,7 +367,7 @@ exports.TdToken = TdToken;
|
|
|
367
367
|
* @param config
|
|
368
368
|
*/
|
|
369
369
|
const createTd = (inner, subtype = 'td', attr = {}, include, config) => {
|
|
370
|
-
const innerToken = typeof inner === 'string' ?
|
|
370
|
+
const innerToken = typeof inner === 'string' ? index_2.default.parse(inner, include, undefined, config) : inner,
|
|
371
371
|
// @ts-expect-error abstract class
|
|
372
372
|
token = debug_1.Shadow.run(() => new TdToken('\n|', undefined, config));
|
|
373
373
|
token.setSyntax(subtype);
|
package/dist/src/table/tr.d.ts
CHANGED
|
@@ -13,12 +13,12 @@ export declare abstract class TrToken extends TrBaseToken {
|
|
|
13
13
|
abstract get lastChild(): AttributesToken | TdToken;
|
|
14
14
|
abstract get parentNode(): TableToken | undefined;
|
|
15
15
|
abstract get nextSibling(): this | SyntaxToken | undefined;
|
|
16
|
-
abstract get previousSibling(): Token;
|
|
16
|
+
abstract get previousSibling(): Token | undefined;
|
|
17
17
|
abstract get children(): [SyntaxToken, AttributesToken, ...TdToken[]];
|
|
18
18
|
abstract get lastElementChild(): AttributesToken | TdToken;
|
|
19
19
|
abstract get parentElement(): TableToken | undefined;
|
|
20
20
|
abstract get nextElementSibling(): this | SyntaxToken | undefined;
|
|
21
|
-
abstract get previousElementSibling(): Token;
|
|
21
|
+
abstract get previousElementSibling(): Token | undefined;
|
|
22
22
|
get type(): 'tr';
|
|
23
23
|
/**
|
|
24
24
|
* @param syntax 表格语法
|
package/dist/src/tagPair/ext.js
CHANGED
|
@@ -45,26 +45,10 @@ const attributesParent_1 = require("../../mixin/attributesParent");
|
|
|
45
45
|
const index_2 = require("../index");
|
|
46
46
|
const index_3 = require("./index");
|
|
47
47
|
const attributes_1 = require("../attributes");
|
|
48
|
-
const pre_1 = require("../pre");
|
|
49
|
-
const index_4 = require("../paramTag/index");
|
|
50
|
-
const inputbox_1 = require("../paramTag/inputbox");
|
|
51
|
-
const gallery_1 = require("../gallery");
|
|
52
|
-
const imagemap_1 = require("../imagemap");
|
|
53
|
-
const index_5 = require("../nowiki/index");
|
|
54
48
|
/* NOT FOR BROWSER */
|
|
55
49
|
const debug_1 = require("../../util/debug");
|
|
56
50
|
const constants_1 = require("../../util/constants");
|
|
57
51
|
const string_1 = require("../../util/string");
|
|
58
|
-
/**
|
|
59
|
-
* 从数组中删除指定元素
|
|
60
|
-
* @param arr 数组
|
|
61
|
-
* @param ele 元素
|
|
62
|
-
*/
|
|
63
|
-
const del = (arr, ele) => {
|
|
64
|
-
const set = new Set(arr);
|
|
65
|
-
set.delete(ele);
|
|
66
|
-
return [...set];
|
|
67
|
-
};
|
|
68
52
|
/**
|
|
69
53
|
* extension tag
|
|
70
54
|
*
|
|
@@ -102,13 +86,13 @@ let ExtToken = (() => {
|
|
|
102
86
|
// @ts-expect-error abstract class
|
|
103
87
|
attrToken = new attributes_1.AttributesToken(!attr || /^\s/u.test(attr) ? attr : ` ${attr}`, 'ext-attrs', lcName, config, accum), newConfig = {
|
|
104
88
|
...config,
|
|
105
|
-
ext:
|
|
106
|
-
excludes: [...config.excludes
|
|
89
|
+
ext: config.ext.filter(e => e !== lcName),
|
|
90
|
+
excludes: [...config.excludes],
|
|
107
91
|
};
|
|
108
92
|
let innerToken;
|
|
109
93
|
switch (lcName) {
|
|
110
94
|
case 'tab':
|
|
111
|
-
newConfig.ext =
|
|
95
|
+
newConfig.ext = newConfig.ext.filter(e => e !== 'tabs');
|
|
112
96
|
// fall through
|
|
113
97
|
case 'indicator':
|
|
114
98
|
case 'poem':
|
|
@@ -118,25 +102,33 @@ let ExtToken = (() => {
|
|
|
118
102
|
case 'tabs':
|
|
119
103
|
case 'poll':
|
|
120
104
|
case 'seo':
|
|
105
|
+
case 'langconvert':
|
|
106
|
+
case 'phonos':
|
|
121
107
|
if (lcName === 'poem') {
|
|
122
108
|
newConfig.excludes.push('heading');
|
|
123
109
|
}
|
|
124
110
|
innerToken = new index_2.Token(inner, newConfig, accum);
|
|
125
111
|
break;
|
|
126
|
-
case 'pre':
|
|
112
|
+
case 'pre': {
|
|
113
|
+
const { PreToken } = require('../pre');
|
|
127
114
|
// @ts-expect-error abstract class
|
|
128
|
-
innerToken = new
|
|
115
|
+
innerToken = new PreToken(inner, newConfig, accum);
|
|
129
116
|
break;
|
|
130
|
-
|
|
117
|
+
}
|
|
118
|
+
case 'dynamicpagelist': {
|
|
119
|
+
const { ParamTagToken } = require('../paramTag/index');
|
|
131
120
|
// @ts-expect-error abstract class
|
|
132
|
-
innerToken = new
|
|
121
|
+
innerToken = new ParamTagToken(include, inner, newConfig, accum);
|
|
133
122
|
break;
|
|
134
|
-
|
|
135
|
-
|
|
123
|
+
}
|
|
124
|
+
case 'inputbox': {
|
|
125
|
+
const { InputboxToken } = require('../paramTag/inputbox');
|
|
136
126
|
// @ts-expect-error abstract class
|
|
137
|
-
innerToken = new
|
|
127
|
+
innerToken = new InputboxToken(include, inner, newConfig, accum);
|
|
138
128
|
break;
|
|
129
|
+
}
|
|
139
130
|
case 'references': {
|
|
131
|
+
// NestedToken 依赖 ExtToken
|
|
140
132
|
const { NestedToken } = require('../nested');
|
|
141
133
|
newConfig.excludes.push('heading');
|
|
142
134
|
// @ts-expect-error abstract class
|
|
@@ -144,25 +136,37 @@ let ExtToken = (() => {
|
|
|
144
136
|
break;
|
|
145
137
|
}
|
|
146
138
|
case 'choose': {
|
|
139
|
+
// NestedToken 依赖 ExtToken
|
|
147
140
|
const { NestedToken } = require('../nested');
|
|
148
141
|
// @ts-expect-error abstract class
|
|
149
142
|
innerToken = new NestedToken(inner, /<(option|choicetemplate)(\s[^>]*?)?(?:\/>|>([\s\S]*?)<\/(\1)>)/gu, ['option', 'choicetemplate'], newConfig, accum);
|
|
150
143
|
break;
|
|
151
144
|
}
|
|
152
145
|
case 'combobox': {
|
|
146
|
+
// NestedToken 依赖 ExtToken
|
|
153
147
|
const { NestedToken } = require('../nested');
|
|
154
148
|
// @ts-expect-error abstract class
|
|
155
149
|
innerToken = new NestedToken(inner, /<(combooption)(\s[^>]*?)?(?:\/>|>([\s\S]*?)<\/(combooption\s*)>)/giu, ['combooption'], newConfig, accum);
|
|
156
150
|
break;
|
|
157
151
|
}
|
|
158
|
-
case 'gallery':
|
|
152
|
+
case 'gallery': {
|
|
153
|
+
const { GalleryToken } = require('../gallery');
|
|
154
|
+
// @ts-expect-error abstract class
|
|
155
|
+
innerToken = new GalleryToken(inner, newConfig, accum);
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
case 'imagemap': {
|
|
159
|
+
const { ImagemapToken } = require('../imagemap');
|
|
159
160
|
// @ts-expect-error abstract class
|
|
160
|
-
innerToken = new
|
|
161
|
+
innerToken = new ImagemapToken(inner, newConfig, accum);
|
|
161
162
|
break;
|
|
162
|
-
|
|
163
|
+
}
|
|
164
|
+
case 'hiero': {
|
|
165
|
+
const { CommentedToken } = require('../commented');
|
|
163
166
|
// @ts-expect-error abstract class
|
|
164
|
-
innerToken = new
|
|
167
|
+
innerToken = new CommentedToken(inner, newConfig, accum);
|
|
165
168
|
break;
|
|
169
|
+
}
|
|
166
170
|
// 更多定制扩展的代码示例:
|
|
167
171
|
// ```
|
|
168
172
|
// case 'extensionName': {
|
|
@@ -171,15 +175,18 @@ let ExtToken = (() => {
|
|
|
171
175
|
// break;
|
|
172
176
|
// }
|
|
173
177
|
// ```
|
|
174
|
-
default:
|
|
178
|
+
default: {
|
|
179
|
+
const { NowikiToken } = require('../nowiki/index');
|
|
175
180
|
// @ts-expect-error abstract class
|
|
176
|
-
innerToken = new
|
|
181
|
+
innerToken = new NowikiToken(inner, newConfig, accum);
|
|
182
|
+
}
|
|
177
183
|
}
|
|
178
184
|
innerToken.setAttribute('name', lcName);
|
|
179
185
|
if (innerToken.type === 'plain') {
|
|
180
186
|
innerToken.type = 'ext-inner';
|
|
181
187
|
}
|
|
182
188
|
super(name, attrToken, innerToken, closed, config, accum);
|
|
189
|
+
/* PRINT ONLY */
|
|
183
190
|
this.seal('closed', true);
|
|
184
191
|
}
|
|
185
192
|
/** @private */
|
|
@@ -11,7 +11,7 @@ export declare abstract class TagPairToken extends Token {
|
|
|
11
11
|
readonly name: string;
|
|
12
12
|
closed: boolean;
|
|
13
13
|
selfClosing: boolean;
|
|
14
|
-
abstract get type(): 'ext' | 'include';
|
|
14
|
+
abstract get type(): 'ext' | 'include' | 'translate';
|
|
15
15
|
readonly childNodes: readonly [AstNodes, AstNodes];
|
|
16
16
|
abstract get firstChild(): AstNodes;
|
|
17
17
|
abstract get lastChild(): AstNodes;
|
|
@@ -38,6 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
};
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
40
|
exports.TagPairToken = void 0;
|
|
41
|
+
const gapped_1 = require("../../mixin/gapped");
|
|
41
42
|
const index_1 = require("../index");
|
|
42
43
|
/* NOT FOR BROWSER */
|
|
43
44
|
const constants_1 = require("../../util/constants");
|
|
@@ -51,7 +52,7 @@ const index_2 = __importDefault(require("../../index"));
|
|
|
51
52
|
* 成对标签
|
|
52
53
|
*/
|
|
53
54
|
let TagPairToken = (() => {
|
|
54
|
-
let _classDecorators = [fixed_1.fixedToken, noEscape_1.noEscape];
|
|
55
|
+
let _classDecorators = [fixed_1.fixedToken, noEscape_1.noEscape, (0, gapped_1.gapped)()];
|
|
55
56
|
let _classDescriptor;
|
|
56
57
|
let _classExtraInitializers = [];
|
|
57
58
|
let _classThis;
|
|
@@ -121,10 +122,6 @@ let TagPairToken = (() => {
|
|
|
121
122
|
return key === 'padding' ? this.#tags[0].length + 1 : super.getAttribute(key);
|
|
122
123
|
}
|
|
123
124
|
/** @private */
|
|
124
|
-
getGaps() {
|
|
125
|
-
return 1;
|
|
126
|
-
}
|
|
127
|
-
/** @private */
|
|
128
125
|
print() {
|
|
129
126
|
const [opening, closing] = this.#tags;
|
|
130
127
|
return super.print(this.selfClosing
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Token } from '../index';
|
|
2
|
+
import { TagPairToken } from './index';
|
|
3
|
+
import { SyntaxToken } from '../syntax';
|
|
4
|
+
import type { Config } from '../../base';
|
|
5
|
+
import type { AttributesParentBase } from '../../mixin/attributesParent';
|
|
6
|
+
/**
|
|
7
|
+
* `<translate>`
|
|
8
|
+
* @classdesc `{childNodes: [SyntaxToken, Token]}`
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class TranslateToken extends TagPairToken implements Omit<AttributesParentBase, 'attributes' | 'className' | 'classList' | 'id' | 'getAttrNames' | 'getAttrs' | 'css'> {
|
|
11
|
+
#private;
|
|
12
|
+
name: 'translate';
|
|
13
|
+
closed: true;
|
|
14
|
+
selfClosing: false;
|
|
15
|
+
readonly childNodes: readonly [SyntaxToken, Token];
|
|
16
|
+
abstract get firstChild(): SyntaxToken;
|
|
17
|
+
abstract get lastChild(): Token;
|
|
18
|
+
abstract get children(): [SyntaxToken, Token];
|
|
19
|
+
abstract get firstElementChild(): SyntaxToken;
|
|
20
|
+
abstract get lastElementChild(): Token;
|
|
21
|
+
get type(): 'translate';
|
|
22
|
+
/**
|
|
23
|
+
* @param attr 标签属性
|
|
24
|
+
* @param inner 内部wikitext
|
|
25
|
+
*/
|
|
26
|
+
constructor(attr?: string, inner?: string, config?: Config, accum?: Token[]);
|
|
27
|
+
/** @implements */
|
|
28
|
+
getAttr(key: string): true | undefined;
|
|
29
|
+
/** @implements */
|
|
30
|
+
hasAttr(key: string): boolean;
|
|
31
|
+
/** @implements */
|
|
32
|
+
setAttr(keyOrProp: string | Record<string, string | boolean>, value?: string | boolean): void;
|
|
33
|
+
/** @implements */
|
|
34
|
+
removeAttr(key: string): void;
|
|
35
|
+
/** @implements */
|
|
36
|
+
toggleAttr(key: string, force?: boolean): void;
|
|
37
|
+
cloneNode(): this;
|
|
38
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TranslateToken = void 0;
|
|
4
|
+
const index_1 = require("../index");
|
|
5
|
+
const index_2 = require("./index");
|
|
6
|
+
const syntax_1 = require("../syntax");
|
|
7
|
+
const noinclude_1 = require("../nowiki/noinclude");
|
|
8
|
+
/* NOT FOR BROWSER */
|
|
9
|
+
const debug_1 = require("../../util/debug");
|
|
10
|
+
const constants_1 = require("../../util/constants");
|
|
11
|
+
const string_1 = require("../../util/string");
|
|
12
|
+
/* NOT FOR BROWSER END */
|
|
13
|
+
/**
|
|
14
|
+
* `<translate>`
|
|
15
|
+
* @classdesc `{childNodes: [SyntaxToken, Token]}`
|
|
16
|
+
*/
|
|
17
|
+
class TranslateToken extends index_2.TagPairToken {
|
|
18
|
+
/* NOT FOR BROWSER END */
|
|
19
|
+
get type() {
|
|
20
|
+
return 'translate';
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @param attr 标签属性
|
|
24
|
+
* @param inner 内部wikitext
|
|
25
|
+
*/
|
|
26
|
+
constructor(attr, inner, config, accum = []) {
|
|
27
|
+
const attrToken = new syntax_1.SyntaxToken(attr, /^(?: nowrap)?$/u, 'translate-attr', config, accum, { AstText: ':' });
|
|
28
|
+
inner = inner?.replace(/(<tvar\|[^>]+>)([\s\S]*?)(<\/>)/gu, (_, p1, p2, p3) => {
|
|
29
|
+
// @ts-expect-error abstract class
|
|
30
|
+
new noinclude_1.NoincludeToken(p1, config, accum);
|
|
31
|
+
// @ts-expect-error abstract class
|
|
32
|
+
new noinclude_1.NoincludeToken(p3, config, accum);
|
|
33
|
+
return `\0${accum.length - 1}n\x7F${p2}\0${accum.length}n\x7F`;
|
|
34
|
+
}).replace(/(<tvar\s+name\s*=(?:\s*(?:(["'])[\s\S]*?\2|[^"'\s>]+))?\s*>)([\s\S]*?)(<\/tvar\s*>)/giu, (_, p1, __, p3, p4) => {
|
|
35
|
+
// @ts-expect-error abstract class
|
|
36
|
+
new noinclude_1.NoincludeToken(p1, config, accum);
|
|
37
|
+
// @ts-expect-error abstract class
|
|
38
|
+
new noinclude_1.NoincludeToken(p4, config, accum);
|
|
39
|
+
return `\0${accum.length - 1}n\x7F${p3}\0${accum.length}n\x7F`;
|
|
40
|
+
});
|
|
41
|
+
const innerToken = new index_1.Token(inner, config, accum);
|
|
42
|
+
innerToken.type = 'translate-inner';
|
|
43
|
+
super('translate', attrToken, innerToken, 'translate', config, accum);
|
|
44
|
+
/* PRINT ONLY */
|
|
45
|
+
this.seal('closed', true);
|
|
46
|
+
this.seal('selfClosing', true);
|
|
47
|
+
}
|
|
48
|
+
/** @private */
|
|
49
|
+
toString(skip) {
|
|
50
|
+
return skip ? this.lastChild.toString(true) : super.toString();
|
|
51
|
+
}
|
|
52
|
+
/** @private */
|
|
53
|
+
text() {
|
|
54
|
+
return this.lastChild.text();
|
|
55
|
+
}
|
|
56
|
+
/* PRINT ONLY */
|
|
57
|
+
/** 是否有nowrap属性 */
|
|
58
|
+
#isNowrap() {
|
|
59
|
+
return this.firstChild.toString() === ' nowrap';
|
|
60
|
+
}
|
|
61
|
+
/** @private */
|
|
62
|
+
print() {
|
|
63
|
+
return `<span class="wpb-ext"><translate${this.#isNowrap()
|
|
64
|
+
? '<span class="wpb-ext-attrs"> <span class="wpb-ext-attr">'
|
|
65
|
+
+ '<span class="wpb-attr-key">nowrap</span>'
|
|
66
|
+
+ '</span></span>'
|
|
67
|
+
: ''}>${this.lastChild.print({ class: 'ext-inner' })}</translate></span>`;
|
|
68
|
+
}
|
|
69
|
+
/* PRINT ONLY END */
|
|
70
|
+
/* NOT FOR BROWSER */
|
|
71
|
+
/**
|
|
72
|
+
* 设置nowrap属性
|
|
73
|
+
* @param nowrap 是否nowrap
|
|
74
|
+
*/
|
|
75
|
+
#setNowrap(nowrap) {
|
|
76
|
+
this.firstChild.setText(nowrap ? ' nowrap' : '');
|
|
77
|
+
}
|
|
78
|
+
/** @implements */
|
|
79
|
+
getAttr(key) {
|
|
80
|
+
return (0, string_1.trimLc)(key) === 'nowrap' && this.#isNowrap() || undefined;
|
|
81
|
+
}
|
|
82
|
+
/** @implements */
|
|
83
|
+
hasAttr(key) {
|
|
84
|
+
return (0, string_1.trimLc)(key) === 'nowrap' && this.#isNowrap();
|
|
85
|
+
}
|
|
86
|
+
/** @implements */
|
|
87
|
+
setAttr(keyOrProp, value) {
|
|
88
|
+
if (typeof keyOrProp === 'object') {
|
|
89
|
+
for (const [key, val] of Object.entries(keyOrProp)) {
|
|
90
|
+
this.setAttr(key, val);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if ((0, string_1.trimLc)(keyOrProp) === 'nowrap') {
|
|
94
|
+
this.#setNowrap(value);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** @implements */
|
|
98
|
+
removeAttr(key) {
|
|
99
|
+
if ((0, string_1.trimLc)(key) === 'nowrap') {
|
|
100
|
+
this.firstChild.replaceChildren();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** @implements */
|
|
104
|
+
toggleAttr(key, force) {
|
|
105
|
+
if ((0, string_1.trimLc)(key) === 'nowrap') {
|
|
106
|
+
this.#setNowrap(force ?? !this.#isNowrap());
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
cloneNode() {
|
|
110
|
+
const inner = this.lastChild.cloneNode(), config = this.getAttribute('config'), attr = this.firstChild.toString() || undefined;
|
|
111
|
+
return debug_1.Shadow.run(() => {
|
|
112
|
+
// @ts-expect-error abstract class
|
|
113
|
+
const token = new TranslateToken(attr, undefined, config);
|
|
114
|
+
token.lastChild.safeReplaceWith(inner);
|
|
115
|
+
return token;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/** @private */
|
|
119
|
+
toHtmlInternal(opt) {
|
|
120
|
+
for (const { innerText, nextSibling } of this.querySelectorAll('comment')) {
|
|
121
|
+
if (nextSibling?.type === 'text' && /^T:[^_/\n<>~]+$/u.test(innerText) && /^[\n ]/u.test(nextSibling.data)) {
|
|
122
|
+
nextSibling.deleteData(0, 1);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return this.lastChild.toHtmlInternal(opt);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.TranslateToken = TranslateToken;
|
|
129
|
+
constants_1.classes['TranslateToken'] = __filename;
|
package/dist/src/transclude.js
CHANGED
|
@@ -43,6 +43,7 @@ const lint_1 = require("../util/lint");
|
|
|
43
43
|
const debug_1 = require("../util/debug");
|
|
44
44
|
const constants_1 = require("../util/constants");
|
|
45
45
|
const rect_1 = require("../lib/rect");
|
|
46
|
+
const gapped_1 = require("../mixin/gapped");
|
|
46
47
|
const index_1 = require("./index");
|
|
47
48
|
const parameter_1 = require("./parameter");
|
|
48
49
|
const atom_1 = require("./atom");
|
|
@@ -58,7 +59,7 @@ const basicMagicWords = new Map([['=', '='], ['!', '|']]);
|
|
|
58
59
|
* @classdesc `{childNodes: [AtomToken|SyntaxToken, ...AtomToken[], ...ParameterToken[]]}`
|
|
59
60
|
*/
|
|
60
61
|
let TranscludeToken = (() => {
|
|
61
|
-
let _classDecorators = [noEscape_1.noEscape];
|
|
62
|
+
let _classDecorators = [noEscape_1.noEscape, (0, gapped_1.gapped)()];
|
|
62
63
|
let _classDescriptor;
|
|
63
64
|
let _classExtraInitializers = [];
|
|
64
65
|
let _classThis;
|
|
@@ -192,7 +193,9 @@ let TranscludeToken = (() => {
|
|
|
192
193
|
// @ts-expect-error abstract class
|
|
193
194
|
this.insertAt(new parameter_1.ParameterToken(...part, config, accum));
|
|
194
195
|
}
|
|
196
|
+
/* PRINT ONLY */
|
|
195
197
|
this.seal('modifier');
|
|
198
|
+
/* PRINT ONLY END */
|
|
196
199
|
/* NOT FOR BROWSER */
|
|
197
200
|
this.protectChildren(0);
|
|
198
201
|
}
|
|
@@ -328,10 +331,6 @@ let TranscludeToken = (() => {
|
|
|
328
331
|
}
|
|
329
332
|
}
|
|
330
333
|
/** @private */
|
|
331
|
-
getGaps() {
|
|
332
|
-
return 1;
|
|
333
|
-
}
|
|
334
|
-
/** @private */
|
|
335
334
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
336
335
|
const errors = super.lint(start, re);
|
|
337
336
|
if (!this.isTemplate()) {
|
|
@@ -454,7 +453,7 @@ let TranscludeToken = (() => {
|
|
|
454
453
|
this.#args.set(keyStr, args);
|
|
455
454
|
}
|
|
456
455
|
/* NOT FOR BROWSER */
|
|
457
|
-
if (exact && keyStr.trim() &&
|
|
456
|
+
if (exact && keyStr.trim() && Number.isInteger(Number(keyStr))) {
|
|
458
457
|
args = new Set([...args].filter(({ anon }) => typeof key === 'number' === anon));
|
|
459
458
|
}
|
|
460
459
|
else if (copy) {
|
|
@@ -553,7 +552,7 @@ let TranscludeToken = (() => {
|
|
|
553
552
|
if (token.length > 1) {
|
|
554
553
|
token.removeAt(1);
|
|
555
554
|
}
|
|
556
|
-
token.
|
|
555
|
+
token.safeAppend(cloned);
|
|
557
556
|
return token;
|
|
558
557
|
});
|
|
559
558
|
}
|
package/dist/util/html.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* NOT FOR BROWSER */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.html = exports.getCommon = void 0;
|
|
4
|
+
exports.cloneNode = exports.html = exports.getCommon = void 0;
|
|
5
|
+
const debug_1 = require("./debug");
|
|
5
6
|
/* NOT FOR BROWSER END */
|
|
6
7
|
/**
|
|
7
8
|
* get common prefix length
|
|
@@ -16,7 +17,6 @@ exports.getCommon = getCommon;
|
|
|
16
17
|
* get next list item
|
|
17
18
|
* @param char list syntax
|
|
18
19
|
* @param state
|
|
19
|
-
* @param state.dt whether a <dt> tag is open
|
|
20
20
|
*/
|
|
21
21
|
const nextItem = (char, state) => {
|
|
22
22
|
if (char === '*' || char === '#') {
|
|
@@ -34,7 +34,6 @@ const nextItem = (char, state) => {
|
|
|
34
34
|
* close list item
|
|
35
35
|
* @param chars list syntax
|
|
36
36
|
* @param state
|
|
37
|
-
* @param state.dt whether a <dt> tag is open
|
|
38
37
|
*/
|
|
39
38
|
const closeList = (chars, state) => {
|
|
40
39
|
let result = '';
|
|
@@ -58,7 +57,6 @@ const closeList = (chars, state) => {
|
|
|
58
57
|
* open list item
|
|
59
58
|
* @param chars list syntax
|
|
60
59
|
* @param state
|
|
61
|
-
* @param state.dt whether a <dt> tag is open
|
|
62
60
|
*/
|
|
63
61
|
const openList = (chars, state) => {
|
|
64
62
|
let result = '';
|
|
@@ -134,3 +132,17 @@ const html = (childNodes, separator = '', opt) => {
|
|
|
134
132
|
return results.join(separator);
|
|
135
133
|
};
|
|
136
134
|
exports.html = html;
|
|
135
|
+
/**
|
|
136
|
+
* basic function of `cloneNode`
|
|
137
|
+
* @param token token to clone
|
|
138
|
+
* @param f empty token constructor
|
|
139
|
+
*/
|
|
140
|
+
const cloneNode = (token, f) => {
|
|
141
|
+
const cloned = token.cloneChildNodes();
|
|
142
|
+
return debug_1.Shadow.run(() => {
|
|
143
|
+
const newToken = f();
|
|
144
|
+
newToken.safeAppend(cloned);
|
|
145
|
+
return newToken;
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
exports.cloneNode = cloneNode;
|
package/dist/util/lint.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.provideValues = exports.cache = exports.generateForSelf = exports.generateForChild = exports.getEndPos = void 0;
|
|
7
7
|
const debug_1 = require("./debug");
|
|
8
8
|
const rect_1 = require("../lib/rect");
|
|
9
9
|
const index_1 = __importDefault(require("../index"));
|
|
@@ -65,34 +65,21 @@ const cache = (store, compute, update) => {
|
|
|
65
65
|
return result;
|
|
66
66
|
};
|
|
67
67
|
exports.cache = cache;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
/**
|
|
69
|
+
* 获取HTML属性值可选列表
|
|
70
|
+
* @param tag 标签名
|
|
71
|
+
* @param attribute 属性名
|
|
72
|
+
*/
|
|
73
|
+
const provideValues = (tag, attribute) => {
|
|
74
|
+
if (tag === 'ol' && attribute === 'type') {
|
|
75
|
+
return ['1', 'a', 'A', 'i', 'I'];
|
|
72
76
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
* 获取HTML属性值可选列表
|
|
76
|
-
* @param tag 标签名
|
|
77
|
-
* @param attribute 属性名
|
|
78
|
-
*/
|
|
79
|
-
const provideValues = (tag, attribute) => {
|
|
80
|
-
if (tag === 'ol' && attribute === 'type') {
|
|
81
|
-
return ['1', 'a', 'A', 'i', 'I'];
|
|
82
|
-
}
|
|
83
|
-
else if (tag === 'th' && attribute === 'scope') {
|
|
84
|
-
return ['row', 'col', 'rowgroup', 'colgroup'];
|
|
85
|
-
}
|
|
86
|
-
else if (attribute === 'dir') {
|
|
87
|
-
return ['ltr', 'rtl', 'auto'];
|
|
88
|
-
}
|
|
89
|
-
return attribute === 'aria-hidden' ? ['true', 'false'] : [];
|
|
90
|
-
};
|
|
91
|
-
return {
|
|
92
|
-
/** @implements */
|
|
93
|
-
provideValues(tag, attribute) {
|
|
94
|
-
return provideValues(tag, attribute).map(value => ({ name: value }));
|
|
95
|
-
},
|
|
96
|
-
};
|
|
77
|
+
else if (tag === 'th' && attribute === 'scope') {
|
|
78
|
+
return ['row', 'col', 'rowgroup', 'colgroup'];
|
|
97
79
|
}
|
|
98
|
-
|
|
80
|
+
else if (attribute === 'dir') {
|
|
81
|
+
return ['ltr', 'rtl', 'auto'];
|
|
82
|
+
}
|
|
83
|
+
return attribute === 'aria-hidden' ? ['true', 'false'] : [];
|
|
84
|
+
};
|
|
85
|
+
exports.provideValues = provideValues;
|
package/dist/util/sharable.js
CHANGED
|
@@ -2,7 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.obsoleteAttrs = exports.extAttrs = exports.htmlAttrs = exports.commonHtmlAttrs = void 0;
|
|
4
4
|
/* eslint-disable unicorn/no-unreadable-iife */
|
|
5
|
-
const blockAttrs = new Set(['align']), citeAttrs = new Set(['cite']), citeAndAttrs = new Set(['cite', 'datetime']), widthAttrs = new Set(['width']), obsoleteTdAttrs = new Set(['axis', 'align', 'bgcolor', 'height', 'width', 'valign']), tdAttrs = new Set([...obsoleteTdAttrs, 'abbr', 'headers', 'scope', 'rowspan', 'colspan']), typeAttrs = new Set(['type']), obsoleteTableAttrs = new Set(['summary', 'align', 'bgcolor', 'cellpadding', 'cellspacing', 'frame', 'rules', 'width']), brAttrs = new Set(['clear']), trAttrs = new Set(['bgcolor', 'align', 'valign']),
|
|
5
|
+
const blockAttrs = new Set(['align']), citeAttrs = new Set(['cite']), citeAndAttrs = new Set(['cite', 'datetime']), widthAttrs = new Set(['width']), obsoleteTdAttrs = new Set(['axis', 'align', 'bgcolor', 'height', 'width', 'valign']), tdAttrs = new Set([...obsoleteTdAttrs, 'abbr', 'headers', 'scope', 'rowspan', 'colspan']), typeAttrs = new Set(['type']), obsoleteTableAttrs = new Set(['summary', 'align', 'bgcolor', 'cellpadding', 'cellspacing', 'frame', 'rules', 'width']), brAttrs = new Set(['clear']), trAttrs = new Set(['bgcolor', 'align', 'valign']), chemAttrs = new Set(['qid', 'forcemathmode', 'type', 'display']), syntaxHighlightAttrs = new Set([
|
|
6
|
+
'enclose',
|
|
7
|
+
'inline',
|
|
8
|
+
'lang',
|
|
9
|
+
'line',
|
|
10
|
+
'linelinks',
|
|
11
|
+
'style',
|
|
12
|
+
'class',
|
|
13
|
+
'id',
|
|
14
|
+
'dir',
|
|
15
|
+
'copy',
|
|
16
|
+
'highlight',
|
|
17
|
+
'start',
|
|
18
|
+
]), empty = new Set();
|
|
6
19
|
exports.commonHtmlAttrs = new Set([
|
|
7
20
|
'id',
|
|
8
21
|
'class',
|
|
@@ -63,6 +76,9 @@ exports.commonHtmlAttrs = new Set([
|
|
|
63
76
|
poem: blockAttrs,
|
|
64
77
|
categorytree: blockAttrs,
|
|
65
78
|
combooption: blockAttrs,
|
|
79
|
+
math: empty,
|
|
80
|
+
chem: empty,
|
|
81
|
+
ce: empty,
|
|
66
82
|
}))(), exports.extAttrs = (() => ({
|
|
67
83
|
gallery: new Set(['mode', 'showfilename', 'caption', 'perrow', 'widths', 'heights', 'showthumbnails']),
|
|
68
84
|
poem: new Set(['compact']),
|
|
@@ -142,6 +158,18 @@ exports.commonHtmlAttrs = new Set([
|
|
|
142
158
|
]),
|
|
143
159
|
tabs: new Set(['plain', 'class', 'container', 'id', 'title', 'style']),
|
|
144
160
|
combobox: new Set(['placeholder', 'value', 'id', 'class', 'text', 'dropdown', 'style']),
|
|
161
|
+
math: new Set([...chemAttrs, 'chem']),
|
|
162
|
+
chem: chemAttrs,
|
|
163
|
+
ce: chemAttrs,
|
|
164
|
+
hiero: empty,
|
|
165
|
+
phonos: new Set(['ipa', 'class', 'text', 'lang', 'wikibase', 'file']),
|
|
166
|
+
section: new Set(['begin', 'end']),
|
|
167
|
+
source: syntaxHighlightAttrs,
|
|
168
|
+
syntaxhighlight: syntaxHighlightAttrs,
|
|
169
|
+
templatedata: empty,
|
|
170
|
+
timeline: new Set(['method', 'font']),
|
|
171
|
+
quiz: new Set(['display', 'shuffleanswers', 'points', 'shuffle', 'case']),
|
|
172
|
+
languages: empty,
|
|
145
173
|
}))(), exports.obsoleteAttrs = (() => ({
|
|
146
174
|
table: obsoleteTableAttrs,
|
|
147
175
|
td: new Set([...obsoleteTdAttrs, 'scope']),
|