質問編集履歴
3
変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
[react-codemirror2]
|
1
|
+
[react-codemirror2]TypeError: mfactory is not a function
|
test
CHANGED
@@ -4,9 +4,7 @@
|
|
4
4
|
|
5
5
|
codemirrorのreactラッパーを使っています。
|
6
6
|
|
7
|
-
自作modeを指定して自分が指定した正規表現と一致した時にハイライトを付けたいと思っているのですが、
|
7
|
+
自作modeを指定して自分が指定した正規表現と一致した時にハイライトを付けたいと思っているのですが、以下のようなエラーが出てうまく行きません。nodemodulesでエラーになっているというのは、自力で直せないということでしょうか。
|
8
|
-
|
9
|
-
公式documentをみながらやっていますが、うまくいきません。どのようにすれば自作modeを作成できるのでしょうか。
|
10
8
|
|
11
9
|
わかる方、経験者がいればコメントお願いします。
|
12
10
|
|
@@ -24,7 +22,27 @@
|
|
24
22
|
|
25
23
|
|
26
24
|
|
25
|
+
TypeError: mfactory is not a function
|
26
|
+
|
27
|
+
|
28
|
+
|
27
|
-
|
29
|
+
getMode
|
30
|
+
|
31
|
+
node_modules/codemirror/lib/codemirror.js:751
|
32
|
+
|
33
|
+
748 | spec = resolveMode(spec);
|
34
|
+
|
35
|
+
749 | var mfactory = modes[spec.name];
|
36
|
+
|
37
|
+
750 | if (!mfactory) { return getMode(options, "text/plain") }
|
38
|
+
|
39
|
+
> 751 | var modeObj = mfactory(options, spec);
|
40
|
+
|
41
|
+
| ^ 752 | if (modeExtensions.hasOwnProperty(spec.name)) {
|
42
|
+
|
43
|
+
753 | var exts = modeExtensions[spec.name];
|
44
|
+
|
45
|
+
754 | for (var prop in exts) {
|
28
46
|
|
29
47
|
|
30
48
|
|
@@ -56,7 +74,13 @@
|
|
56
74
|
|
57
75
|
options={{
|
58
76
|
|
77
|
+
theme: "material",
|
78
|
+
|
79
|
+
lineNumbers: true,
|
80
|
+
|
81
|
+
}}
|
82
|
+
|
59
|
-
|
83
|
+
defineMode: {
|
60
84
|
|
61
85
|
name: "simplemode",
|
62
86
|
|
@@ -76,12 +100,6 @@
|
|
76
100
|
|
77
101
|
},
|
78
102
|
|
79
|
-
theme: "material",
|
80
|
-
|
81
|
-
lineNumbers: true,
|
82
|
-
|
83
|
-
}}
|
84
|
-
|
85
103
|
onChange={(editor, data, value) => {
|
86
104
|
|
87
105
|
}}
|
@@ -99,101 +117,3 @@
|
|
99
117
|
|
100
118
|
|
101
119
|
```
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
##試したこと
|
108
|
-
|
109
|
-
modeの中身を以下のように公式documentと同じにしてもハイライトができなかったので、何か根本が違いそうです。。。
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
```
|
114
|
-
|
115
|
-
// The start state contains the rules that are intially used
|
116
|
-
|
117
|
-
start: [
|
118
|
-
|
119
|
-
// The regex matches the token, the token property contains the type
|
120
|
-
|
121
|
-
{regex: /"(?:[^\]|\.)*?(?:"|$)/, token: "string"},
|
122
|
-
|
123
|
-
// You can match multiple tokens at once. Note that the captured
|
124
|
-
|
125
|
-
// groups must span the whole string in this case
|
126
|
-
|
127
|
-
{regex: /(function)(\s+)([a-z$][\w$]*)/,
|
128
|
-
|
129
|
-
token: ["keyword", null, "variable-2"]},
|
130
|
-
|
131
|
-
// Rules are matched in the order in which they appear, so there is
|
132
|
-
|
133
|
-
// no ambiguity between this one and the one above
|
134
|
-
|
135
|
-
{regex: /(?:function|var|return|if|for|while|else|do|this)\b/,
|
136
|
-
|
137
|
-
token: "keyword"},
|
138
|
-
|
139
|
-
{regex: /true|false|null|undefined/, token: "atom"},
|
140
|
-
|
141
|
-
{regex: /0x[a-f\d]+|[-+]?(?:.\d+|\d+.?\d*)(?:e[-+]?\d+)?/i,
|
142
|
-
|
143
|
-
token: "number"},
|
144
|
-
|
145
|
-
{regex: ///.*/, token: "comment"},
|
146
|
-
|
147
|
-
{regex: //(?:[^\]|\.)*?//, token: "variable-3"},
|
148
|
-
|
149
|
-
// A next property will cause the mode to move to a different state
|
150
|
-
|
151
|
-
{regex: //*/, token: "comment", next: "comment"},
|
152
|
-
|
153
|
-
{regex: /[-+/*=<>!]+/, token: "operator"},
|
154
|
-
|
155
|
-
// indent and dedent properties guide autoindentation
|
156
|
-
|
157
|
-
{regex: /[\{[(]/, indent: true},
|
158
|
-
|
159
|
-
{regex: /[\}])]/, dedent: true},
|
160
|
-
|
161
|
-
{regex: /[a-z$][\w$]*/, token: "variable"},
|
162
|
-
|
163
|
-
// You can embed other modes with the mode property. This rule
|
164
|
-
|
165
|
-
// causes all code between << and >> to be highlighted with the XML
|
166
|
-
|
167
|
-
// mode.
|
168
|
-
|
169
|
-
{regex: /<</, token: "meta", mode: {spec: "xml", end: />>/}}
|
170
|
-
|
171
|
-
],
|
172
|
-
|
173
|
-
// The multi-line comment state.
|
174
|
-
|
175
|
-
comment: [
|
176
|
-
|
177
|
-
{regex: /.*?*//, token: "comment", next: "start"},
|
178
|
-
|
179
|
-
{regex: /.*/, token: "comment"}
|
180
|
-
|
181
|
-
],
|
182
|
-
|
183
|
-
// The meta property contains global information about the mode. It
|
184
|
-
|
185
|
-
// can contain properties like lineComment, which are supported by
|
186
|
-
|
187
|
-
// all modes, and also directives like dontIndentStates, which are
|
188
|
-
|
189
|
-
// specific to simple modes.
|
190
|
-
|
191
|
-
meta: {
|
192
|
-
|
193
|
-
dontIndentStates: ["comment"],
|
194
|
-
|
195
|
-
lineComment: "//"
|
196
|
-
|
197
|
-
}
|
198
|
-
|
199
|
-
```
|
2
変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -102,4 +102,98 @@
|
|
102
102
|
|
103
103
|
|
104
104
|
|
105
|
+
|
106
|
+
|
107
|
+
##試したこと
|
108
|
+
|
109
|
+
modeの中身を以下のように公式documentと同じにしてもハイライトができなかったので、何か根本が違いそうです。。。
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
```
|
114
|
+
|
115
|
+
// The start state contains the rules that are intially used
|
116
|
+
|
117
|
+
start: [
|
118
|
+
|
119
|
+
// The regex matches the token, the token property contains the type
|
120
|
+
|
121
|
+
{regex: /"(?:[^\]|\.)*?(?:"|$)/, token: "string"},
|
122
|
+
|
123
|
+
// You can match multiple tokens at once. Note that the captured
|
124
|
+
|
125
|
+
// groups must span the whole string in this case
|
126
|
+
|
127
|
+
{regex: /(function)(\s+)([a-z$][\w$]*)/,
|
128
|
+
|
129
|
+
token: ["keyword", null, "variable-2"]},
|
130
|
+
|
131
|
+
// Rules are matched in the order in which they appear, so there is
|
132
|
+
|
133
|
+
// no ambiguity between this one and the one above
|
134
|
+
|
135
|
+
{regex: /(?:function|var|return|if|for|while|else|do|this)\b/,
|
136
|
+
|
137
|
+
token: "keyword"},
|
138
|
+
|
139
|
+
{regex: /true|false|null|undefined/, token: "atom"},
|
140
|
+
|
141
|
+
{regex: /0x[a-f\d]+|[-+]?(?:.\d+|\d+.?\d*)(?:e[-+]?\d+)?/i,
|
142
|
+
|
143
|
+
token: "number"},
|
144
|
+
|
145
|
+
{regex: ///.*/, token: "comment"},
|
146
|
+
|
147
|
+
{regex: //(?:[^\]|\.)*?//, token: "variable-3"},
|
148
|
+
|
149
|
+
// A next property will cause the mode to move to a different state
|
150
|
+
|
151
|
+
{regex: //*/, token: "comment", next: "comment"},
|
152
|
+
|
153
|
+
{regex: /[-+/*=<>!]+/, token: "operator"},
|
154
|
+
|
155
|
+
// indent and dedent properties guide autoindentation
|
156
|
+
|
157
|
+
{regex: /[\{[(]/, indent: true},
|
158
|
+
|
159
|
+
{regex: /[\}])]/, dedent: true},
|
160
|
+
|
161
|
+
{regex: /[a-z$][\w$]*/, token: "variable"},
|
162
|
+
|
163
|
+
// You can embed other modes with the mode property. This rule
|
164
|
+
|
165
|
+
// causes all code between << and >> to be highlighted with the XML
|
166
|
+
|
167
|
+
// mode.
|
168
|
+
|
169
|
+
{regex: /<</, token: "meta", mode: {spec: "xml", end: />>/}}
|
170
|
+
|
171
|
+
],
|
172
|
+
|
173
|
+
// The multi-line comment state.
|
174
|
+
|
175
|
+
comment: [
|
176
|
+
|
177
|
+
{regex: /.*?*//, token: "comment", next: "start"},
|
178
|
+
|
179
|
+
{regex: /.*/, token: "comment"}
|
180
|
+
|
181
|
+
],
|
182
|
+
|
183
|
+
// The meta property contains global information about the mode. It
|
184
|
+
|
185
|
+
// can contain properties like lineComment, which are supported by
|
186
|
+
|
187
|
+
// all modes, and also directives like dontIndentStates, which are
|
188
|
+
|
189
|
+
// specific to simple modes.
|
190
|
+
|
191
|
+
meta: {
|
192
|
+
|
193
|
+
dontIndentStates: ["comment"],
|
194
|
+
|
195
|
+
lineComment: "//"
|
196
|
+
|
105
|
-
|
197
|
+
}
|
198
|
+
|
199
|
+
```
|
1
ミス
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,11 +24,7 @@
|
|
24
24
|
|
25
25
|
|
26
26
|
|
27
|
-
```
|
28
|
-
|
29
|
-
|
27
|
+
ハイライトが付かない
|
30
|
-
|
31
|
-
```
|
32
28
|
|
33
29
|
|
34
30
|
|
@@ -70,7 +66,7 @@
|
|
70
66
|
|
71
67
|
{
|
72
68
|
|
73
|
-
regex: /@/,
|
69
|
+
regex: /@/, //例えば@をハイライトさせたい場合
|
74
70
|
|
75
71
|
},
|
76
72
|
|