@bhsd/codemirror-mediawiki 2.0.6 → 2.0.8

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/README.md CHANGED
@@ -1,2 +1,8 @@
1
+ [![npm version](https://badge.fury.io/js/@bhsd%2Fcodemirror-mediawiki.svg)](https://www.npmjs.com/package/@bhsd/codemirror-mediawiki)
2
+ [![CodeQL](https://github.com/bhsd-harry/codemirror-mediawiki/actions/workflows/codeql.yml/badge.svg)](https://github.com/bhsd-harry/codemirror-mediawiki/actions/workflows/codeql.yml)
3
+
1
4
  # Description
2
- This repository contains a modified version of a [CodeMirror](https://codemirror.net/) mode ["mediawiki"](https://github.com/wikimedia/mediawiki-extensions-CodeMirror/tree/REL1_37/resources/mode/mediawiki) within the [MediaWiki extension CodeMirror](https://www.mediawiki.org/wiki/Extension:CodeMirror).
5
+
6
+ This repository contains a modified version of the frontend scripts and styles from [MediaWiki extension CodeMirror](https://www.mediawiki.org/wiki/Extension:CodeMirror). The goal is to support a standalone integration between [CodeMirror](https://codemimrror.net) and [Wikitext](https://www.mediawiki.org/wiki/Wikitext), without the need for a [MediaWiki environment](https://doc.wikimedia.org/mediawiki-core/master/js/).
7
+
8
+ Here is a [demo](https://bhsd-harry.github.io/wikiparser-node/index.html#linter) when the option "with syntax highlighting" is checked.
@@ -0,0 +1,34 @@
1
+ import { Compartment } from '@codemirror/state';
2
+ import { EditorView } from '@codemirror/view';
3
+ import type { Diagnostic } from '@codemirror/lint';
4
+ export type { MwConfig } from './mediawiki';
5
+ export declare class CodeMirror6 {
6
+ textarea: HTMLTextAreaElement;
7
+ language: Compartment;
8
+ linter: Compartment;
9
+ extensions: Compartment;
10
+ view: EditorView;
11
+ /**
12
+ * @param textarea 文本框
13
+ * @param lang 语言
14
+ * @param config 语言设置
15
+ */
16
+ constructor(textarea: HTMLTextAreaElement, lang?: string, config?: unknown);
17
+ /**
18
+ * 设置语言
19
+ * @param lang 语言
20
+ * @param config 语言设置
21
+ */
22
+ setLanguage(lang?: string, config?: unknown): void;
23
+ /**
24
+ * 开始语法检查
25
+ * @param lintSource 语法检查函数
26
+ */
27
+ lint(lintSource?: (str: string) => Diagnostic[] | Promise<Diagnostic[]>): void;
28
+ /** 立即更新语法检查 */
29
+ update(): void;
30
+ /** 保存至文本框 */
31
+ save(): void;
32
+ /** 添加扩展 */
33
+ prefer(names: string[]): void;
34
+ }
@@ -0,0 +1,191 @@
1
+ /**
2
+ * @author MusikAnimal and others
3
+ * @license GPL-2.0-or-later
4
+ * @link https://gerrit.wikimedia.org/g/mediawiki/extensions/CodeMirror
5
+ */
6
+ import { HighlightStyle } from '@codemirror/language';
7
+ import { Tag } from '@lezer/highlight';
8
+ import type { StreamParser } from '@codemirror/language';
9
+ /**
10
+ * Configuration for the MediaWiki highlighting mode for CodeMirror.
11
+ * This is a separate class mainly to keep static configuration out of
12
+ * the logic in CodeMirrorModeMediaWiki.
13
+ */
14
+ export declare const modeConfig: {
15
+ /**
16
+ * All HTML/XML tags permitted in MediaWiki Core.
17
+ *
18
+ * Extensions should use the CodeMirrorTagModes extension attribute to register tags
19
+ * instead of adding them here.
20
+ *
21
+ * @see https://www.mediawiki.org/wiki/Extension:CodeMirror#Extension_integration
22
+ */
23
+ permittedHtmlTags: {
24
+ b: boolean;
25
+ bdi: boolean;
26
+ del: boolean;
27
+ i: boolean;
28
+ ins: boolean;
29
+ u: boolean;
30
+ font: boolean;
31
+ big: boolean;
32
+ small: boolean;
33
+ sub: boolean;
34
+ sup: boolean;
35
+ h1: boolean;
36
+ h2: boolean;
37
+ h3: boolean;
38
+ h4: boolean;
39
+ h5: boolean;
40
+ h6: boolean;
41
+ cite: boolean;
42
+ code: boolean;
43
+ em: boolean;
44
+ s: boolean;
45
+ strike: boolean;
46
+ strong: boolean;
47
+ tt: boolean;
48
+ var: boolean;
49
+ div: boolean;
50
+ center: boolean;
51
+ blockquote: boolean;
52
+ q: boolean;
53
+ ol: boolean;
54
+ ul: boolean;
55
+ dl: boolean;
56
+ table: boolean;
57
+ caption: boolean;
58
+ pre: boolean;
59
+ ruby: boolean;
60
+ rb: boolean;
61
+ rp: boolean;
62
+ rt: boolean;
63
+ rtc: boolean;
64
+ p: boolean;
65
+ span: boolean;
66
+ abbr: boolean;
67
+ dfn: boolean;
68
+ kbd: boolean;
69
+ samp: boolean;
70
+ data: boolean;
71
+ time: boolean;
72
+ mark: boolean;
73
+ br: boolean;
74
+ wbr: boolean;
75
+ hr: boolean;
76
+ li: boolean;
77
+ dt: boolean;
78
+ dd: boolean;
79
+ td: boolean;
80
+ th: boolean;
81
+ tr: boolean;
82
+ noinclude: boolean;
83
+ includeonly: boolean;
84
+ onlyinclude: boolean;
85
+ };
86
+ /**
87
+ * HTML tags that are only self-closing.
88
+ */
89
+ implicitlyClosedHtmlTags: Record<string, true>;
90
+ /**
91
+ * Mapping of MediaWiki-esque token identifiers to a standardized lezer highlighting tag.
92
+ * Values are one of the default highlighting tags. The idea is to use as many default tags as
93
+ * possible so that theming (such as dark mode) can be applied with minimal effort. The
94
+ * semantic meaning of the tag may not really match how it is used, but as per CodeMirror docs,
95
+ * this is fine. It's still better to make use of the standard tags in some way.
96
+ *
97
+ * Once we allow use of other themes, we may want to tweak these values for aesthetic reasons.
98
+ * The values here can freely be changed. The actual CSS class used is defined further down
99
+ * in highlightStyle().
100
+ *
101
+ * @see https://lezer.codemirror.net/docs/ref/#highlight.tags
102
+ * @internal
103
+ */
104
+ tags: {
105
+ apostrophes: string;
106
+ apostrophesBold: string;
107
+ apostrophesItalic: string;
108
+ comment: string;
109
+ doubleUnderscore: string;
110
+ extLink: string;
111
+ extLinkBracket: string;
112
+ extLinkProtocol: string;
113
+ extLinkText: string;
114
+ hr: string;
115
+ htmlTagAttribute: string;
116
+ htmlTagBracket: string;
117
+ htmlTagName: string;
118
+ extTagAttribute: string;
119
+ extTagBracket: string;
120
+ extTagName: string;
121
+ indenting: string;
122
+ linkBracket: string;
123
+ linkDelimiter: string;
124
+ linkText: string;
125
+ linkToSection: string;
126
+ list: string;
127
+ parserFunction: string;
128
+ parserFunctionBracket: string;
129
+ parserFunctionDelimiter: string;
130
+ parserFunctionName: string;
131
+ sectionHeader: string;
132
+ sectionHeader1: string;
133
+ sectionHeader2: string;
134
+ sectionHeader3: string;
135
+ sectionHeader4: string;
136
+ sectionHeader5: string;
137
+ sectionHeader6: string;
138
+ signature: string;
139
+ tableBracket: string;
140
+ tableDefinition: string;
141
+ tableDelimiter: string;
142
+ template: string;
143
+ templateArgumentName: string;
144
+ templateBracket: string;
145
+ templateDelimiter: string;
146
+ templateName: string;
147
+ templateVariable: string;
148
+ templateVariableBracket: string;
149
+ templateVariableName: string;
150
+ section: string;
151
+ em: string;
152
+ error: string;
153
+ extTag: string;
154
+ extGround: string;
155
+ freeExtLink: string;
156
+ freeExtLinkProtocol: string;
157
+ link: string;
158
+ linkGround: string;
159
+ linkPageName: string;
160
+ mnemonic: string;
161
+ pageName: string;
162
+ skipFormatting: string;
163
+ strong: string;
164
+ tableCaption: string;
165
+ templateGround: string;
166
+ templateExtGround: string;
167
+ templateLinkGround: string;
168
+ templateVariableDelimiter: string;
169
+ template2ExtGround: string;
170
+ template2Ground: string;
171
+ template3ExtGround: string;
172
+ template3Ground: string;
173
+ pre: string;
174
+ nowiki: string;
175
+ };
176
+ /**
177
+ * These are custom tokens (a.k.a. tags) that aren't mapped to any of the standardized tags.
178
+ * Make sure these are also defined in tags() above.
179
+ *
180
+ * @see https://codemirror.net/docs/ref/#language.StreamParser.tokenTable
181
+ * @see https://lezer.codemirror.net/docs/ref/#highlight.Tag%5Edefine
182
+ */
183
+ readonly tokenTable: Record<string, Tag>;
184
+ /**
185
+ * This defines the actual CSS class assigned to each tag/token.
186
+ * Keep this in sync and in the same order as tags().
187
+ *
188
+ * @see https://codemirror.net/docs/ref/#language.TagStyle
189
+ */
190
+ getHighlightStyle(context: StreamParser<unknown>): HighlightStyle;
191
+ };