wikiparser-node 0.11.0-b → 0.11.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.
Files changed (176) hide show
  1. package/config/.schema.json +18 -0
  2. package/config/default.json +1 -0
  3. package/config/llwiki.json +35 -0
  4. package/config/moegirl.json +44 -0
  5. package/config/zhwiki.json +466 -0
  6. package/dist/index.d.ts +114 -0
  7. package/dist/lib/element.d.ts +162 -0
  8. package/dist/lib/node.d.ts +291 -0
  9. package/dist/lib/ranges.d.ts +37 -0
  10. package/dist/lib/text.d.ts +64 -0
  11. package/dist/lib/title.d.ts +21 -0
  12. package/dist/mixin/attributeParent.d.ts +9 -0
  13. package/dist/mixin/fixedToken.d.ts +8 -0
  14. package/dist/mixin/hidden.d.ts +8 -0
  15. package/dist/mixin/singleLine.d.ts +8 -0
  16. package/dist/mixin/sol.d.ts +8 -0
  17. package/dist/parser/brackets.d.ts +12 -0
  18. package/dist/parser/commentAndExt.d.ts +8 -0
  19. package/dist/parser/converter.d.ts +7 -0
  20. package/dist/parser/externalLinks.d.ts +7 -0
  21. package/dist/parser/hrAndDoubleUnderscore.d.ts +11 -0
  22. package/dist/parser/html.d.ts +7 -0
  23. package/dist/parser/links.d.ts +7 -0
  24. package/dist/parser/list.d.ts +7 -0
  25. package/dist/parser/magicLinks.d.ts +7 -0
  26. package/dist/parser/quotes.d.ts +7 -0
  27. package/dist/parser/selector.d.ts +12 -0
  28. package/dist/parser/table.d.ts +11 -0
  29. package/dist/src/arg.d.ts +54 -0
  30. package/dist/src/atom/hidden.d.ts +5 -0
  31. package/dist/src/atom/index.d.ts +15 -0
  32. package/dist/src/attribute.d.ts +65 -0
  33. package/dist/src/attributes.d.ts +112 -0
  34. package/dist/src/charinsert.d.ts +32 -0
  35. package/dist/src/converter.d.ts +103 -0
  36. package/dist/src/converterFlags.d.ts +83 -0
  37. package/dist/src/converterRule.d.ts +75 -0
  38. package/dist/src/extLink.d.ts +62 -0
  39. package/dist/src/gallery.d.ts +33 -0
  40. package/dist/src/hasNowiki/index.d.ts +14 -0
  41. package/dist/src/hasNowiki/pre.d.ts +13 -0
  42. package/dist/src/heading.d.ts +44 -0
  43. package/dist/src/html.d.ts +56 -0
  44. package/dist/src/imageParameter.d.ts +65 -0
  45. package/dist/src/imagemap.d.ts +37 -0
  46. package/dist/src/imagemapLink.d.ts +21 -0
  47. package/dist/src/index.d.ts +186 -0
  48. package/dist/src/link/category.d.ts +16 -0
  49. package/dist/src/link/file.d.ts +85 -0
  50. package/dist/src/link/galleryImage.d.ts +15 -0
  51. package/dist/src/link/index.d.ts +88 -0
  52. package/dist/src/magicLink.d.ts +36 -0
  53. package/dist/src/nested/choose.d.ts +13 -0
  54. package/dist/src/nested/combobox.d.ts +13 -0
  55. package/dist/src/nested/index.d.ts +18 -0
  56. package/dist/src/nested/references.d.ts +13 -0
  57. package/dist/src/nowiki/comment.d.ts +31 -0
  58. package/dist/src/nowiki/dd.d.ts +17 -0
  59. package/dist/src/nowiki/doubleUnderscore.d.ts +22 -0
  60. package/dist/src/nowiki/hr.d.ts +13 -0
  61. package/dist/src/nowiki/index.d.ts +27 -0
  62. package/dist/src/nowiki/list.d.ts +8 -0
  63. package/dist/src/nowiki/noinclude.d.ts +8 -0
  64. package/dist/src/nowiki/quote.d.ts +13 -0
  65. package/dist/src/onlyinclude.d.ts +24 -0
  66. package/dist/src/paramTag/index.d.ts +29 -0
  67. package/dist/src/paramTag/inputbox.d.ts +8 -0
  68. package/dist/src/parameter.d.ts +75 -0
  69. package/dist/src/syntax.d.ts +20 -0
  70. package/dist/src/table/index.d.ts +273 -0
  71. package/dist/src/table/td.d.ts +100 -0
  72. package/dist/src/table/tr.d.ts +91 -0
  73. package/dist/src/tagPair/ext.d.ts +18 -0
  74. package/dist/src/tagPair/include.d.ts +25 -0
  75. package/dist/src/tagPair/index.d.ts +41 -0
  76. package/dist/src/transclude.d.ts +199 -0
  77. package/dist/tool/index.d.ts +420 -0
  78. package/dist/util/base.d.ts +10 -0
  79. package/dist/util/debug.d.ts +20 -0
  80. package/dist/util/diff.d.ts +8 -0
  81. package/dist/util/lint.d.ts +28 -0
  82. package/dist/util/string.d.ts +55 -0
  83. package/index.js +333 -0
  84. package/lib/element.js +618 -0
  85. package/lib/node.js +730 -0
  86. package/lib/ranges.js +130 -0
  87. package/lib/text.js +265 -0
  88. package/lib/title.js +83 -0
  89. package/mixin/attributeParent.js +117 -0
  90. package/mixin/fixedToken.js +40 -0
  91. package/mixin/hidden.js +21 -0
  92. package/mixin/singleLine.js +31 -0
  93. package/mixin/sol.js +54 -0
  94. package/package.json +17 -13
  95. package/parser/brackets.js +128 -0
  96. package/parser/commentAndExt.js +62 -0
  97. package/parser/converter.js +46 -0
  98. package/parser/externalLinks.js +33 -0
  99. package/parser/hrAndDoubleUnderscore.js +49 -0
  100. package/parser/html.js +42 -0
  101. package/parser/links.js +94 -0
  102. package/parser/list.js +59 -0
  103. package/parser/magicLinks.js +41 -0
  104. package/parser/quotes.js +64 -0
  105. package/parser/selector.js +180 -0
  106. package/parser/table.js +114 -0
  107. package/src/arg.js +207 -0
  108. package/src/atom/hidden.js +13 -0
  109. package/src/atom/index.js +43 -0
  110. package/src/attribute.js +472 -0
  111. package/src/attributes.js +453 -0
  112. package/src/charinsert.js +97 -0
  113. package/src/converter.js +176 -0
  114. package/src/converterFlags.js +284 -0
  115. package/src/converterRule.js +256 -0
  116. package/src/extLink.js +180 -0
  117. package/src/gallery.js +149 -0
  118. package/src/hasNowiki/index.js +44 -0
  119. package/src/hasNowiki/pre.js +40 -0
  120. package/src/heading.js +134 -0
  121. package/src/html.js +254 -0
  122. package/src/imageParameter.js +303 -0
  123. package/src/imagemap.js +199 -0
  124. package/src/imagemapLink.js +41 -0
  125. package/src/index.js +938 -0
  126. package/src/link/category.js +44 -0
  127. package/src/link/file.js +287 -0
  128. package/src/link/galleryImage.js +120 -0
  129. package/src/link/index.js +388 -0
  130. package/src/magicLink.js +151 -0
  131. package/src/nested/choose.js +24 -0
  132. package/src/nested/combobox.js +23 -0
  133. package/src/nested/index.js +96 -0
  134. package/src/nested/references.js +23 -0
  135. package/src/nowiki/comment.js +71 -0
  136. package/src/nowiki/dd.js +59 -0
  137. package/src/nowiki/doubleUnderscore.js +56 -0
  138. package/src/nowiki/hr.js +41 -0
  139. package/src/nowiki/index.js +56 -0
  140. package/src/nowiki/list.js +16 -0
  141. package/src/nowiki/noinclude.js +28 -0
  142. package/src/nowiki/quote.js +69 -0
  143. package/src/onlyinclude.js +64 -0
  144. package/src/paramTag/index.js +89 -0
  145. package/src/paramTag/inputbox.js +35 -0
  146. package/src/parameter.js +239 -0
  147. package/src/syntax.js +91 -0
  148. package/src/table/index.js +985 -0
  149. package/src/table/td.js +343 -0
  150. package/src/table/tr.js +319 -0
  151. package/src/tagPair/ext.js +146 -0
  152. package/src/tagPair/include.js +50 -0
  153. package/src/tagPair/index.js +131 -0
  154. package/src/transclude.js +843 -0
  155. package/tool/index.js +1209 -0
  156. package/typings/api.d.ts +9 -0
  157. package/typings/array.d.ts +29 -0
  158. package/typings/event.d.ts +22 -0
  159. package/typings/index.d.ts +118 -0
  160. package/typings/node.d.ts +35 -0
  161. package/typings/parser.d.ts +12 -0
  162. package/typings/table.d.ts +10 -0
  163. package/typings/token.d.ts +31 -0
  164. package/typings/tool.d.ts +6 -0
  165. package/util/base.js +17 -0
  166. package/util/debug.js +73 -0
  167. package/util/diff.js +76 -0
  168. package/util/lint.js +57 -0
  169. package/util/string.js +126 -0
  170. package/bundle/bundle.min.js +0 -38
  171. package/config/minimum.json +0 -135
  172. package/extensions/base.js +0 -154
  173. package/extensions/editor.css +0 -63
  174. package/extensions/editor.js +0 -183
  175. package/extensions/highlight.js +0 -40
  176. package/extensions/ui.css +0 -119
@@ -1,183 +0,0 @@
1
- 'use strict';
2
-
3
- (() => {
4
- const /** @type {{wikiparse: import('../typings/extension')}} */ {wikiparse} = window,
5
- {MAX_STAGE, print} = wikiparse;
6
-
7
- /** 用于打印AST */
8
- class Printer {
9
- /**
10
- * @param {HTMLDivElement} preview 置于下层的代码高亮
11
- * @param {HTMLTextAreaElement} textbox 置于上层的文本框
12
- * @param {boolean} include 是否嵌入
13
- */
14
- constructor(preview, textbox, include) {
15
- this.id = wikiparse.id++;
16
- this.preview = preview;
17
- this.textbox = textbox;
18
- this.include = Boolean(include);
19
- /** @type {[number, string, string][]} */ this.root = [];
20
- /** @type {Promise<void>} */ this.running = undefined;
21
- this.viewportChanged = false;
22
- /** @type {[number, string]} */ this.ticks = [0, undefined];
23
- }
24
-
25
- /** 倒计时 */
26
- tick() {
27
- setTimeout(() => {
28
- const {ticks} = this;
29
- if (ticks[0] > 0) {
30
- ticks[0] -= 500;
31
- this[ticks[0] <= 0 ? ticks[1] : 'tick']();
32
- }
33
- }, 500);
34
- }
35
-
36
- /**
37
- * 用于debounce
38
- * @param {number} delay 延迟
39
- * @param {string} method 方法
40
- */
41
- queue(delay, method) {
42
- const {ticks} = this,
43
- [state] = ticks;
44
- if (state <= 0 || method === 'coarsePrint' || ticks[1] !== 'coarsePrint') {
45
- ticks[0] = delay;
46
- ticks[1] = method;
47
- if (state <= 0) {
48
- this.tick();
49
- }
50
- }
51
- }
52
-
53
- /** 渲染 */
54
- paint() {
55
- this.preview.innerHTML = `<span class="wpb-root">${
56
- this.root.map(([,, printed]) => printed).join('')
57
- }</span> `;
58
- this.preview.scrollTop = this.textbox.scrollTop;
59
- this.preview.classList.remove('active');
60
- this.textbox.style.color = 'transparent';
61
- }
62
-
63
- /** 初步解析 */
64
- async coarsePrint() {
65
- if (this.running) {
66
- return undefined;
67
- }
68
- const {include, textbox: {value}} = this,
69
- parsed = await print(value, include, 2, this.id);
70
- if (this.include !== include || this.textbox.value !== value) {
71
- this.running = undefined;
72
- this.running = this.coarsePrint();
73
- return this.running;
74
- }
75
- this.root = parsed;
76
- this.paint();
77
- this.running = undefined;
78
- this.running = this.finePrint();
79
- return this.running;
80
- }
81
-
82
- /** 根据可见范围精细解析 */
83
- async finePrint() {
84
- if (this.running) {
85
- this.viewportChanged = true;
86
- return undefined;
87
- }
88
- this.viewportChanged = false;
89
- const {
90
- root,
91
- preview: {scrollHeight, offsetHeight: parentHeight, scrollTop, children: [rootNode]},
92
- include,
93
- textbox: {value},
94
- } = this;
95
- let text = value,
96
- start = 0,
97
- {length: end} = root;
98
- if (scrollHeight > parentHeight) {
99
- const /** @type {HTMLElement[]} */ childNodes = [...rootNode.childNodes],
100
- headings = childNodes.filter(({className}) => className === 'wpb-heading'),
101
- {length} = headings;
102
- if (length > 0) {
103
- let i = headings.findIndex(({offsetTop, offsetHeight}) => offsetTop + offsetHeight > scrollTop);
104
- i = i === -1 ? length : i;
105
- let j = headings.slice(i).findIndex(({offsetTop}) => offsetTop >= scrollTop + parentHeight);
106
- j = j === -1 ? length : i + j;
107
- start = i ? childNodes.indexOf(headings[i - 1]) : 0;
108
- while (i <= j && root[start][0] === MAX_STAGE) {
109
- start = childNodes.indexOf(headings[i++]);
110
- }
111
- end = j === length ? end : childNodes.indexOf(headings[j]);
112
- while (i <= j && root[end - 1][0] === MAX_STAGE) {
113
- end = childNodes.indexOf(headings[--j]);
114
- }
115
- text = root.slice(start, end).map(([, str]) => str).join('');
116
- }
117
- }
118
- if (start === end) {
119
- this.running = undefined;
120
- return undefined;
121
- }
122
- const parsed = await print(text, include, MAX_STAGE, this.id);
123
- if (this.include === include && this.textbox.value === value) {
124
- this.root.splice(start, end - start, ...parsed);
125
- this.paint();
126
- this.running = undefined;
127
- if (this.viewportChanged) {
128
- this.running = this.finePrint();
129
- }
130
- } else {
131
- this.running = undefined;
132
- this.running = this.coarsePrint();
133
- }
134
- return this.running;
135
- }
136
- }
137
-
138
- /**
139
- * 高亮textarea
140
- * @param {HTMLTextAreaElement} textbox textarea元素
141
- * @param {boolean} include 是否嵌入
142
- * @throws `TypeError` 不是textarea
143
- */
144
- const edit = (textbox, include) => {
145
- if (!(textbox instanceof HTMLTextAreaElement)) {
146
- throw new TypeError('wikiparse.edit方法仅可用于textarea元素!');
147
- }
148
- const preview = document.createElement('div'),
149
- container = document.createElement('div'),
150
- printer = new Printer(preview, textbox, include);
151
- preview.id = 'wikiPretty';
152
- preview.classList.add('wikiparser', 'active');
153
- container.classList.add('wikiparse-container');
154
- textbox.replaceWith(container);
155
- textbox.classList.add('wikiparsed');
156
- container.append(preview, textbox);
157
-
158
- textbox.addEventListener('input', ({isComposing}) => {
159
- if (!isComposing) {
160
- printer.queue(2000, 'coarsePrint');
161
- }
162
- textbox.style.color = '';
163
- preview.classList.add('active');
164
- });
165
- textbox.addEventListener('scroll', () => {
166
- if (preview.scrollHeight > preview.offsetHeight && !preview.classList.contains('active')) {
167
- preview.scrollTop = textbox.scrollTop;
168
- printer.queue(500, 'finePrint');
169
- }
170
- });
171
- textbox.addEventListener('keydown', e => {
172
- if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
173
- e.preventDefault();
174
- printer.ticks[0] = 0;
175
- printer.running = printer.coarsePrint();
176
- }
177
- });
178
- printer.running = printer.coarsePrint();
179
- return printer;
180
- };
181
-
182
- Object.assign(wikiparse, {edit, Printer});
183
- })();
@@ -1,40 +0,0 @@
1
- 'use strict';
2
-
3
- (() => {
4
- const /** @type {{wikiparse: import('../typings/extension')}} */ {wikiparse} = window;
5
-
6
- /**
7
- * 高亮代码块
8
- * @param {HTMLElement} ele 代码块
9
- * @param {boolean} linenums 是否添加行号
10
- * @param {number} start 起始行号
11
- */
12
- const highlight = async (ele, linenums, start = 1) => {
13
- if (ele.classList.contains('highlighted')) {
14
- return;
15
- }
16
- const html = (await wikiparse.print(ele.innerText)).map(([,, printed]) => printed).join('');
17
- ele.classList.add('highlighted');
18
- if (linenums) {
19
- // 添加行号。这里不使用<table>排版,而是使用<ol>
20
- const lines = html.split('\n').map((line, i) => {
21
- const li = document.createElement('li');
22
- li.id = `L${i + start}`;
23
- li.innerHTML = line;
24
- return li;
25
- });
26
- if (!lines[lines.length - 1].textContent) {
27
- lines.pop();
28
- }
29
- const ol = document.createElement('ol');
30
- ol.start = start;
31
- ol.style.paddingLeft = `${(lines.length + start - 1).toString().length + 2.5}ch`;
32
- ol.append(...lines);
33
- ele.replaceChildren(ol);
34
- } else {
35
- ele.innerHTML = html;
36
- }
37
- };
38
-
39
- wikiparse.highlight = highlight;
40
- })();
package/extensions/ui.css DELETED
@@ -1,119 +0,0 @@
1
- .wikiparser {
2
- white-space: pre-wrap;
3
- overflow-wrap: break-word;
4
- font-family: monospace;
5
- }
6
-
7
- .wpb-error {
8
- text-decoration: underline wavy #f00 1px;
9
- }
10
- .wpb-hidden, .wpb-table-inter, .wpb-table-inter span {
11
- color: #f00;
12
- font-weight: normal;
13
- text-decoration: underline wavy 1px;
14
- }
15
-
16
- .wpb-noinclude, .wpb-include, .wpb-comment {
17
- color: #72777d;
18
- font-weight: normal;
19
- }
20
- .wpb-comment {
21
- font-style: italic;
22
- }
23
-
24
- .wpb-ext, .wpb-html {
25
- color: #14866d;
26
- font-weight: bold;
27
- }
28
- .wpb-ext-attrs, .wpb-html-attrs {
29
- font-weight: normal;
30
- }
31
- .wpb-ext-attr > .wpb-attr-value, .wpb-html-attr > .wpb-attr-value {
32
- color: #179b1c;
33
- }
34
- .wpb-ext-inner {
35
- color: initial;
36
- font-weight: normal;
37
- background-color: rgba(0, 0, 0, .03);
38
- }
39
-
40
- .wpb-arg {
41
- color: #ac6600;
42
- font-weight: bold;
43
- }
44
- .wpb-arg-default {
45
- color: #ad9300;
46
- font-weight: normal;
47
- }
48
-
49
- .wpb-template {
50
- color: #80c;
51
- font-weight: bold;
52
- background-color: rgba(119, 0, 170, .03);
53
- }
54
- .wpb-magic-word {
55
- color: #d33;
56
- font-weight: bold;
57
- background-color: rgba(170, 17, 17, .03);
58
- }
59
- .wpb-invoke-module, .wpb-invoke-function {
60
- color: #dd5d33;
61
- font-weight: normal;
62
- }
63
- .wpb-parameter {
64
- color: initial;
65
- font-weight: normal;
66
- }
67
- .wpb-template > .wpb-parameter > .wpb-parameter-key,
68
- .wpb-invoke-function ~ .wpb-parameter > .wpb-parameter-key {
69
- color: #b0c;
70
- }
71
-
72
- .wpb-heading, .wpb-image-parameter {
73
- color: #0076dd;
74
- }
75
- .wpb-heading-title {
76
- color: initial;
77
- font-weight: bold;
78
- }
79
-
80
- .wpb-table, .wpb-tr, .wpb-td {
81
- color: #d08;
82
- font-weight: bold;
83
- }
84
- .wpb-table-attrs {
85
- font-weight: normal;
86
- }
87
- .wpb-table-attr > .wpb-attr-value {
88
- color: #f500d4;
89
- }
90
- .wpb-td-inner {
91
- color: initial;
92
- font-weight: normal;
93
- }
94
-
95
- .wpb-double-underscore, .wpb-hr, .wpb-quote, .wpb-list, .wpb-dd {
96
- color: #0076dd;
97
- font-weight: bold;
98
- background-color: #eee;
99
- }
100
-
101
- .wpb-link, .wpb-category, .wpb-file, .wpb-gallery-image, .wpb-imagemap-image,
102
- .wpb-ext-link, .wpb-free-ext-link {
103
- color: #000aaa;
104
- background-color: rgba(34, 17, 153, .03);
105
- }
106
- .wpb-link-text, .wpb-image-caption, .wpb-ext-link-text {
107
- color: initial;
108
- }
109
-
110
- .wpb-converter {
111
- color: #b68;
112
- font-weight: bold;
113
- }
114
- .wpb-converter-rule {
115
- font-weight: normal;
116
- }
117
- .wpb-converter-rule-from, .wpb-converter-rule-to, .wpb-converter-noconvert {
118
- color: initial;
119
- }