@bhsd/codemirror-mediawiki 3.5.1 → 3.6.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/dist/token.js CHANGED
@@ -170,6 +170,7 @@ const lookahead = (chars, comment) => {
170
170
  '<': comment ? '<(?!!--)' : '<(?!!--|/?[a-z])',
171
171
  '~': '~~?(?!~)',
172
172
  _: '_(?!_)',
173
+ '_': '_(?!_)',
173
174
  '[': String.raw `\[(?!\[)`,
174
175
  ']': String.raw `\](?!\])`,
175
176
  '/': '/(?!>)',
@@ -329,7 +330,7 @@ const syntaxHighlight = new Set(['syntaxhighlight', 'source', 'pre']), pageFunct
329
330
  'canonicalurle',
330
331
  'int',
331
332
  'msgnw',
332
- ]), substs = new Set(['subst', 'safesubst']), headerRegex = new RegExp(`^(?:[^&[<{~'-]|${lookahead("<{~'-")})+`, 'iu'), templateRegex = new RegExp(`^(?:[^|{}<]|${lookahead('{}<', true)})+`, 'u'), argumentRegex = new RegExp(`^(?:[^|[&:}{<~'_-]|${lookahead("}{<~'_-")})+`, 'iu'), styleRegex = new RegExp(`^(?:[^|[&}{<~'_-]|${lookahead("}{<~'_-")})+`, 'iu'), wikiRegex = new RegExp(`^(?:[^&'{[<~_:-]|${lookahead("'{[<~_-")})+`, 'iu'), tableDefinitionRegex = new RegExp(`^(?:[^&={<]|${lookahead('{<')})+`, 'iu'), tableCellRegex = /^\s*(?:[|!]|\{\{\s*![!)+-]?\s*\}\})/u, extLinkChars = "[{'<-", tableDefinitionChars = '{<', tableCellChars = "'<~_{-", htmlAttrChars = '{/', freeRegex = [false, true].map(lpar => {
333
+ ]), substs = new Set(['subst', 'safesubst']), headerRegex = new RegExp(`^(?:[^&[<{~'-]|${lookahead("<{~'-")})+`, 'iu'), templateRegex = new RegExp(`^(?:[^|{}<]|${lookahead('{}<', true)})+`, 'u'), argumentRegex = new RegExp(`^(?:[^|[&:}{<~'__-]|${lookahead("}{<~'__-")})+`, 'iu'), styleRegex = new RegExp(`^(?:[^|[&}{<~'__-]|${lookahead("}{<~'__-")})+`, 'iu'), wikiRegex = new RegExp(`^(?:[^&'{[<~__:-]|${lookahead("'{[<~__-")})+`, 'iu'), tableDefinitionRegex = new RegExp(`^(?:[^&={<]|${lookahead('{<')})+`, 'iu'), tableCellRegex = /^\s*(?:[|!]|\{\{\s*![!)+-]?\s*\}\})/u, extLinkChars = "[{'<-", tableDefinitionChars = '{<', tableCellChars = "'<~__{-", htmlAttrChars = '{/', freeRegex = [false, true].map(lpar => {
333
334
  const punctuations = getPunctuations(lpar), source = getUrlRegex(punctuations);
334
335
  return new RegExp(`^(?:${source}|[${punctuations}]+(?=${source}))*`, 'u');
335
336
  }), indentedTableRegex = [false, true].map(isTemplate => new RegExp(String.raw `^:*\s*(?=\{${getPipe(isTemplate)})`, 'u')), tableRegex = [false, true]
@@ -340,7 +341,10 @@ const syntaxHighlight = new Set(['syntaxhighlight', 'source', 'pre']), pageFunct
340
341
  new RegExp(String.raw `^(?:[<>{}]|%(?:3[ce]|[57][bd])|${lookahead('[]')})+`, 'iu'),
341
342
  new RegExp(String.raw `^(?:\}|${lookahead('[]{')})+`, 'u'),
342
343
  new RegExp(String.raw `^(?:[>}]|%(?:3[ce]|[57][bd])|${lookahead('[]{<')})+`, 'iu'),
343
- ], tableDefinitionValueRegex = ['', '='].map(equal => new RegExp(String.raw `^(?:[^\s&${tableDefinitionChars}${equal}]|${lookahead(tableDefinitionChars)})+`, 'iu')), variableRegex = [false, true].map(isDefault => new RegExp(String.raw `^(?:[^|{}<${isDefault ? "[&~'_:-" : ''}]|\}(?!\}\})|${isDefault ? lookahead("{<~'_-") : lookahead('{<', true)})+`, 'iu')), parserFunctionRegex = ['', '[&', '[&:'].map(s => getRegex(chars => new RegExp(`^(?:[^|${s}${chars}]|${lookahead(chars)})+`, 'iu'))), getExtLinkTextRegex = getRegex(pipe => new RegExp(String.raw `^(?:[^\]&${pipe}${extLinkChars}]|${lookahead(extLinkChars)})+`, 'iu')), getExtLinkRegex = getRegex(pipe => new RegExp(`^(?:${getUrlRegex(pipe)})+`, 'u')), getTableDefinitionRegex = getRegex(s => new RegExp(`^(?:[^&${tableDefinitionChars}${s}]|${lookahead(tableDefinitionChars)})+`, 'iu')), getTableCellRegex = getRegex(s => new RegExp(`^(?:[^[&${s}${tableCellChars}]|${lookahead(tableCellChars)})+`, 'iu')), getHtmlAttrRegex = getRegex(s => new RegExp(`^(?:[^<>&${htmlAttrChars}${s}]|${lookahead(htmlAttrChars)})+`, 'u')), getHtmlAttrKeyRegex = getRegex(pipe => new RegExp(`^(?:[^<>&={/${pipe}]|${lookahead('{/')})+`, 'u')), getExtAttrRegex = getRegex(s => new RegExp(`^(?:[^>/${s}]|${lookahead('/')})+`, 'u')), getExtTagCloseRegex = getRegex(name => name === 'onlyinclude'
344
+ ], tableDefinitionValueRegex = ['', '='].map(equal => new RegExp(String.raw `^(?:[^\s&${tableDefinitionChars}${equal}]|${lookahead(tableDefinitionChars)})+`, 'iu')), variableRegex = [false, true].map(isDefault => new RegExp(String.raw `^(?:[^|{}<${isDefault ? "[&~'__:-" : ''}]|\}(?!\}\})|${isDefault ? lookahead("{<~'__-") : lookahead('{<', true)})+`, 'iu')), parserFunctionRegex = ['', '[&', '[&:'].map(s => getRegex(chars => new RegExp(`^(?:[^|${s}${chars}]|${lookahead(chars)})+`, 'iu'))), doubleUnderscoreRegex = {
345
+ _: /^[\p{L}\p{N}_]+?__/u,
346
+ '_': /^[\p{L}\p{N}__]+?_{2}/u,
347
+ }, getExtLinkTextRegex = getRegex(pipe => new RegExp(String.raw `^(?:[^\]&${pipe}${extLinkChars}]|${lookahead(extLinkChars)})+`, 'iu')), getExtLinkRegex = getRegex(pipe => new RegExp(`^(?:${getUrlRegex(pipe)})+`, 'u')), getTableDefinitionRegex = getRegex(s => new RegExp(`^(?:[^&${tableDefinitionChars}${s}]|${lookahead(tableDefinitionChars)})+`, 'iu')), getTableCellRegex = getRegex(s => new RegExp(`^(?:[^[&${s}${tableCellChars}]|${lookahead(tableCellChars)})+`, 'iu')), getHtmlAttrRegex = getRegex(s => new RegExp(`^(?:[^<>&${htmlAttrChars}${s}]|${lookahead(htmlAttrChars)})+`, 'u')), getHtmlAttrKeyRegex = getRegex(pipe => new RegExp(`^(?:[^<>&={/${pipe}]|${lookahead('{/')})+`, 'u')), getExtAttrRegex = getRegex(s => new RegExp(`^(?:[^>/${s}]|${lookahead('/')})+`, 'u')), getExtTagCloseRegex = getRegex(name => name === 'onlyinclude'
344
348
  ? /<\/onlyinclude(?:>|$)/u
345
349
  : new RegExp(String.raw `</${name}\s*(?:>|$)`, 'iu')), getNestedRegex = getRegex(tag => new RegExp(String.raw `^(?:[^<]|<(?!${tag}(?:[\s/>]|$)))+`, 'iu'));
346
350
  /** Adapted from the original CodeMirror 5 stream parser by Pavel Astakhov */
@@ -469,7 +473,7 @@ let MediaWiki = (() => {
469
473
  this.imgRegex = new RegExp(String.raw `^(?:${this.img.filter(word => word.endsWith('$1')).map(word => word.slice(0, -2))
470
474
  .join('|')}|(?:${this.img.filter(word => !word.endsWith('$1')).join('|')}|(?:\d+x?|\d*x\d+)\s*(?:px)?px)\s*(?=\||\]\]|$))`, 'u');
471
475
  this.tags = [...Object.keys(tags), 'includeonly', 'noinclude', 'onlyinclude'];
472
- this.convertRegex = new RegExp(String.raw `^(?:[^}|;&='{[<~_-]|\}(?!-)|=(?!>)|\[(?!\[|${urlProtocols})|${lookahead("'{<~_-")})+`, 'iu');
476
+ this.convertRegex = new RegExp(String.raw `^(?:[^}|;&='{[<~__-]|\}(?!-)|=(?!>)|\[(?!\[|${urlProtocols})|${lookahead("'{<~__-")})+`, 'iu');
473
477
  this.convertSemicolon = variants && new RegExp(String.raw `^;\s*(?=(?:[^;]*?=>\s*)?(?:${variants.join('|')})\s*:|(?:$|\}-))`, 'iu');
474
478
  this.convertLang = variants
475
479
  && new RegExp(String.raw `^(?:=>\s*)?(?:${variants.join('|')})\s*:`, 'iu');
@@ -706,14 +710,15 @@ let MediaWiki = (() => {
706
710
  }
707
711
  break;
708
712
  }
709
- case '_': {
713
+ case '_':
714
+ case '_': {
710
715
  const { pos } = stream;
711
- stream.eatWhile('_');
716
+ stream.eatWhile(ch);
712
717
  switch (stream.pos - pos) {
713
718
  case 0:
714
719
  break;
715
720
  case 1:
716
- return this.eatDoubleUnderscore(style, stream, state);
721
+ return this.eatDoubleUnderscore(style, ch, stream, state);
717
722
  default:
718
723
  if (!stream.eol()) {
719
724
  stream.backUp(2);
@@ -768,13 +773,13 @@ let MediaWiki = (() => {
768
773
  // no default
769
774
  }
770
775
  if (state.stack.length === 0) {
771
- if (ch !== '_') {
776
+ if (ch !== '_' && ch !== '_') {
772
777
  // highlight free external links, bug T108448
773
778
  if (/[\p{L}\p{N}]/u.test(ch)) {
774
779
  stream.backUp(1);
775
780
  }
776
781
  else {
777
- stream.eatWhile(/[^\p{L}\p{N}_&'{[<~:-]/u);
782
+ stream.eatWhile(/[^\p{L}\p{N}__&'{[<~:-]/u);
778
783
  }
779
784
  const mt = stream.match(this.urlProtocols, false);
780
785
  if (mt) {
@@ -978,11 +983,11 @@ let MediaWiki = (() => {
978
983
  }
979
984
  return makeLocalTagStyle('list', state);
980
985
  }
981
- eatDoubleUnderscore(style, stream, state) {
982
- const { config: { doubleUnderscore } } = this, name = stream.match(/^[\p{L}\p{N}_]+?__/u);
986
+ eatDoubleUnderscore(style, ch, stream, state) {
987
+ const { config: { doubleUnderscore } } = this, underscore = ch.repeat(2), name = stream.match(doubleUnderscoreRegex[ch]);
983
988
  if (name) {
984
- if (Object.prototype.hasOwnProperty.call(doubleUnderscore[0], `__${name[0].toLowerCase()}`)
985
- || Object.prototype.hasOwnProperty.call(doubleUnderscore[1], `__${name[0]}`)) {
989
+ if (Object.prototype.hasOwnProperty.call(doubleUnderscore[0], underscore + name[0].toLowerCase())
990
+ || Object.prototype.hasOwnProperty.call(doubleUnderscore[1], underscore + name[0])) {
986
991
  return tokens.doubleUnderscore;
987
992
  }
988
993
  else if (!stream.eol()) {
@@ -1583,7 +1588,7 @@ let MediaWiki = (() => {
1583
1588
  if (n === 0) {
1584
1589
  return this.inTemplateArgument(true, true);
1585
1590
  }
1586
- const chars = n === 2 ? '}{<' : "}{<~'_-"; // `#invoke`/`#tag`
1591
+ const chars = n === 2 ? '}{<' : "}{<~'__-"; // `#invoke`/`#tag`
1587
1592
  let style = `${tokens.parserFunction} ${module ? tokens.pageName : ''}`;
1588
1593
  switch (module) {
1589
1594
  case 1:
package/dist/util.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ import type { EditorView, TooltipView } from '@codemirror/view';
2
+ import type { Text, EditorState } from '@codemirror/state';
3
+ import type { SyntaxNode } from '@lezer/common';
4
+ import type { Position } from 'vscode-languageserver-types';
5
+ /**
6
+ * 转义HTML字符串
7
+ * @param text 原字符串
8
+ */
9
+ export declare const escHTML: (text: string) => string;
10
+ /**
11
+ * 将索引转换为位置
12
+ * @param doc Text 实例
13
+ * @param index 索引
14
+ */
15
+ export declare const indexToPos: (doc: Text, index: number) => Position;
16
+ /**
17
+ * 将位置转换为索引
18
+ * @param doc Text 实例
19
+ * @param pos 位置
20
+ */
21
+ export declare const posToIndex: (doc: Text, pos: Position) => number;
22
+ /**
23
+ * 创建 TooltipView
24
+ * @param view EditorView 实例
25
+ * @param innerHTML 提示内容
26
+ */
27
+ export declare const createTooltipView: (view: EditorView, innerHTML: string) => TooltipView;
28
+ /**
29
+ * Update the stack of opening (+) or closing (-) brackets
30
+ * @param state
31
+ * @param node 语法树节点
32
+ */
33
+ export declare const braceStackUpdate: (state: EditorState, node: SyntaxNode) => [number, number];
34
+ /**
35
+ * 判断节点是否包含指定类型
36
+ * @param types 节点类型
37
+ * @param names 指定类型
38
+ */
39
+ export declare const hasTag: (types: Set<string>, names: string | string[]) => boolean;
package/dist/util.js ADDED
@@ -0,0 +1,53 @@
1
+ import elt from 'crelt';
2
+ import { tokens } from './config';
3
+ import { hoverSelector } from './constants';
4
+ const dict = { '\n': '<br>', '&': '&amp;', '<': '&lt;' };
5
+ /**
6
+ * 转义HTML字符串
7
+ * @param text 原字符串
8
+ */
9
+ export const escHTML = (text) => text.replace(/[\n<&]/gu, ch => dict[ch]);
10
+ /**
11
+ * 将索引转换为位置
12
+ * @param doc Text 实例
13
+ * @param index 索引
14
+ */
15
+ export const indexToPos = (doc, index) => {
16
+ const line = doc.lineAt(index);
17
+ return { line: line.number - 1, character: index - line.from };
18
+ };
19
+ /**
20
+ * 将位置转换为索引
21
+ * @param doc Text 实例
22
+ * @param pos 位置
23
+ */
24
+ export const posToIndex = (doc, pos) => {
25
+ const line = doc.line(pos.line + 1);
26
+ return Math.min(line.from + pos.character, line.to);
27
+ };
28
+ /**
29
+ * 创建 TooltipView
30
+ * @param view EditorView 实例
31
+ * @param innerHTML 提示内容
32
+ */
33
+ export const createTooltipView = (view, innerHTML) => {
34
+ const inner = elt('div'), dom = elt('div', { class: hoverSelector.slice(1) }, inner);
35
+ dom.style.font = getComputedStyle(view.contentDOM).font;
36
+ inner.innerHTML = innerHTML;
37
+ return { dom };
38
+ };
39
+ /**
40
+ * Update the stack of opening (+) or closing (-) brackets
41
+ * @param state
42
+ * @param node 语法树节点
43
+ */
44
+ export const braceStackUpdate = (state, node) => {
45
+ const brackets = state.sliceDoc(node.from, node.to);
46
+ return [brackets.split('{{').length - 1, 1 - brackets.split('}}').length];
47
+ };
48
+ /**
49
+ * 判断节点是否包含指定类型
50
+ * @param types 节点类型
51
+ * @param names 指定类型
52
+ */
53
+ export const hasTag = (types, names) => (Array.isArray(names) ? names : [names]).some(name => types.has(name in tokens ? tokens[name] : name));
package/dist/vue.js CHANGED
@@ -2,8 +2,8 @@ import { vue } from '@codemirror/lang-vue';
2
2
  import { htmlLanguage, htmlCompletionSource } from '@codemirror/lang-html';
3
3
  import { javascript } from '@codemirror/lang-javascript';
4
4
  import { LanguageSupport } from '@codemirror/language';
5
- import { jsCompletion } from './javascript';
6
5
  import { cssCompletion } from './css';
6
+ import { jsCompletion } from './javascript';
7
7
  export default () => vue({
8
8
  base: new LanguageSupport(htmlLanguage, [
9
9
  htmlLanguage.data.of({ autocomplete: htmlCompletionSource }),