@bhsd/codemirror-mediawiki 3.6.4 → 3.6.5

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.d.ts CHANGED
@@ -81,7 +81,8 @@ declare class MediaWikiData {
81
81
  firstMultiLetterWord: number | null;
82
82
  firstSpace: number | null;
83
83
  readonly tags: string[];
84
- constructor(tags: string[]);
84
+ readonly urlProtocols: RegExp;
85
+ constructor(tags: string[], urlProtocols: string);
85
86
  }
86
87
  /** Adapted from the original CodeMirror 5 stream parser by Pavel Astakhov */
87
88
  export declare class MediaWiki {
package/dist/token.js CHANGED
@@ -44,8 +44,9 @@ import { decodeHTML } from '@bhsd/browser';
44
44
  import { otherParserFunctions } from '@bhsd/cm-util';
45
45
  import { htmlTags, voidHtmlTags, selfClosingTags, tokenTable, tokens } from './config';
46
46
  class MediaWikiData {
47
- constructor(tags) {
47
+ constructor(tags, urlProtocols) {
48
48
  this.tags = tags.includes('translate') ? tags.filter(tag => tag !== 'tvar') : tags;
49
+ this.urlProtocols = new RegExp(String.raw `^(${this.tags.includes('tvar') ? '<tvar name=[^>]+>' : ''})?${urlProtocols}`, 'iu');
49
50
  this.firstSingleLetterWord = null;
50
51
  this.firstMultiLetterWord = null;
51
52
  this.firstSpace = null;
@@ -84,7 +85,7 @@ const simpleToken = (stream, state) => {
84
85
  const style = state.tokenize(stream, state);
85
86
  return Array.isArray(style) ? style[0] : style;
86
87
  };
87
- const startState = (tokenize, tags, sof = false) => ({
88
+ const startState = (tokenize, tags, urlProtocols, sof = false) => ({
88
89
  tokenize,
89
90
  stack: [],
90
91
  inHtmlTag: [],
@@ -103,7 +104,7 @@ const startState = (tokenize, tags, sof = false) => ({
103
104
  sof,
104
105
  redirect: false,
105
106
  imgLink: false,
106
- data: new MediaWikiData(tags),
107
+ data: new MediaWikiData(tags, `(${urlProtocols.source.slice(4)}`),
107
108
  });
108
109
  /**
109
110
  * 复制 StreamParser 状态
@@ -732,10 +733,15 @@ let MediaWiki = (() => {
732
733
  }
733
734
  }
734
735
  else {
735
- const mt = stream.match(this.urlProtocols, false);
736
+ const mt = stream.match(state.data.urlProtocols, false);
736
737
  if (mt) {
737
738
  state.nExtLink++;
738
- chain(state, this.eatExternalLinkProtocol(mt[0], false));
739
+ if (mt[1]) {
740
+ chain(state, this.inChars('<', 'extTagBracket'), this.eatTagName('tvar'), this.inExternalLink(true));
741
+ }
742
+ else {
743
+ chain(state, this.eatExternalLinkProtocol(mt[2], false));
744
+ }
739
745
  return makeLocalTagStyle('extLinkBracket', state);
740
746
  }
741
747
  }
@@ -1697,7 +1703,7 @@ let MediaWiki = (() => {
1697
1703
  */
1698
1704
  mediawiki(tags) {
1699
1705
  return {
1700
- startState: () => startState(this.eatWikiText(''), tags ?? this.tags, tags === undefined),
1706
+ startState: () => startState(this.eatWikiText(''), tags ?? this.tags, this.urlProtocols, tags === undefined),
1701
1707
  copyState,
1702
1708
  token(stream, state) {
1703
1709
  const { data } = state, { readyTokens } = data;
@@ -1895,7 +1901,7 @@ let MediaWiki = (() => {
1895
1901
  }
1896
1902
  'text/pre'() {
1897
1903
  return {
1898
- startState: () => startState(this.inPre(), []),
1904
+ startState: () => startState(this.inPre(), [], this.urlProtocols),
1899
1905
  token: simpleToken,
1900
1906
  };
1901
1907
  }
@@ -1926,19 +1932,19 @@ let MediaWiki = (() => {
1926
1932
  }
1927
1933
  'text/references'(tags) {
1928
1934
  return {
1929
- startState: () => startState(this.inNested('ref'), tags),
1935
+ startState: () => startState(this.inNested('ref'), tags, this.urlProtocols),
1930
1936
  token: simpleToken,
1931
1937
  };
1932
1938
  }
1933
1939
  'text/choose'(tags) {
1934
1940
  return {
1935
- startState: () => startState(this.inNested('option'), tags),
1941
+ startState: () => startState(this.inNested('option'), tags, this.urlProtocols),
1936
1942
  token: simpleToken,
1937
1943
  };
1938
1944
  }
1939
1945
  'text/combobox'(tags) {
1940
1946
  return {
1941
- startState: () => startState(this.inNested('combooption'), tags),
1947
+ startState: () => startState(this.inNested('combooption'), tags, this.urlProtocols),
1942
1948
  token: simpleToken,
1943
1949
  };
1944
1950
  }
@@ -1955,7 +1961,7 @@ let MediaWiki = (() => {
1955
1961
  }
1956
1962
  'text/inputbox'() {
1957
1963
  return {
1958
- startState: () => startState(this.inInputbox, []),
1964
+ startState: () => startState(this.inInputbox, [], this.urlProtocols),
1959
1965
  token: simpleToken,
1960
1966
  };
1961
1967
  }
@@ -1982,10 +1988,10 @@ let MediaWiki = (() => {
1982
1988
  }
1983
1989
  'text/gallery'(tags) {
1984
1990
  return {
1985
- startState: () => startState(this.inGallery(), tags),
1991
+ startState: () => startState(this.inGallery(), tags, this.urlProtocols),
1986
1992
  token: (stream, state) => {
1987
1993
  if (stream.sol()) {
1988
- Object.assign(state, startState(this.inGallery(), state.data.tags));
1994
+ Object.assign(state, startState(this.inGallery(), state.data.tags, this.urlProtocols));
1989
1995
  }
1990
1996
  return simpleToken(stream, state);
1991
1997
  },