@zzish/math-rich-input 0.1.35 → 0.1.36
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/index.js +16 -15
- package/dist/math-rich-input.css +130 -130
- package/package.json +1 -1
- package/src/mimeTypeHelper.js +72 -81
package/dist/index.js
CHANGED
|
@@ -20534,10 +20534,10 @@ var Toolbar = /*#__PURE__*/function (_React$Component) {
|
|
|
20534
20534
|
|
|
20535
20535
|
var INLINE_LATEX_REG_EXP = /\$\$[\s\S]+?\$\$|\\\[[\s\S]+?\\\]|\\\([\s\S]+?\\\)|\$[^$\\]*(?:\\.[^$\\]*)*\$/g;
|
|
20536
20536
|
var BLOCL_LATEX_REG_EXP = /\$\$[\s\S]+?\$\$|\\\[[\s\S]+?\\\]/g;
|
|
20537
|
-
var MIME_TYPE_PLAIN_TEXT$2 =
|
|
20538
|
-
var MIME_TYPE_HTML$2 =
|
|
20539
|
-
var MIME_TYPE_TEX$2 =
|
|
20540
|
-
var MIME_TYPE_ZZISH_HTML_MATH$2 =
|
|
20537
|
+
var MIME_TYPE_PLAIN_TEXT$2 = 'text/plain';
|
|
20538
|
+
var MIME_TYPE_HTML$2 = 'text/html';
|
|
20539
|
+
var MIME_TYPE_TEX$2 = 'application/x-tex';
|
|
20540
|
+
var MIME_TYPE_ZZISH_HTML_MATH$2 = 'application/x-zzish-html-math';
|
|
20541
20541
|
var LATEX_COMMAND_REG_EXP = /\\[a-zA-Z]/g;
|
|
20542
20542
|
var HTML_CODES_REG_EXP = /&(#36|quot|apos|lt|gt|amp);/;
|
|
20543
20543
|
var HTML_TAGS_REG_EXP = /<(br|basefont|hr|input|source|frame|param|area|meta|!--|col|link|option|base|img|wbr|!DOCTYPE).*?>|<(a|abbr|acronym|address|applet|article|aside|audio|b|bdi|bdo|big|blockquote|body|button|canvas|caption|center|cite|code|colgroup|command|datalist|dd|del|details|dfn|dialog|dir|div|dl|dt|em|embed|fieldset|figcaption|figure|font|footer|form|frameset|head|header|hgroup|h1|h2|h3|h4|h5|h6|html|i|iframe|ins|kbd|keygen|label|legend|li|map|mark|menu|meter|nav|noframes|noscript|object|ol|optgroup|output|p|pre|progress|q|rp|rt|ruby|s|samp|script|section|select|small|span|strike|strong|style|sub|summary|sup|table|tbody|td|textarea|tfoot|th|thead|time|title|tr|track|tt|u|ul|var|video).*?<\/\2>/i;
|
|
@@ -20545,16 +20545,16 @@ var HTML_MATH_TAGS_REC_EXP = /<math>/i;
|
|
|
20545
20545
|
var WORDS_REG_EXP = /^[a-zA-Z]*[,."';:?!]*$/i;
|
|
20546
20546
|
|
|
20547
20547
|
function stripDollars$1(stringToStrip) {
|
|
20548
|
-
return stringToStrip[0] ===
|
|
20548
|
+
return stringToStrip[0] === '$' && stringToStrip[1] !== '$' ? stringToStrip.slice(1, -1) : stringToStrip.slice(2, -2);
|
|
20549
20549
|
}
|
|
20550
20550
|
|
|
20551
20551
|
function isTextLatexMath(text) {
|
|
20552
20552
|
// We need at least two dollar signs to be latex
|
|
20553
|
-
var i = text.indexOf(
|
|
20553
|
+
var i = text.indexOf('$');
|
|
20554
20554
|
if (i < 0) return false;
|
|
20555
|
-
var j = text.indexOf(
|
|
20555
|
+
var j = text.indexOf('\\$');
|
|
20556
20556
|
if (j >= 0) return true;
|
|
20557
|
-
i = text.indexOf(
|
|
20557
|
+
i = text.indexOf('$', i + 1);
|
|
20558
20558
|
if (i < 0) return false; // Lets try and extract the potentially latex nodes
|
|
20559
20559
|
|
|
20560
20560
|
var latexMatch = text.match(BLOCL_LATEX_REG_EXP);
|
|
@@ -20566,7 +20566,7 @@ function isTextLatexMath(text) {
|
|
|
20566
20566
|
} // If all dollar signs are followed by a number, it probably is not latex
|
|
20567
20567
|
|
|
20568
20568
|
|
|
20569
|
-
i = text.indexOf(
|
|
20569
|
+
i = text.indexOf('$');
|
|
20570
20570
|
var probablyLatex = false;
|
|
20571
20571
|
|
|
20572
20572
|
while (i >= 0) {
|
|
@@ -20577,14 +20577,14 @@ function isTextLatexMath(text) {
|
|
|
20577
20577
|
|
|
20578
20578
|
var c = text.charAt(i + 1);
|
|
20579
20579
|
|
|
20580
|
-
if (c <
|
|
20580
|
+
if (c < '0' || c > '9') {
|
|
20581
20581
|
probablyLatex = true;
|
|
20582
20582
|
break;
|
|
20583
20583
|
}
|
|
20584
20584
|
|
|
20585
|
-
i = text.indexOf(
|
|
20585
|
+
i = text.indexOf('$', i + 1);
|
|
20586
20586
|
} // Note that there are other uses of a dollar sign, that couold potentially be
|
|
20587
|
-
// entered. For example, if someone created a question about the use of the
|
|
20587
|
+
// entered. For example, if someone created a question about the use of the
|
|
20588
20588
|
// $ sign in excel cells or the use of the $ sign in regular expressions.
|
|
20589
20589
|
|
|
20590
20590
|
|
|
@@ -20603,14 +20603,14 @@ function isTextLatexMath(text) {
|
|
|
20603
20603
|
var allEmpty = true;
|
|
20604
20604
|
|
|
20605
20605
|
for (var _i2 = 0; _i2 < latexMatch.length; _i2++) {
|
|
20606
|
-
if (latexMatch[_i2] !==
|
|
20606
|
+
if (latexMatch[_i2] !== '') allEmpty = false;
|
|
20607
20607
|
}
|
|
20608
20608
|
|
|
20609
20609
|
if (allEmpty) return false; // If an element between two dollars is two or more words and only words
|
|
20610
20610
|
// and at least one word has three characters then we will treat it as text
|
|
20611
20611
|
|
|
20612
20612
|
for (var _i3 = 0; _i3 < latexMatch.length; _i3++) {
|
|
20613
|
-
var words = latexMatch[_i3].split(
|
|
20613
|
+
var words = latexMatch[_i3].split(' ');
|
|
20614
20614
|
|
|
20615
20615
|
if (words.length >= 2) {
|
|
20616
20616
|
var allWords = true;
|
|
@@ -20643,8 +20643,9 @@ function isTextLatexMath(text) {
|
|
|
20643
20643
|
}
|
|
20644
20644
|
}
|
|
20645
20645
|
function isTextHtml(text) {
|
|
20646
|
+
text = text.replace(/[\r\n]+/g, ' ');
|
|
20646
20647
|
if (HTML_CODES_REG_EXP.test(text)) return true;
|
|
20647
|
-
var i = text.indexOf(
|
|
20648
|
+
var i = text.indexOf('<');
|
|
20648
20649
|
if (i < 0) return false;
|
|
20649
20650
|
var containsHtmlTags = HTML_TAGS_REG_EXP.test(text);
|
|
20650
20651
|
return containsHtmlTags;
|
package/dist/math-rich-input.css
CHANGED
|
@@ -78,6 +78,136 @@
|
|
|
78
78
|
padding: 2px;
|
|
79
79
|
margin: 0px 2px;
|
|
80
80
|
}
|
|
81
|
+
/* Note that the top left position of the toolbar is set programatically in componentDidMount */
|
|
82
|
+
|
|
83
|
+
.Toolbar {
|
|
84
|
+
position: absolute;
|
|
85
|
+
z-index: 1;
|
|
86
|
+
display: flex;
|
|
87
|
+
height: 42px;
|
|
88
|
+
background-color: white;
|
|
89
|
+
border: 1px solid #d0d0d0;
|
|
90
|
+
border-radius: 5px;
|
|
91
|
+
box-shadow: 1px 1px 5px #a0a0a0;
|
|
92
|
+
animation: 0.5s fadeIn1;
|
|
93
|
+
animation-fill-mode: forwards;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@keyframes fadeIn1 {
|
|
97
|
+
0% {
|
|
98
|
+
opacity: 0;
|
|
99
|
+
}
|
|
100
|
+
100% {
|
|
101
|
+
opacity: 1;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.Toolbar-button {
|
|
106
|
+
font-family: sans-serif;
|
|
107
|
+
font-size: 16px;
|
|
108
|
+
width: 40px;
|
|
109
|
+
height: 36px;
|
|
110
|
+
background-color: white;
|
|
111
|
+
border-radius: 5px;
|
|
112
|
+
border: 0px;
|
|
113
|
+
padding: 1px;
|
|
114
|
+
margin: 2px;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.Toolbar-button:hover {
|
|
118
|
+
color: white;
|
|
119
|
+
background: #663676;
|
|
120
|
+
cursor: pointer;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.Toolbar-button:active {
|
|
124
|
+
background: #808080;
|
|
125
|
+
color: white;
|
|
126
|
+
cursor: pointer;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.TB-narrow {
|
|
130
|
+
width: 30px;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.TB-wide {
|
|
134
|
+
width: 46px;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.TB-selected {
|
|
138
|
+
background: #d0d0d0;
|
|
139
|
+
color: black;
|
|
140
|
+
cursor: pointer;
|
|
141
|
+
animation: 0.2s TB-fadeIn;
|
|
142
|
+
animation-fill-mode: forwards;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.TB-selected:hover {
|
|
146
|
+
color: white;
|
|
147
|
+
background: #663676;
|
|
148
|
+
cursor: pointer;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@keyframes TB-fadeIn {
|
|
152
|
+
00% {
|
|
153
|
+
background: white;
|
|
154
|
+
}
|
|
155
|
+
100% {
|
|
156
|
+
background: #d0d0d0;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/* Tooltip text */
|
|
161
|
+
.Toolbar-button .tooltiptext {
|
|
162
|
+
font-weight: normal;
|
|
163
|
+
visibility: hidden;
|
|
164
|
+
width: 100px;
|
|
165
|
+
background-color: #222;
|
|
166
|
+
color: #fff;
|
|
167
|
+
/*font-weight: bold;*/
|
|
168
|
+
font-size: 12px;
|
|
169
|
+
text-align: center;
|
|
170
|
+
padding: 4px 10px;
|
|
171
|
+
border-radius: 6px;
|
|
172
|
+
|
|
173
|
+
/* Position the tooltip text - see examples below! */
|
|
174
|
+
position: absolute;
|
|
175
|
+
z-index: 2;
|
|
176
|
+
top: -90%; /* Must leave a small gap between tooltip and button */
|
|
177
|
+
left: 50px;
|
|
178
|
+
|
|
179
|
+
/* transform: translate (50%,0%); */
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/* Show the tooltip text when you mouse over the tooltip container */
|
|
183
|
+
.Toolbar-button:hover .tooltiptext {
|
|
184
|
+
animation: 0.8s fadeIn2;
|
|
185
|
+
animation-fill-mode: forwards;
|
|
186
|
+
visibility: visible;
|
|
187
|
+
/* width: 100px; */
|
|
188
|
+
/* top: -90%; */ /* Must leave a small gap between tooltip and button */
|
|
189
|
+
/* left: 20%; */
|
|
190
|
+
/* margin-left: -50px; */
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
@keyframes fadeIn2 {
|
|
194
|
+
00% {
|
|
195
|
+
opacity: 0;
|
|
196
|
+
}
|
|
197
|
+
70% {
|
|
198
|
+
opacity: 0;
|
|
199
|
+
}
|
|
200
|
+
100% {
|
|
201
|
+
visibility: visible;
|
|
202
|
+
opacity: 0.9;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/* .tooltip {
|
|
207
|
+
position: relative;
|
|
208
|
+
display: inline-block;
|
|
209
|
+
border-bottom: 1px dotted black; /* If you want dots under the hoverable text
|
|
210
|
+
} */
|
|
81
211
|
/* Note that the top left position of the accent bar is set programatically in componentDidMount */
|
|
82
212
|
|
|
83
213
|
.AccentBar {
|
|
@@ -253,136 +383,6 @@
|
|
|
253
383
|
animation: 0.4s fadeIn1;
|
|
254
384
|
animation-fill-mode: forwards;
|
|
255
385
|
}
|
|
256
|
-
/* Note that the top left position of the toolbar is set programatically in componentDidMount */
|
|
257
|
-
|
|
258
|
-
.Toolbar {
|
|
259
|
-
position: absolute;
|
|
260
|
-
z-index: 1;
|
|
261
|
-
display: flex;
|
|
262
|
-
height: 42px;
|
|
263
|
-
background-color: white;
|
|
264
|
-
border: 1px solid #d0d0d0;
|
|
265
|
-
border-radius: 5px;
|
|
266
|
-
box-shadow: 1px 1px 5px #a0a0a0;
|
|
267
|
-
animation: 0.5s fadeIn1;
|
|
268
|
-
animation-fill-mode: forwards;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
@keyframes fadeIn1 {
|
|
272
|
-
0% {
|
|
273
|
-
opacity: 0;
|
|
274
|
-
}
|
|
275
|
-
100% {
|
|
276
|
-
opacity: 1;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
.Toolbar-button {
|
|
281
|
-
font-family: sans-serif;
|
|
282
|
-
font-size: 16px;
|
|
283
|
-
width: 40px;
|
|
284
|
-
height: 36px;
|
|
285
|
-
background-color: white;
|
|
286
|
-
border-radius: 5px;
|
|
287
|
-
border: 0px;
|
|
288
|
-
padding: 1px;
|
|
289
|
-
margin: 2px;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
.Toolbar-button:hover {
|
|
293
|
-
color: white;
|
|
294
|
-
background: #663676;
|
|
295
|
-
cursor: pointer;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
.Toolbar-button:active {
|
|
299
|
-
background: #808080;
|
|
300
|
-
color: white;
|
|
301
|
-
cursor: pointer;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
.TB-narrow {
|
|
305
|
-
width: 30px;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
.TB-wide {
|
|
309
|
-
width: 46px;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
.TB-selected {
|
|
313
|
-
background: #d0d0d0;
|
|
314
|
-
color: black;
|
|
315
|
-
cursor: pointer;
|
|
316
|
-
animation: 0.2s TB-fadeIn;
|
|
317
|
-
animation-fill-mode: forwards;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
.TB-selected:hover {
|
|
321
|
-
color: white;
|
|
322
|
-
background: #663676;
|
|
323
|
-
cursor: pointer;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
@keyframes TB-fadeIn {
|
|
327
|
-
00% {
|
|
328
|
-
background: white;
|
|
329
|
-
}
|
|
330
|
-
100% {
|
|
331
|
-
background: #d0d0d0;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/* Tooltip text */
|
|
336
|
-
.Toolbar-button .tooltiptext {
|
|
337
|
-
font-weight: normal;
|
|
338
|
-
visibility: hidden;
|
|
339
|
-
width: 100px;
|
|
340
|
-
background-color: #222;
|
|
341
|
-
color: #fff;
|
|
342
|
-
/*font-weight: bold;*/
|
|
343
|
-
font-size: 12px;
|
|
344
|
-
text-align: center;
|
|
345
|
-
padding: 4px 10px;
|
|
346
|
-
border-radius: 6px;
|
|
347
|
-
|
|
348
|
-
/* Position the tooltip text - see examples below! */
|
|
349
|
-
position: absolute;
|
|
350
|
-
z-index: 2;
|
|
351
|
-
top: -90%; /* Must leave a small gap between tooltip and button */
|
|
352
|
-
left: 50px;
|
|
353
|
-
|
|
354
|
-
/* transform: translate (50%,0%); */
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/* Show the tooltip text when you mouse over the tooltip container */
|
|
358
|
-
.Toolbar-button:hover .tooltiptext {
|
|
359
|
-
animation: 0.8s fadeIn2;
|
|
360
|
-
animation-fill-mode: forwards;
|
|
361
|
-
visibility: visible;
|
|
362
|
-
/* width: 100px; */
|
|
363
|
-
/* top: -90%; */ /* Must leave a small gap between tooltip and button */
|
|
364
|
-
/* left: 20%; */
|
|
365
|
-
/* margin-left: -50px; */
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
@keyframes fadeIn2 {
|
|
369
|
-
00% {
|
|
370
|
-
opacity: 0;
|
|
371
|
-
}
|
|
372
|
-
70% {
|
|
373
|
-
opacity: 0;
|
|
374
|
-
}
|
|
375
|
-
100% {
|
|
376
|
-
visibility: visible;
|
|
377
|
-
opacity: 0.9;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/* .tooltip {
|
|
382
|
-
position: relative;
|
|
383
|
-
display: inline-block;
|
|
384
|
-
border-bottom: 1px dotted black; /* If you want dots under the hoverable text
|
|
385
|
-
} */
|
|
386
386
|
.EquationEditorModal-background {
|
|
387
387
|
position: fixed;
|
|
388
388
|
top: 0;
|
package/package.json
CHANGED
package/src/mimeTypeHelper.js
CHANGED
|
@@ -1,67 +1,69 @@
|
|
|
1
|
-
const INLINE_LATEX_REG_EXP =
|
|
1
|
+
const INLINE_LATEX_REG_EXP =
|
|
2
|
+
/\$\$[\s\S]+?\$\$|\\\[[\s\S]+?\\\]|\\\([\s\S]+?\\\)|\$[^$\\]*(?:\\.[^$\\]*)*\$/g;
|
|
2
3
|
const BLOCL_LATEX_REG_EXP = /\$\$[\s\S]+?\$\$|\\\[[\s\S]+?\\\]/g;
|
|
3
4
|
|
|
4
|
-
export const MIME_TYPE_PLAIN_TEXT =
|
|
5
|
-
export const MIME_TYPE_HTML =
|
|
6
|
-
export const MIME_TYPE_TEX =
|
|
7
|
-
export const MIME_TYPE_ZZISH_HTML_MATH =
|
|
5
|
+
export const MIME_TYPE_PLAIN_TEXT = 'text/plain';
|
|
6
|
+
export const MIME_TYPE_HTML = 'text/html';
|
|
7
|
+
export const MIME_TYPE_TEX = 'application/x-tex';
|
|
8
|
+
export const MIME_TYPE_ZZISH_HTML_MATH = 'application/x-zzish-html-math';
|
|
8
9
|
|
|
9
|
-
const LATEX_COMMAND_REG_EXP = /\\[a-zA-Z]/g
|
|
10
|
+
const LATEX_COMMAND_REG_EXP = /\\[a-zA-Z]/g;
|
|
10
11
|
|
|
11
|
-
const HTML_CODES_REG_EXP = /&(#36|quot|apos|lt|gt|amp)
|
|
12
|
-
const HTML_TAGS_REG_EXP =
|
|
13
|
-
|
|
12
|
+
const HTML_CODES_REG_EXP = /&(#36|quot|apos|lt|gt|amp);/;
|
|
13
|
+
const HTML_TAGS_REG_EXP =
|
|
14
|
+
/<(br|basefont|hr|input|source|frame|param|area|meta|!--|col|link|option|base|img|wbr|!DOCTYPE).*?>|<(a|abbr|acronym|address|applet|article|aside|audio|b|bdi|bdo|big|blockquote|body|button|canvas|caption|center|cite|code|colgroup|command|datalist|dd|del|details|dfn|dialog|dir|div|dl|dt|em|embed|fieldset|figcaption|figure|font|footer|form|frameset|head|header|hgroup|h1|h2|h3|h4|h5|h6|html|i|iframe|ins|kbd|keygen|label|legend|li|map|mark|menu|meter|nav|noframes|noscript|object|ol|optgroup|output|p|pre|progress|q|rp|rt|ruby|s|samp|script|section|select|small|span|strike|strong|style|sub|summary|sup|table|tbody|td|textarea|tfoot|th|thead|time|title|tr|track|tt|u|ul|var|video).*?<\/\2>/i;
|
|
15
|
+
const HTML_MATH_TAGS_REC_EXP = /<math>/i;
|
|
14
16
|
|
|
15
|
-
const WORDS_REG_EXP = /^[a-zA-Z]*[,."';:?!]*$/i
|
|
17
|
+
const WORDS_REG_EXP = /^[a-zA-Z]*[,."';:?!]*$/i;
|
|
16
18
|
|
|
17
|
-
function stripDollars
|
|
18
|
-
return stringToStrip[0] ===
|
|
19
|
+
function stripDollars(stringToStrip) {
|
|
20
|
+
return stringToStrip[0] === '$' && stringToStrip[1] !== '$'
|
|
19
21
|
? stringToStrip.slice(1, -1)
|
|
20
|
-
: stringToStrip.slice(2, -2)
|
|
22
|
+
: stringToStrip.slice(2, -2);
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export function isTextLatexMath(text) {
|
|
24
26
|
// We need at least two dollar signs to be latex
|
|
25
|
-
let i = text.indexOf(
|
|
26
|
-
if (i < 0)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
i = text.indexOf("$",i+1)
|
|
32
|
-
if (i < 0)
|
|
33
|
-
return false
|
|
27
|
+
let i = text.indexOf('$');
|
|
28
|
+
if (i < 0) return false;
|
|
29
|
+
let j = text.indexOf('\\$');
|
|
30
|
+
if (j >= 0) return true;
|
|
31
|
+
i = text.indexOf('$', i + 1);
|
|
32
|
+
if (i < 0) return false;
|
|
34
33
|
|
|
35
34
|
// Lets try and extract the potentially latex nodes
|
|
36
|
-
let latexMatch = text.match(BLOCL_LATEX_REG_EXP)
|
|
35
|
+
let latexMatch = text.match(BLOCL_LATEX_REG_EXP);
|
|
37
36
|
if (latexMatch === null || latexMatch === undefined)
|
|
38
37
|
latexMatch = text.match(INLINE_LATEX_REG_EXP);
|
|
39
38
|
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
if (
|
|
40
|
+
latexMatch === null ||
|
|
41
|
+
latexMatch === undefined ||
|
|
42
|
+
latexMatch.length === 0
|
|
43
|
+
)
|
|
44
|
+
return false;
|
|
45
|
+
|
|
43
46
|
for (let i = 0; i < latexMatch.length; i++)
|
|
44
|
-
latexMatch[i] = stripDollars(latexMatch[i])
|
|
47
|
+
latexMatch[i] = stripDollars(latexMatch[i]);
|
|
45
48
|
|
|
46
|
-
|
|
47
49
|
// If all dollar signs are followed by a number, it probably is not latex
|
|
48
|
-
i = text.indexOf(
|
|
49
|
-
let probablyLatex = false
|
|
50
|
-
while (i >=0) {
|
|
51
|
-
if (i === text.length-1) {
|
|
52
|
-
probablyLatex = true
|
|
53
|
-
break
|
|
50
|
+
i = text.indexOf('$');
|
|
51
|
+
let probablyLatex = false;
|
|
52
|
+
while (i >= 0) {
|
|
53
|
+
if (i === text.length - 1) {
|
|
54
|
+
probablyLatex = true;
|
|
55
|
+
break;
|
|
54
56
|
}
|
|
55
|
-
let c = text.charAt(i+1)
|
|
56
|
-
if (c <
|
|
57
|
-
probablyLatex = true
|
|
58
|
-
break
|
|
57
|
+
let c = text.charAt(i + 1);
|
|
58
|
+
if (c < '0' || c > '9') {
|
|
59
|
+
probablyLatex = true;
|
|
60
|
+
break;
|
|
59
61
|
}
|
|
60
|
-
i = text.indexOf(
|
|
62
|
+
i = text.indexOf('$', i + 1);
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
// Note that there are other uses of a dollar sign, that couold potentially be
|
|
64
|
-
// entered. For example, if someone created a question about the use of the
|
|
66
|
+
// entered. For example, if someone created a question about the use of the
|
|
65
67
|
// $ sign in excel cells or the use of the $ sign in regular expressions.
|
|
66
68
|
|
|
67
69
|
if (probablyLatex) {
|
|
@@ -79,80 +81,69 @@ export function isTextLatexMath(text) {
|
|
|
79
81
|
// }
|
|
80
82
|
|
|
81
83
|
// If all the latex elements are empty, then we will treat it as plain text
|
|
82
|
-
let allEmpty = true
|
|
84
|
+
let allEmpty = true;
|
|
83
85
|
for (let i = 0; i < latexMatch.length; i++) {
|
|
84
|
-
if (latexMatch[i] !==
|
|
85
|
-
allEmpty = false
|
|
86
|
+
if (latexMatch[i] !== '') allEmpty = false;
|
|
86
87
|
}
|
|
87
|
-
if (allEmpty)
|
|
88
|
-
return false
|
|
88
|
+
if (allEmpty) return false;
|
|
89
89
|
|
|
90
90
|
// If an element between two dollars is two or more words and only words
|
|
91
91
|
// and at least one word has three characters then we will treat it as text
|
|
92
92
|
for (let i = 0; i < latexMatch.length; i++) {
|
|
93
|
-
let words = latexMatch[i].split(
|
|
93
|
+
let words = latexMatch[i].split(' ');
|
|
94
94
|
if (words.length >= 2) {
|
|
95
|
-
let allWords = true
|
|
96
|
-
let longWord = false
|
|
95
|
+
let allWords = true;
|
|
96
|
+
let longWord = false;
|
|
97
97
|
for (let j = 0; j < words.length; j++) {
|
|
98
98
|
// console.log(j+":"+words[j])
|
|
99
|
-
if (words[j].length > 0 &&
|
|
100
|
-
WORDS_REG_EXP.test(words[j]) === false) {
|
|
99
|
+
if (words[j].length > 0 && WORDS_REG_EXP.test(words[j]) === false) {
|
|
101
100
|
// console.log("Not: "+words[j])
|
|
102
|
-
allWords = false
|
|
103
|
-
break
|
|
104
|
-
}
|
|
105
|
-
if (words[j].length >= 3)
|
|
106
|
-
longWord = true
|
|
101
|
+
allWords = false;
|
|
102
|
+
break;
|
|
107
103
|
}
|
|
108
|
-
|
|
109
|
-
|
|
104
|
+
if (words[j].length >= 3) longWord = true;
|
|
105
|
+
}
|
|
106
|
+
if (allWords && longWord) return false;
|
|
110
107
|
}
|
|
111
108
|
}
|
|
112
109
|
|
|
113
|
-
return true
|
|
110
|
+
return true;
|
|
114
111
|
} else {
|
|
115
112
|
// At this point it probably is not latex, but we can check inside the latex
|
|
116
113
|
// elements for things that make it likely to be latex, such as latex commands
|
|
117
114
|
|
|
118
115
|
for (let i = 0; i < latexMatch.length; i++) {
|
|
119
|
-
if (latexMatch[i].match(LATEX_COMMAND_REG_EXP) !== null)
|
|
120
|
-
return true
|
|
116
|
+
if (latexMatch[i].match(LATEX_COMMAND_REG_EXP) !== null) return true;
|
|
121
117
|
}
|
|
122
118
|
|
|
123
|
-
return false
|
|
119
|
+
return false;
|
|
124
120
|
}
|
|
125
121
|
}
|
|
126
122
|
|
|
127
123
|
export function isTextHtml(text) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
let i = text.indexOf(
|
|
131
|
-
if (i < 0)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return containsHtmlTags
|
|
124
|
+
text = text.replace(/[\r\n]+/g, ' ');
|
|
125
|
+
if (HTML_CODES_REG_EXP.test(text)) return true;
|
|
126
|
+
let i = text.indexOf('<');
|
|
127
|
+
if (i < 0) return false;
|
|
128
|
+
|
|
129
|
+
let containsHtmlTags = HTML_TAGS_REG_EXP.test(text);
|
|
130
|
+
return containsHtmlTags;
|
|
136
131
|
}
|
|
137
132
|
|
|
138
133
|
export function isTextHtmlMath(text) {
|
|
139
|
-
let containsMathTags = HTML_MATH_TAGS_REC_EXP.test(text)
|
|
140
|
-
return containsMathTags
|
|
134
|
+
let containsMathTags = HTML_MATH_TAGS_REC_EXP.test(text);
|
|
135
|
+
return containsMathTags;
|
|
141
136
|
}
|
|
142
137
|
|
|
143
138
|
export function determineMimeType(text) {
|
|
144
|
-
if (isTextHtmlMath(text))
|
|
145
|
-
return MIME_TYPE_ZZISH_HTML_MATH
|
|
146
|
-
|
|
147
|
-
if (isTextHtml(text))
|
|
148
|
-
return MIME_TYPE_HTML
|
|
139
|
+
if (isTextHtmlMath(text)) return MIME_TYPE_ZZISH_HTML_MATH;
|
|
149
140
|
|
|
150
|
-
if (
|
|
151
|
-
return MIME_TYPE_TEX
|
|
141
|
+
if (isTextHtml(text)) return MIME_TYPE_HTML;
|
|
152
142
|
|
|
153
|
-
return
|
|
154
|
-
}
|
|
143
|
+
if (isTextLatexMath(text)) return MIME_TYPE_TEX;
|
|
155
144
|
|
|
145
|
+
return MIME_TYPE_PLAIN_TEXT;
|
|
146
|
+
}
|
|
156
147
|
|
|
157
148
|
// test = (text, mimeType) => {
|
|
158
149
|
// let result = determineMimeType(text)
|
|
@@ -201,4 +192,4 @@ export function determineMimeType(text) {
|
|
|
201
192
|
{this.test("$a bcd; e$", "text/plain")}
|
|
202
193
|
{this.test("$a bcd. e$", "text/plain")}
|
|
203
194
|
{this.test("$a bcd> e$", "application/x-tex")}
|
|
204
|
-
*/
|
|
195
|
+
*/
|