wikiparser-node 1.4.2 → 1.4.3-b
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/bundle/bundle.min.js +36 -0
- package/config/enwiki.json +1 -814
- package/config/llwiki.json +1 -35
- package/config/moegirl.json +1 -44
- package/config/zhwiki.json +1 -466
- package/extensions/dist/base.js +64 -0
- package/extensions/dist/editor.js +159 -0
- package/extensions/dist/highlight.js +59 -0
- package/extensions/dist/lint.js +48 -0
- package/extensions/editor.css +63 -0
- package/extensions/ui.css +141 -0
- package/package.json +30 -15
- package/config/.schema.json +0 -172
- package/dist/addon/table.d.ts +0 -6
- package/dist/addon/table.js +0 -560
- package/dist/base.d.ts +0 -53
- package/dist/index.d.ts +0 -32
- package/dist/index.js +0 -211
- package/dist/internal.d.ts +0 -44
- package/dist/lib/element.d.ts +0 -154
- package/dist/lib/element.js +0 -643
- package/dist/lib/node.d.ts +0 -146
- package/dist/lib/node.js +0 -425
- package/dist/lib/range.d.ts +0 -104
- package/dist/lib/range.js +0 -385
- package/dist/lib/ranges.d.ts +0 -26
- package/dist/lib/ranges.js +0 -118
- package/dist/lib/text.d.ts +0 -62
- package/dist/lib/text.js +0 -306
- package/dist/lib/title.d.ts +0 -38
- package/dist/lib/title.js +0 -172
- package/dist/mixin/attributesParent.d.ts +0 -20
- package/dist/mixin/attributesParent.js +0 -89
- package/dist/mixin/fixed.d.ts +0 -5
- package/dist/mixin/fixed.js +0 -28
- package/dist/mixin/flagsParent.d.ts +0 -61
- package/dist/mixin/flagsParent.js +0 -72
- package/dist/mixin/hidden.d.ts +0 -5
- package/dist/mixin/hidden.js +0 -24
- package/dist/mixin/magicLinkParent.d.ts +0 -34
- package/dist/mixin/magicLinkParent.js +0 -43
- package/dist/mixin/singleLine.d.ts +0 -5
- package/dist/mixin/singleLine.js +0 -25
- package/dist/mixin/sol.d.ts +0 -8
- package/dist/mixin/sol.js +0 -41
- package/dist/mixin/syntax.d.ts +0 -6
- package/dist/mixin/syntax.js +0 -54
- package/dist/parser/braces.js +0 -131
- package/dist/parser/commentAndExt.js +0 -90
- package/dist/parser/converter.js +0 -41
- package/dist/parser/externalLinks.js +0 -32
- package/dist/parser/hrAndDoubleUnderscore.js +0 -41
- package/dist/parser/html.js +0 -39
- package/dist/parser/links.js +0 -97
- package/dist/parser/list.js +0 -68
- package/dist/parser/magicLinks.js +0 -43
- package/dist/parser/quotes.js +0 -68
- package/dist/parser/selector.js +0 -162
- package/dist/parser/table.js +0 -124
- package/dist/src/arg.d.ts +0 -58
- package/dist/src/arg.js +0 -196
- package/dist/src/atom.d.ts +0 -12
- package/dist/src/atom.js +0 -27
- package/dist/src/attribute.d.ts +0 -67
- package/dist/src/attribute.js +0 -422
- package/dist/src/attributes.d.ts +0 -109
- package/dist/src/attributes.js +0 -347
- package/dist/src/converter.d.ts +0 -28
- package/dist/src/converter.js +0 -85
- package/dist/src/converterFlags.d.ts +0 -87
- package/dist/src/converterFlags.js +0 -227
- package/dist/src/converterRule.d.ts +0 -77
- package/dist/src/converterRule.js +0 -210
- package/dist/src/extLink.d.ts +0 -38
- package/dist/src/extLink.js +0 -137
- package/dist/src/gallery.d.ts +0 -54
- package/dist/src/gallery.js +0 -127
- package/dist/src/heading.d.ts +0 -47
- package/dist/src/heading.js +0 -143
- package/dist/src/hidden.d.ts +0 -7
- package/dist/src/hidden.js +0 -23
- package/dist/src/html.d.ts +0 -62
- package/dist/src/html.js +0 -286
- package/dist/src/imageParameter.d.ts +0 -65
- package/dist/src/imageParameter.js +0 -247
- package/dist/src/imagemap.d.ts +0 -56
- package/dist/src/imagemap.js +0 -156
- package/dist/src/imagemapLink.d.ts +0 -28
- package/dist/src/imagemapLink.js +0 -44
- package/dist/src/index.d.ts +0 -143
- package/dist/src/index.js +0 -804
- package/dist/src/link/base.d.ts +0 -52
- package/dist/src/link/base.js +0 -212
- package/dist/src/link/category.d.ts +0 -13
- package/dist/src/link/category.js +0 -28
- package/dist/src/link/file.d.ts +0 -96
- package/dist/src/link/file.js +0 -266
- package/dist/src/link/galleryImage.d.ts +0 -31
- package/dist/src/link/galleryImage.js +0 -109
- package/dist/src/link/index.d.ts +0 -56
- package/dist/src/link/index.js +0 -134
- package/dist/src/magicLink.d.ts +0 -51
- package/dist/src/magicLink.js +0 -149
- package/dist/src/nested.d.ts +0 -43
- package/dist/src/nested.js +0 -91
- package/dist/src/nowiki/base.d.ts +0 -27
- package/dist/src/nowiki/base.js +0 -42
- package/dist/src/nowiki/comment.d.ts +0 -27
- package/dist/src/nowiki/comment.js +0 -77
- package/dist/src/nowiki/dd.d.ts +0 -8
- package/dist/src/nowiki/dd.js +0 -24
- package/dist/src/nowiki/doubleUnderscore.d.ts +0 -18
- package/dist/src/nowiki/doubleUnderscore.js +0 -51
- package/dist/src/nowiki/hr.d.ts +0 -8
- package/dist/src/nowiki/hr.js +0 -14
- package/dist/src/nowiki/index.d.ts +0 -16
- package/dist/src/nowiki/index.js +0 -20
- package/dist/src/nowiki/list.d.ts +0 -19
- package/dist/src/nowiki/list.js +0 -48
- package/dist/src/nowiki/listBase.d.ts +0 -5
- package/dist/src/nowiki/listBase.js +0 -11
- package/dist/src/nowiki/noinclude.d.ts +0 -10
- package/dist/src/nowiki/noinclude.js +0 -23
- package/dist/src/nowiki/quote.d.ts +0 -14
- package/dist/src/nowiki/quote.js +0 -68
- package/dist/src/onlyinclude.d.ts +0 -16
- package/dist/src/onlyinclude.js +0 -57
- package/dist/src/paramTag/index.d.ts +0 -37
- package/dist/src/paramTag/index.js +0 -68
- package/dist/src/paramTag/inputbox.d.ts +0 -8
- package/dist/src/paramTag/inputbox.js +0 -22
- package/dist/src/parameter.d.ts +0 -67
- package/dist/src/parameter.js +0 -213
- package/dist/src/pre.d.ts +0 -28
- package/dist/src/pre.js +0 -54
- package/dist/src/syntax.d.ts +0 -14
- package/dist/src/syntax.js +0 -35
- package/dist/src/table/base.d.ts +0 -27
- package/dist/src/table/base.js +0 -81
- package/dist/src/table/index.d.ts +0 -230
- package/dist/src/table/index.js +0 -390
- package/dist/src/table/td.d.ts +0 -88
- package/dist/src/table/td.js +0 -284
- package/dist/src/table/tr.d.ts +0 -32
- package/dist/src/table/tr.js +0 -57
- package/dist/src/table/trBase.d.ts +0 -53
- package/dist/src/table/trBase.js +0 -154
- package/dist/src/tagPair/ext.d.ts +0 -29
- package/dist/src/tagPair/ext.js +0 -153
- package/dist/src/tagPair/include.d.ts +0 -37
- package/dist/src/tagPair/include.js +0 -71
- package/dist/src/tagPair/index.d.ts +0 -27
- package/dist/src/tagPair/index.js +0 -79
- package/dist/src/transclude.d.ts +0 -167
- package/dist/src/transclude.js +0 -715
- package/dist/util/constants.js +0 -113
- package/dist/util/debug.js +0 -90
- package/dist/util/diff.js +0 -82
- package/dist/util/lint.js +0 -30
- package/dist/util/string.js +0 -53
- package/errors/README +0 -1
- package/printed/README +0 -1
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _Printer_instances, _Printer_id, _Printer_preview, _Printer_textbox, _Printer_root, _Printer_viewportChanged, _Printer_running, _Printer_ticks, _Printer_tick, _Printer_exec, _Printer_paint, _Printer_coarsePrint, _Printer_finePrint;
|
|
14
|
+
class Printer {
|
|
15
|
+
constructor(preview, textbox, include) {
|
|
16
|
+
_Printer_instances.add(this);
|
|
17
|
+
_Printer_id.set(this, void 0);
|
|
18
|
+
_Printer_preview.set(this, void 0);
|
|
19
|
+
_Printer_textbox.set(this, void 0);
|
|
20
|
+
_Printer_root.set(this, void 0);
|
|
21
|
+
_Printer_viewportChanged.set(this, void 0);
|
|
22
|
+
_Printer_running.set(this, void 0);
|
|
23
|
+
_Printer_ticks.set(this, void 0);
|
|
24
|
+
__classPrivateFieldSet(this, _Printer_id, wikiparse.id++, "f");
|
|
25
|
+
__classPrivateFieldSet(this, _Printer_preview, preview, "f");
|
|
26
|
+
__classPrivateFieldSet(this, _Printer_textbox, textbox, "f");
|
|
27
|
+
__classPrivateFieldSet(this, _Printer_root, [], "f");
|
|
28
|
+
__classPrivateFieldSet(this, _Printer_viewportChanged, false, "f");
|
|
29
|
+
this.include = Boolean(include);
|
|
30
|
+
__classPrivateFieldSet(this, _Printer_ticks, [0, undefined], "f");
|
|
31
|
+
}
|
|
32
|
+
queue(delay, method) {
|
|
33
|
+
const [state] = __classPrivateFieldGet(this, _Printer_ticks, "f");
|
|
34
|
+
if (delay === 0 || state <= 0 || method === 0 || __classPrivateFieldGet(this, _Printer_ticks, "f")[1] !== 0) {
|
|
35
|
+
__classPrivateFieldSet(this, _Printer_ticks, [delay, method], "f");
|
|
36
|
+
if (delay === 0) {
|
|
37
|
+
__classPrivateFieldGet(this, _Printer_instances, "m", _Printer_exec).call(this, method);
|
|
38
|
+
}
|
|
39
|
+
else if (state <= 0) {
|
|
40
|
+
__classPrivateFieldGet(this, _Printer_instances, "m", _Printer_tick).call(this);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
_Printer_id = new WeakMap(), _Printer_preview = new WeakMap(), _Printer_textbox = new WeakMap(), _Printer_root = new WeakMap(), _Printer_viewportChanged = new WeakMap(), _Printer_running = new WeakMap(), _Printer_ticks = new WeakMap(), _Printer_instances = new WeakSet(), _Printer_tick = function _Printer_tick() {
|
|
46
|
+
setTimeout(() => {
|
|
47
|
+
const [t, method] = __classPrivateFieldGet(this, _Printer_ticks, "f");
|
|
48
|
+
if (t > 0) {
|
|
49
|
+
__classPrivateFieldGet(this, _Printer_ticks, "f")[0] -= 500;
|
|
50
|
+
if (t <= 500) {
|
|
51
|
+
__classPrivateFieldGet(this, _Printer_instances, "m", _Printer_exec).call(this, method);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
__classPrivateFieldGet(this, _Printer_instances, "m", _Printer_tick).call(this);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}, 500);
|
|
58
|
+
}, _Printer_exec = function _Printer_exec(method) {
|
|
59
|
+
if (method === 0) {
|
|
60
|
+
__classPrivateFieldGet(this, _Printer_instances, "m", _Printer_coarsePrint).call(this);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
__classPrivateFieldGet(this, _Printer_instances, "m", _Printer_finePrint).call(this);
|
|
64
|
+
}
|
|
65
|
+
}, _Printer_paint = function _Printer_paint() {
|
|
66
|
+
__classPrivateFieldGet(this, _Printer_preview, "f").innerHTML = `<span class="wpb-root">${__classPrivateFieldGet(this, _Printer_root, "f").map(([, , printed]) => printed).join('')}</span> `;
|
|
67
|
+
__classPrivateFieldGet(this, _Printer_preview, "f").scrollTop = __classPrivateFieldGet(this, _Printer_textbox, "f").scrollTop;
|
|
68
|
+
__classPrivateFieldGet(this, _Printer_preview, "f").classList.remove('active');
|
|
69
|
+
__classPrivateFieldGet(this, _Printer_textbox, "f").style.color = 'transparent';
|
|
70
|
+
}, _Printer_coarsePrint = async function _Printer_coarsePrint() {
|
|
71
|
+
if (__classPrivateFieldGet(this, _Printer_running, "f")) {
|
|
72
|
+
return __classPrivateFieldGet(this, _Printer_running, "f");
|
|
73
|
+
}
|
|
74
|
+
const { include } = this, { value } = __classPrivateFieldGet(this, _Printer_textbox, "f"), parsed = await wikiparse.print(value, include, 2, __classPrivateFieldGet(this, _Printer_id, "f"));
|
|
75
|
+
if (this.include !== include || __classPrivateFieldGet(this, _Printer_textbox, "f").value !== value) {
|
|
76
|
+
__classPrivateFieldSet(this, _Printer_running, undefined, "f");
|
|
77
|
+
__classPrivateFieldSet(this, _Printer_running, __classPrivateFieldGet(this, _Printer_instances, "m", _Printer_coarsePrint).call(this), "f");
|
|
78
|
+
return __classPrivateFieldGet(this, _Printer_running, "f");
|
|
79
|
+
}
|
|
80
|
+
__classPrivateFieldSet(this, _Printer_root, parsed, "f");
|
|
81
|
+
__classPrivateFieldGet(this, _Printer_instances, "m", _Printer_paint).call(this);
|
|
82
|
+
__classPrivateFieldSet(this, _Printer_running, undefined, "f");
|
|
83
|
+
__classPrivateFieldSet(this, _Printer_running, __classPrivateFieldGet(this, _Printer_instances, "m", _Printer_finePrint).call(this), "f");
|
|
84
|
+
return __classPrivateFieldGet(this, _Printer_running, "f");
|
|
85
|
+
}, _Printer_finePrint = async function _Printer_finePrint() {
|
|
86
|
+
if (__classPrivateFieldGet(this, _Printer_running, "f")) {
|
|
87
|
+
__classPrivateFieldSet(this, _Printer_viewportChanged, true, "f");
|
|
88
|
+
return __classPrivateFieldGet(this, _Printer_running, "f");
|
|
89
|
+
}
|
|
90
|
+
__classPrivateFieldSet(this, _Printer_viewportChanged, false, "f");
|
|
91
|
+
const { include } = this, { value } = __classPrivateFieldGet(this, _Printer_textbox, "f"), { scrollHeight, offsetHeight: parentHeight, scrollTop, children: [rootNode] } = __classPrivateFieldGet(this, _Printer_preview, "f");
|
|
92
|
+
let text = value, start = 0, { length: end } = __classPrivateFieldGet(this, _Printer_root, "f");
|
|
93
|
+
if (scrollHeight > parentHeight) {
|
|
94
|
+
const childNodes = [...rootNode.childNodes], headings = childNodes.filter(({ className }) => className === 'wpb-heading'), { length } = headings;
|
|
95
|
+
if (length > 0) {
|
|
96
|
+
let i = headings.findIndex(({ offsetTop, offsetHeight }) => offsetTop + offsetHeight > scrollTop);
|
|
97
|
+
i = i === -1 ? length : i;
|
|
98
|
+
let j = headings.slice(i).findIndex(({ offsetTop }) => offsetTop >= scrollTop + parentHeight);
|
|
99
|
+
j = j === -1 ? length : i + j;
|
|
100
|
+
start = i ? childNodes.indexOf(headings[i - 1]) : 0;
|
|
101
|
+
while (i <= j && __classPrivateFieldGet(this, _Printer_root, "f")[start][0] === Infinity) {
|
|
102
|
+
start = childNodes.indexOf(headings[i++]);
|
|
103
|
+
}
|
|
104
|
+
end = j === length ? end : childNodes.indexOf(headings[j]);
|
|
105
|
+
while (i <= j && __classPrivateFieldGet(this, _Printer_root, "f")[end - 1][0] === Infinity) {
|
|
106
|
+
end = childNodes.indexOf(headings[--j]);
|
|
107
|
+
}
|
|
108
|
+
text = __classPrivateFieldGet(this, _Printer_root, "f").slice(start, end).map(([, str]) => str).join('');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (start === end) {
|
|
112
|
+
__classPrivateFieldSet(this, _Printer_running, undefined, "f");
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
const parsed = await wikiparse.print(text, include, undefined, __classPrivateFieldGet(this, _Printer_id, "f"));
|
|
116
|
+
if (this.include === include && __classPrivateFieldGet(this, _Printer_textbox, "f").value === value) {
|
|
117
|
+
__classPrivateFieldGet(this, _Printer_root, "f").splice(start, end - start, ...parsed);
|
|
118
|
+
__classPrivateFieldGet(this, _Printer_instances, "m", _Printer_paint).call(this);
|
|
119
|
+
__classPrivateFieldSet(this, _Printer_running, undefined, "f");
|
|
120
|
+
if (__classPrivateFieldGet(this, _Printer_viewportChanged, "f")) {
|
|
121
|
+
__classPrivateFieldSet(this, _Printer_running, __classPrivateFieldGet(this, _Printer_instances, "m", _Printer_finePrint).call(this), "f");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
__classPrivateFieldSet(this, _Printer_running, undefined, "f");
|
|
126
|
+
__classPrivateFieldSet(this, _Printer_running, __classPrivateFieldGet(this, _Printer_instances, "m", _Printer_coarsePrint).call(this), "f");
|
|
127
|
+
}
|
|
128
|
+
return __classPrivateFieldGet(this, _Printer_running, "f");
|
|
129
|
+
};
|
|
130
|
+
const edit = (textbox, include) => {
|
|
131
|
+
if (!(textbox instanceof HTMLTextAreaElement)) {
|
|
132
|
+
throw new TypeError('wikiparse.edit方法仅可用于textarea元素!');
|
|
133
|
+
}
|
|
134
|
+
const preview = document.createElement('div'), container = document.createElement('div'), printer = new Printer(preview, textbox, include);
|
|
135
|
+
preview.id = 'wikiPretty';
|
|
136
|
+
preview.classList.add('wikiparser', 'active');
|
|
137
|
+
container.className = 'wikiparse-container';
|
|
138
|
+
textbox.replaceWith(container);
|
|
139
|
+
textbox.classList.add('wikiparsed');
|
|
140
|
+
container.append(preview, textbox);
|
|
141
|
+
textbox.addEventListener('input', e => {
|
|
142
|
+
if (!e.isComposing) {
|
|
143
|
+
printer.queue(2000, 0);
|
|
144
|
+
}
|
|
145
|
+
textbox.style.color = '';
|
|
146
|
+
preview.classList.add('active');
|
|
147
|
+
});
|
|
148
|
+
textbox.addEventListener('scroll', () => {
|
|
149
|
+
if (preview.scrollHeight > preview.offsetHeight && !preview.classList.contains('active')) {
|
|
150
|
+
preview.scrollTop = textbox.scrollTop;
|
|
151
|
+
printer.queue(500, 1);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
printer.queue(0, 0);
|
|
155
|
+
return printer;
|
|
156
|
+
};
|
|
157
|
+
wikiparse.Printer = Printer;
|
|
158
|
+
wikiparse.edit = edit;
|
|
159
|
+
})();
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
"use strict";
|
|
3
|
+
const append = (parent, text) => {
|
|
4
|
+
if (text) {
|
|
5
|
+
parent.append(text);
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
const splitNewLine = (html) => {
|
|
9
|
+
let cur = html.cloneNode();
|
|
10
|
+
const result = [cur];
|
|
11
|
+
for (const child of html.childNodes) {
|
|
12
|
+
const { textContent } = child;
|
|
13
|
+
if (!(textContent === null || textContent === void 0 ? void 0 : textContent.includes('\n'))) {
|
|
14
|
+
cur.append(child.cloneNode(true));
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const lines = child.nodeType === Node.TEXT_NODE
|
|
18
|
+
? textContent.split('\n')
|
|
19
|
+
: splitNewLine(child);
|
|
20
|
+
append(cur, lines[0]);
|
|
21
|
+
for (const text of lines.slice(1)) {
|
|
22
|
+
cur = html.cloneNode();
|
|
23
|
+
result.push(cur);
|
|
24
|
+
append(cur, text);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
const highlight = async (ele, include, linenums = false, start = 1) => {
|
|
30
|
+
if (ele.classList.contains('wikiparser')) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const html = (await wikiparse.print(ele.innerText, include)).map(([, , printed]) => printed).join('');
|
|
34
|
+
ele.classList.add('wikiparser');
|
|
35
|
+
if (linenums) {
|
|
36
|
+
const root = document.createElement('span');
|
|
37
|
+
root.className = 'wpb-root';
|
|
38
|
+
root.innerHTML = html;
|
|
39
|
+
const lines = splitNewLine(root).map((line, i) => {
|
|
40
|
+
const li = document.createElement('li');
|
|
41
|
+
li.id = `L${i + start}`;
|
|
42
|
+
li.append(line);
|
|
43
|
+
return li;
|
|
44
|
+
}), { length } = lines;
|
|
45
|
+
if (length > 1 && !lines[length - 1].textContent) {
|
|
46
|
+
lines.pop();
|
|
47
|
+
}
|
|
48
|
+
const ol = document.createElement('ol');
|
|
49
|
+
ol.style.counterReset = `wikiparser ${start - 1}`;
|
|
50
|
+
ol.style.paddingLeft = `${String(lines.length + start - 1).length + 1.5}ch`;
|
|
51
|
+
ol.replaceChildren(...lines);
|
|
52
|
+
ele.replaceChildren(ol);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
ele.innerHTML = html;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
wikiparse.highlight = highlight;
|
|
59
|
+
})();
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _Linter_instances, _Linter_id, _Linter_wikitext, _Linter_running, _Linter_lint;
|
|
14
|
+
class Linter {
|
|
15
|
+
constructor(include) {
|
|
16
|
+
_Linter_instances.add(this);
|
|
17
|
+
_Linter_id.set(this, void 0);
|
|
18
|
+
_Linter_wikitext.set(this, void 0);
|
|
19
|
+
_Linter_running.set(this, void 0);
|
|
20
|
+
__classPrivateFieldSet(this, _Linter_id, wikiparse.id++, "f");
|
|
21
|
+
this.include = Boolean(include);
|
|
22
|
+
}
|
|
23
|
+
queue(wikitext) {
|
|
24
|
+
var _a;
|
|
25
|
+
__classPrivateFieldSet(this, _Linter_wikitext, wikitext, "f");
|
|
26
|
+
__classPrivateFieldSet(this, _Linter_running, (_a = __classPrivateFieldGet(this, _Linter_running, "f")) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _Linter_instances, "m", _Linter_lint).call(this, wikitext), "f");
|
|
27
|
+
return __classPrivateFieldGet(this, _Linter_running, "f");
|
|
28
|
+
}
|
|
29
|
+
async codemirror(wikitext) {
|
|
30
|
+
return (await this.queue(wikitext)).map(({ startIndex, endIndex, severity, message }) => ({
|
|
31
|
+
from: startIndex,
|
|
32
|
+
to: endIndex,
|
|
33
|
+
severity,
|
|
34
|
+
message,
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
_Linter_id = new WeakMap(), _Linter_wikitext = new WeakMap(), _Linter_running = new WeakMap(), _Linter_instances = new WeakSet(), _Linter_lint = async function _Linter_lint(wikitext) {
|
|
39
|
+
const { include } = this, errors = await wikiparse.lint(wikitext, include, __classPrivateFieldGet(this, _Linter_id, "f"));
|
|
40
|
+
if (this.include === include && __classPrivateFieldGet(this, _Linter_wikitext, "f") === wikitext) {
|
|
41
|
+
__classPrivateFieldSet(this, _Linter_running, undefined, "f");
|
|
42
|
+
return errors;
|
|
43
|
+
}
|
|
44
|
+
__classPrivateFieldSet(this, _Linter_running, __classPrivateFieldGet(this, _Linter_instances, "m", _Linter_lint).call(this, __classPrivateFieldGet(this, _Linter_wikitext, "f")), "f");
|
|
45
|
+
return __classPrivateFieldGet(this, _Linter_running, "f");
|
|
46
|
+
};
|
|
47
|
+
wikiparse.Linter = Linter;
|
|
48
|
+
})();
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
.wikiparse-container {
|
|
2
|
+
position: relative;
|
|
3
|
+
-webkit-text-size-adjust: none;
|
|
4
|
+
}
|
|
5
|
+
.wikiparsed {
|
|
6
|
+
position: relative;
|
|
7
|
+
display: block;
|
|
8
|
+
box-sizing: border-box;
|
|
9
|
+
width: 100%;
|
|
10
|
+
resize: vertical;
|
|
11
|
+
font-family: monospace;
|
|
12
|
+
background: none !important;
|
|
13
|
+
caret-color: #000;
|
|
14
|
+
}
|
|
15
|
+
#wikiPretty {
|
|
16
|
+
position: absolute;
|
|
17
|
+
inset: 0;
|
|
18
|
+
background-color: #fff;
|
|
19
|
+
-webkit-user-select: none;
|
|
20
|
+
user-select: none;
|
|
21
|
+
}
|
|
22
|
+
#wikiPretty + .wikiparsed, #wikiPretty {
|
|
23
|
+
outline: none;
|
|
24
|
+
border: 1.5px solid #dedede !important;
|
|
25
|
+
border-radius: 0;
|
|
26
|
+
padding: .4em;
|
|
27
|
+
line-height: 1.4 !important;
|
|
28
|
+
font-size: inherit;
|
|
29
|
+
tab-size: 4;
|
|
30
|
+
overflow-y: auto;
|
|
31
|
+
word-break: normal;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/* compromise for font-weight: bold */
|
|
35
|
+
.wpb-ext, .wpb-html,
|
|
36
|
+
.wpb-arg,
|
|
37
|
+
.wpb-template,
|
|
38
|
+
.wpb-magic-word,
|
|
39
|
+
.wpb-heading-title,
|
|
40
|
+
.wpb-table, .wpb-tr, .wpb-td,
|
|
41
|
+
.wpb-double-underscore, .wpb-hr, .wpb-quote, .wpb-list, .wpb-dd
|
|
42
|
+
.wpb-converter {
|
|
43
|
+
-webkit-text-stroke-width: .1ex;
|
|
44
|
+
}
|
|
45
|
+
.wpb-image-invalid, .wpb-table-inter,
|
|
46
|
+
.wpb-hidden, .wpb-noinclude, .wpb-include, .wpb-comment, .wpb-attr-dirty,
|
|
47
|
+
.wpb-ext-attrs, .wpb-html-attrs,
|
|
48
|
+
.wpb-ext-inner,
|
|
49
|
+
.wpb-arg-default,
|
|
50
|
+
.wpb-invoke-module, .wpb-invoke-function,
|
|
51
|
+
.wpb-parameter,
|
|
52
|
+
.wpb-table-attrs, .wpb-td-inner,
|
|
53
|
+
.wpb-converter-rule {
|
|
54
|
+
-webkit-text-stroke-width: 0;
|
|
55
|
+
}
|
|
56
|
+
#wikiPretty span {
|
|
57
|
+
font-weight: normal;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
#wikiPretty.active span {
|
|
61
|
+
color: transparent;
|
|
62
|
+
background: none;
|
|
63
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
.wikiparser {
|
|
2
|
+
white-space: pre-wrap;
|
|
3
|
+
overflow-wrap: break-word;
|
|
4
|
+
font-family: monospace;
|
|
5
|
+
border: 1.5px solid #dedede;
|
|
6
|
+
}
|
|
7
|
+
.wikiparser > ol {
|
|
8
|
+
background-color: #f5f5f5;
|
|
9
|
+
list-style: none;
|
|
10
|
+
}
|
|
11
|
+
.wikiparser > ol > li {
|
|
12
|
+
background-color: #fff;
|
|
13
|
+
padding: 0 6px;
|
|
14
|
+
border-left: 1px solid #ddd;
|
|
15
|
+
counter-increment: wikiparser;
|
|
16
|
+
}
|
|
17
|
+
.wikiparser > ol > li:first-child {
|
|
18
|
+
padding-top: 4px;
|
|
19
|
+
}
|
|
20
|
+
.wikiparser > ol > li:last-child {
|
|
21
|
+
padding-bottom: 4px;
|
|
22
|
+
}
|
|
23
|
+
.wikiparser > ol > li::before {
|
|
24
|
+
content: counter(wikiparser);
|
|
25
|
+
position: absolute;
|
|
26
|
+
transform: translateX(calc(-100% - 10px));
|
|
27
|
+
color: #6c6c6c;
|
|
28
|
+
}
|
|
29
|
+
.wikiparser > ol > li::after {
|
|
30
|
+
content: "";
|
|
31
|
+
display: inline-block;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.wpb-html-invalid, .wpb-image-invalid, .wpb-table-inter {
|
|
35
|
+
color: #f00;
|
|
36
|
+
font-weight: normal;
|
|
37
|
+
text-decoration: underline wavy 1px;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.wpb-hidden, .wpb-noinclude, .wpb-include, .wpb-comment, .wpb-attr-dirty {
|
|
41
|
+
color: #72777d;
|
|
42
|
+
font-weight: normal;
|
|
43
|
+
font-style: italic;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.wpb-ext, .wpb-html {
|
|
47
|
+
color: #14866d;
|
|
48
|
+
font-weight: bold;
|
|
49
|
+
}
|
|
50
|
+
.wpb-ext-attrs, .wpb-html-attrs {
|
|
51
|
+
font-weight: normal;
|
|
52
|
+
}
|
|
53
|
+
.wpb-ext-attr > .wpb-attr-value, .wpb-html-attr > .wpb-attr-value {
|
|
54
|
+
color: #179b1c;
|
|
55
|
+
}
|
|
56
|
+
.wpb-ext-inner {
|
|
57
|
+
color: initial;
|
|
58
|
+
font-weight: normal;
|
|
59
|
+
background-color: rgba(0, 0, 0, .03);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.wpb-arg {
|
|
63
|
+
color: #ac6600;
|
|
64
|
+
font-weight: bold;
|
|
65
|
+
}
|
|
66
|
+
.wpb-arg-default {
|
|
67
|
+
color: #ad9300;
|
|
68
|
+
font-weight: normal;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.wpb-template {
|
|
72
|
+
color: #80c;
|
|
73
|
+
font-weight: bold;
|
|
74
|
+
background-color: rgba(119, 0, 170, .03);
|
|
75
|
+
}
|
|
76
|
+
.wpb-magic-word {
|
|
77
|
+
color: #d33;
|
|
78
|
+
font-weight: bold;
|
|
79
|
+
background-color: rgba(170, 17, 17, .03);
|
|
80
|
+
}
|
|
81
|
+
.wpb-invoke-module, .wpb-invoke-function {
|
|
82
|
+
color: #dd5d33;
|
|
83
|
+
font-weight: normal;
|
|
84
|
+
}
|
|
85
|
+
.wpb-parameter {
|
|
86
|
+
color: initial;
|
|
87
|
+
font-weight: normal;
|
|
88
|
+
}
|
|
89
|
+
.wpb-template > .wpb-parameter > .wpb-parameter-key,
|
|
90
|
+
.wpb-invoke-function ~ .wpb-parameter > .wpb-parameter-key {
|
|
91
|
+
color: #b0c;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.wpb-heading, .wpb-image-parameter {
|
|
95
|
+
color: #0076dd;
|
|
96
|
+
}
|
|
97
|
+
.wpb-heading-title {
|
|
98
|
+
color: initial;
|
|
99
|
+
font-weight: bold;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.wpb-table, .wpb-tr, .wpb-td {
|
|
103
|
+
color: #d08;
|
|
104
|
+
font-weight: bold;
|
|
105
|
+
}
|
|
106
|
+
.wpb-table-attrs {
|
|
107
|
+
font-weight: normal;
|
|
108
|
+
}
|
|
109
|
+
.wpb-table-attr > .wpb-attr-value {
|
|
110
|
+
color: #f500d4;
|
|
111
|
+
}
|
|
112
|
+
.wpb-td-inner {
|
|
113
|
+
color: initial;
|
|
114
|
+
font-weight: normal;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.wpb-double-underscore, .wpb-hr, .wpb-quote, .wpb-list, .wpb-dd {
|
|
118
|
+
color: #0076dd;
|
|
119
|
+
font-weight: bold;
|
|
120
|
+
background-color: #eee;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.wpb-link, .wpb-category, .wpb-file, .wpb-gallery-image, .wpb-imagemap-image,
|
|
124
|
+
.wpb-ext-link, .wpb-free-ext-link {
|
|
125
|
+
color: #000aaa;
|
|
126
|
+
background-color: rgba(34, 17, 153, .03);
|
|
127
|
+
}
|
|
128
|
+
.wpb-link-text, .wpb-image-caption, .wpb-ext-link-text {
|
|
129
|
+
color: initial;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.wpb-converter {
|
|
133
|
+
color: #b68;
|
|
134
|
+
font-weight: bold;
|
|
135
|
+
}
|
|
136
|
+
.wpb-converter-rule {
|
|
137
|
+
font-weight: normal;
|
|
138
|
+
}
|
|
139
|
+
.wpb-converter-rule-from, .wpb-converter-rule-to, .wpb-converter-noconvert {
|
|
140
|
+
color: initial;
|
|
141
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wikiparser-node",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3-b",
|
|
4
4
|
"description": "A Node.js parser for MediaWiki markup with AST",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mediawiki",
|
|
@@ -14,40 +14,52 @@
|
|
|
14
14
|
"license": "GPL-3.0",
|
|
15
15
|
"author": "Bhsd",
|
|
16
16
|
"files": [
|
|
17
|
-
"/
|
|
18
|
-
"/
|
|
17
|
+
"/bundle/bundle.min.js",
|
|
18
|
+
"/extensions/dist/",
|
|
19
|
+
"/extensions/*.css",
|
|
20
|
+
"!/extensions/dist/gh-page.js",
|
|
21
|
+
"!/extensions/gh-page.css",
|
|
19
22
|
"/config/",
|
|
20
23
|
"/i18n/",
|
|
21
|
-
"
|
|
22
|
-
"!/dist/[bt]*/"
|
|
24
|
+
"!/config/.schema.json"
|
|
23
25
|
],
|
|
24
|
-
"
|
|
26
|
+
"browser": "/bundle/bundle.min.js",
|
|
27
|
+
"main": "./bundle/bundle.js",
|
|
28
|
+
"types": "./extensions/typings.d.ts",
|
|
25
29
|
"repository": {
|
|
26
30
|
"type": "git",
|
|
27
31
|
"url": "git+https://github.com/bhsd-harry/wikiparser-node.git"
|
|
28
32
|
},
|
|
29
33
|
"scripts": {
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"build": "
|
|
34
|
+
"prepublishOnly": "npm run build:prod && npm run build:ext",
|
|
35
|
+
"build:dev": "esbuild index.ts --bundle --target=es2018 --outfile=bundle/bundle.js",
|
|
36
|
+
"build:prod": "esbuild index.ts --bundle --minify --target=es2018 --outfile=bundle/bundle.min.js",
|
|
37
|
+
"build:core": "rm bundle/*.js; npm run build:dev && npm run build:prod && eslint --no-eslintrc -c .eslintrc.browser.json bundle/",
|
|
38
|
+
"build:ext": "bash build-ext.sh",
|
|
39
|
+
"build": "npm run build:core && npm run build:ext",
|
|
34
40
|
"diff": "git diff --ignore-all-space --color-moved",
|
|
35
|
-
"
|
|
41
|
+
"diff:stat": "f() { git diff --stat --ignore-all-space --color=always $1 $2 -- . ':!extensions/' ':!bin/' | grep '\\.ts'; }; f",
|
|
42
|
+
"lint:ts": "tsc --noEmit && tsc --noEmit --project extensions/tsconfig.json && eslint --cache .",
|
|
36
43
|
"lint:json": "ajv -s config/.schema.json -d 'config/*.json' --strict=true --strict-required=false",
|
|
37
|
-
"lint": "
|
|
38
|
-
"
|
|
44
|
+
"lint:css": "stylelint extensions/*.css",
|
|
45
|
+
"lint": "npm run lint:ts && npm run lint:json && npm run lint:css",
|
|
46
|
+
"server": "npm run test:end; http-server .. -c-1 --cors &",
|
|
47
|
+
"test": "npm run build:prod && npm run build:ext && npm run server",
|
|
39
48
|
"test:end": "pkill -x http-server",
|
|
40
|
-
"test:real": "node dist/test/real.js"
|
|
41
|
-
"test:single": "node dist/test/single.js && node --prof dist/test/single.js && node --prof-process isolate-0x*-v8.log > test/processed.txt && rm isolate-0x*-v8.log"
|
|
49
|
+
"test:real": "tsc --project tsconfig.dist.json && node dist/test/real.js"
|
|
42
50
|
},
|
|
43
51
|
"devDependencies": {
|
|
52
|
+
"@bhsd/codemirror-mediawiki": "^2.1.11",
|
|
53
|
+
"@codemirror/lint": "^6.4.2",
|
|
44
54
|
"@cypress/request": "^3.0.1",
|
|
45
55
|
"@stylistic/eslint-plugin": "^1.5.4",
|
|
56
|
+
"@stylistic/stylelint-plugin": "^2.0.0",
|
|
46
57
|
"@types/node": "^20.11.6",
|
|
47
58
|
"@types/request": "^2.48.12",
|
|
48
59
|
"@typescript-eslint/eslint-plugin": "^6.19.1",
|
|
49
60
|
"@typescript-eslint/parser": "^6.19.1",
|
|
50
61
|
"ajv-cli": "^5.0.0",
|
|
62
|
+
"esbuild": "^0.19.12",
|
|
51
63
|
"eslint": "^8.56.0",
|
|
52
64
|
"eslint-plugin-es-x": "^7.5.0",
|
|
53
65
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
@@ -57,6 +69,9 @@
|
|
|
57
69
|
"eslint-plugin-promise": "^6.1.1",
|
|
58
70
|
"eslint-plugin-regexp": "^2.2.0",
|
|
59
71
|
"eslint-plugin-unicorn": "^50.0.1",
|
|
72
|
+
"http-server": "^14.1.0",
|
|
73
|
+
"stylelint": "^16.1.0",
|
|
74
|
+
"stylelint-config-recommended": "^14.0.0",
|
|
60
75
|
"typescript": "^5.3.3"
|
|
61
76
|
},
|
|
62
77
|
"engines": {
|