@bhsd/codemirror-mediawiki 3.5.0 → 3.5.2

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.
@@ -8,7 +8,7 @@ import { MediaWiki } from './token';
8
8
  import type { StreamParser, TagStyle } from '@codemirror/language';
9
9
  import type { CompletionSource, Completion } from '@codemirror/autocomplete';
10
10
  import type { MwConfig } from './token';
11
- export declare const re: RegExp;
11
+ export declare const isWMF: boolean;
12
12
  /**
13
13
  * 判断节点是否包含指定类型
14
14
  * @param types 节点类型
package/dist/mediawiki.js CHANGED
@@ -6,12 +6,13 @@
6
6
  import { HighlightStyle, LanguageSupport, StreamLanguage, syntaxHighlighting, syntaxTree, } from '@codemirror/language';
7
7
  import { insertCompletionText, pickedCompletion } from '@codemirror/autocomplete';
8
8
  import { wmf } from '@bhsd/common';
9
+ import { isUnderscore } from '@bhsd/cm-util';
9
10
  import { commonHtmlAttrs, htmlAttrs, extAttrs } from 'wikiparser-node/dist/util/sharable.mjs';
10
11
  import { MediaWiki } from './token';
11
12
  import { htmlTags, tokens } from './config';
12
13
  import { braceStackUpdate } from './fold';
13
14
  import { EditorView } from '@codemirror/view';
14
- export const re = /* @__PURE__ */ (() => new RegExp(String.raw `\.(?:${wmf})\.org$`, 'u'))();
15
+ export const isWMF = /* @__PURE__ */ (() => typeof location === 'object' && new RegExp(String.raw `\.(?:${wmf})\.org$`, 'u').test(location.hostname))();
15
16
  /**
16
17
  * 检查首字母大小写并插入正确的自动填充内容
17
18
  * @param view
@@ -45,7 +46,7 @@ export class FullMediaWiki extends MediaWiki {
45
46
  type: i ? 'constant' : 'function',
46
47
  label,
47
48
  })));
48
- this.doubleUnderscore = doubleUnderscore.flatMap(Object.keys).map((label) => ({
49
+ this.doubleUnderscore = doubleUnderscore.flatMap(Object.keys).filter(isUnderscore).map((label) => ({
49
50
  type: 'constant',
50
51
  label,
51
52
  }));
@@ -162,7 +163,7 @@ export class FullMediaWiki extends MediaWiki {
162
163
  get completionSource() {
163
164
  return async (context) => {
164
165
  const { state, pos, explicit } = context, node = syntaxTree(state).resolve(pos, -1), types = new Set(node.name.split('_')), isParserFunction = hasTag(types, 'parserFunctionName'),
165
- /** 开头不包含` `,但可能包含`_` */ search = state.sliceDoc(node.from, pos).trimStart(), start = pos - search.length, isWMF = re.test(location.hostname);
166
+ /** 开头不包含` `,但可能包含`_` */ search = state.sliceDoc(node.from, pos).trimStart(), start = pos - search.length;
166
167
  let { prevSibling } = node;
167
168
  if (explicit || isParserFunction && search.includes('#') || isWMF) {
168
169
  const validFor = isWMF ? null : { validFor: /^[^|{}<>[\]#]*$/u };