@bhsd/codemirror-mediawiki 2.0.12 → 2.0.14

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
@@ -8,7 +8,9 @@
8
8
  - [Usage](#usage)
9
9
  - [constructor](#constructor)
10
10
  - [textarea](#textarea)
11
+ - [lang](#lang)
11
12
  - [view](#view)
13
+ - [getLinter](#getlinter)
12
14
  - [lint](#lint)
13
15
  - [prefer](#prefer)
14
16
  - [setIndent](#setindent)
@@ -64,6 +66,18 @@ The textarea element replaced by CodeMirror.
64
66
 
65
67
  </details>
66
68
 
69
+ ## lang
70
+
71
+ <details>
72
+ <summary>Expand</summary>
73
+
74
+ *version added: 2.0.13*
75
+
76
+ **type**: `string`
77
+ The current language mode.
78
+
79
+ </details>
80
+
67
81
  ## view
68
82
 
69
83
  <details>
@@ -74,23 +88,35 @@ The CodeMirror EditorView instance.
74
88
 
75
89
  </details>
76
90
 
91
+ ## getLinter
92
+
93
+ <details>
94
+ <summary>Expand</summary>
95
+
96
+ *version added: 2.0.13*
97
+
98
+ **returns**: `Promise<(doc: Text) => Diagnostic[] | Promise<Diagnostic[]>>`
99
+ Get the default linting function, which can be used as the argument of [`lint`](#lint).
100
+
101
+ </details>
102
+
77
103
  ## lint
78
104
 
79
105
  <details>
80
106
  <summary>Expand</summary>
81
107
 
82
- **param**: `(str: string) => Diagnostic[] | Promise<Diagnostic[]>` the linting function
108
+ **param**: `(doc: Text) => Diagnostic[] | Promise<Diagnostic[]>` the linting function
83
109
  Set the linting function.
84
110
 
85
111
  ```js
86
- cm.lint( ( str ) => [
112
+ cm.lint( ( doc ) => [
87
113
  /**
88
114
  * @type {Diagnostic}
89
115
  * @see https://codemirror.net/docs/ref/#lint.Diagnostic
90
116
  */
91
117
  {
92
118
  from: 0,
93
- to: str.length,
119
+ to: doc.toString().length,
94
120
  message: 'error message',
95
121
  severity: 'error',
96
122
  },
@@ -104,6 +130,8 @@ cm.lint( ( str ) => [
104
130
  <details>
105
131
  <summary>Expand</summary>
106
132
 
133
+ *version added: 2.0.9*
134
+
107
135
  **param**: `string` the preferred [CodeMirror extensions](https://codemirror.net/docs/extensions/)
108
136
  Set the preferred CodeMirror extensions.
109
137
 
@@ -125,6 +153,8 @@ cm.prefer( [
125
153
  <details>
126
154
  <summary>Expand</summary>
127
155
 
156
+ *version added: 2.0.8*
157
+
128
158
  **param**: `string` the indentation string, default as tab
129
159
  Set the indentation string.
130
160
 
@@ -1,8 +1,11 @@
1
1
  import { EditorView } from '@codemirror/view';
2
+ import type { Text } from '@codemirror/state';
2
3
  import type { Diagnostic } from '@codemirror/lint';
3
4
  export type { MwConfig } from './mediawiki';
5
+ export type LintSource = (doc: Text) => Diagnostic[] | Promise<Diagnostic[]>;
4
6
  export declare class CodeMirror6 {
5
7
  #private;
8
+ lang: string;
6
9
  get textarea(): HTMLTextAreaElement;
7
10
  get view(): EditorView;
8
11
  /**
@@ -21,11 +24,13 @@ export declare class CodeMirror6 {
21
24
  * 开始语法检查
22
25
  * @param lintSource 语法检查函数
23
26
  */
24
- lint(lintSource?: (str: string) => Diagnostic[] | Promise<Diagnostic[]>): void;
27
+ lint(lintSource?: LintSource): void;
25
28
  /** 立即更新语法检查 */
26
29
  update(): void;
27
30
  /** 添加扩展 */
28
31
  prefer(names: string[]): void;
29
32
  /** 设置缩进 */
30
33
  setIndent(indent: string): void;
34
+ /** 获取默认linter */
35
+ getLinter(): Promise<LintSource>;
31
36
  }