@waline/vercel 1.31.3 → 1.31.4
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/__tests__/__snapshots__/mathjax.spec.js.snap +16 -0
- package/__tests__/__snapshots__/xss.spec.js.snap +1 -1
- package/__tests__/katex.spec.js +17 -17
- package/__tests__/mathjax.spec.js +31 -35
- package/__tests__/xss.spec.js +17 -17
- package/package.json +11 -11
- package/src/config/netlify.js +1 -1
- package/src/controller/article.js +4 -3
- package/src/controller/comment.js +35 -33
- package/src/controller/db.js +3 -3
- package/src/controller/oauth.js +4 -4
- package/src/controller/token/2fa.js +1 -1
- package/src/controller/user/password.js +1 -1
- package/src/controller/user.js +8 -8
- package/src/extend/think.js +2 -2
- package/src/logic/base.js +5 -5
- package/src/middleware/prefix-warning.js +1 -1
- package/src/service/akismet.js +1 -1
- package/src/service/markdown/katex.js +7 -7
- package/src/service/markdown/mathCommon.js +6 -6
- package/src/service/markdown/mathjax.js +7 -7
- package/src/service/markdown/xss.js +2 -2
- package/src/service/notify.js +12 -10
- package/src/service/storage/base.js +3 -1
- package/src/service/storage/cloudbase.js +1 -1
- package/src/service/storage/deta.js +5 -5
- package/src/service/storage/github.js +5 -5
- package/src/service/storage/leancloud.js +8 -6
- package/src/service/storage/mongodb.js +1 -1
- package/src/service/storage/mysql.js +2 -2
- package/src/service/storage/postgresql.js +1 -1
- package/src/service/storage/sqlite.js +1 -1
|
@@ -8,7 +8,7 @@ async function formatCmt(
|
|
|
8
8
|
{ ua, ip, ...comment },
|
|
9
9
|
users = [],
|
|
10
10
|
{ avatarProxy, deprecated },
|
|
11
|
-
loginUser
|
|
11
|
+
loginUser,
|
|
12
12
|
) {
|
|
13
13
|
ua = think.uaParser(ua);
|
|
14
14
|
if (!think.config('disableUserAgent')) {
|
|
@@ -146,7 +146,7 @@ module.exports = class extends BaseRest {
|
|
|
146
146
|
|
|
147
147
|
if (!think.isEmpty(duplicate)) {
|
|
148
148
|
think.logger.debug(
|
|
149
|
-
'The comment author had post same comment content before'
|
|
149
|
+
'The comment author had post same comment content before',
|
|
150
150
|
);
|
|
151
151
|
|
|
152
152
|
return this.fail(this.locale('Duplicate Content'));
|
|
@@ -177,7 +177,7 @@ module.exports = class extends BaseRest {
|
|
|
177
177
|
|
|
178
178
|
if (data.status === 'approved') {
|
|
179
179
|
const spam = await akismet(data, this.ctx.serverURL).catch((e) =>
|
|
180
|
-
console.log(e)
|
|
180
|
+
console.log(e),
|
|
181
181
|
); // ignore akismet error
|
|
182
182
|
|
|
183
183
|
if (spam === true) {
|
|
@@ -240,14 +240,14 @@ module.exports = class extends BaseRest {
|
|
|
240
240
|
resp,
|
|
241
241
|
[userInfo],
|
|
242
242
|
{ ...this.config(), deprecated: this.ctx.state.deprecated },
|
|
243
|
-
userInfo
|
|
243
|
+
userInfo,
|
|
244
244
|
);
|
|
245
245
|
const parentReturn = parentComment
|
|
246
246
|
? await formatCmt(
|
|
247
247
|
parentComment,
|
|
248
248
|
parentUser ? [parentUser] : [],
|
|
249
249
|
{ ...this.config(), deprecated: this.ctx.state.deprecated },
|
|
250
|
-
userInfo
|
|
250
|
+
userInfo,
|
|
251
251
|
)
|
|
252
252
|
: undefined;
|
|
253
253
|
|
|
@@ -256,7 +256,9 @@ module.exports = class extends BaseRest {
|
|
|
256
256
|
|
|
257
257
|
await notify.run(
|
|
258
258
|
{ ...cmtReturn, mail: resp.mail, rawComment: comment },
|
|
259
|
-
parentReturn
|
|
259
|
+
parentReturn
|
|
260
|
+
? { ...parentReturn, mail: parentComment.mail }
|
|
261
|
+
: undefined,
|
|
260
262
|
);
|
|
261
263
|
}
|
|
262
264
|
|
|
@@ -271,8 +273,8 @@ module.exports = class extends BaseRest {
|
|
|
271
273
|
resp,
|
|
272
274
|
[userInfo],
|
|
273
275
|
{ ...this.config(), deprecated: this.ctx.state.deprecated },
|
|
274
|
-
userInfo
|
|
275
|
-
)
|
|
276
|
+
userInfo,
|
|
277
|
+
),
|
|
276
278
|
);
|
|
277
279
|
}
|
|
278
280
|
|
|
@@ -321,7 +323,7 @@ module.exports = class extends BaseRest {
|
|
|
321
323
|
newData[0],
|
|
322
324
|
cmtUser ? [cmtUser] : [],
|
|
323
325
|
{ ...this.config(), deprecated: this.ctx.state.deprecated },
|
|
324
|
-
userInfo
|
|
326
|
+
userInfo,
|
|
325
327
|
);
|
|
326
328
|
|
|
327
329
|
if (
|
|
@@ -349,13 +351,13 @@ module.exports = class extends BaseRest {
|
|
|
349
351
|
pComment,
|
|
350
352
|
pUser ? [pUser] : [],
|
|
351
353
|
{ ...this.config(), deprecated: this.ctx.state.deprecated },
|
|
352
|
-
userInfo
|
|
354
|
+
userInfo,
|
|
353
355
|
);
|
|
354
356
|
|
|
355
357
|
await notify.run(
|
|
356
358
|
{ ...cmtReturn, mail: newData[0].mail },
|
|
357
359
|
{ ...pcmtReturn, mail: pComment.mail },
|
|
358
|
-
true
|
|
360
|
+
true,
|
|
359
361
|
);
|
|
360
362
|
}
|
|
361
363
|
|
|
@@ -462,12 +464,12 @@ module.exports = class extends BaseRest {
|
|
|
462
464
|
rootIds[objectId] = true;
|
|
463
465
|
});
|
|
464
466
|
comments = comments.filter(
|
|
465
|
-
(cmt) => rootIds[cmt.objectId] || rootIds[cmt.rid]
|
|
467
|
+
(cmt) => rootIds[cmt.objectId] || rootIds[cmt.rid],
|
|
466
468
|
);
|
|
467
469
|
} else {
|
|
468
470
|
comments = await this.modelInstance.select(
|
|
469
471
|
{ ...where, rid: undefined },
|
|
470
|
-
{ ...selectOptions }
|
|
472
|
+
{ ...selectOptions },
|
|
471
473
|
);
|
|
472
474
|
rootCount = comments.length;
|
|
473
475
|
rootComments = [
|
|
@@ -480,7 +482,7 @@ module.exports = class extends BaseRest {
|
|
|
480
482
|
...where,
|
|
481
483
|
rid: ['IN', rootComments.map(({ objectId }) => objectId)],
|
|
482
484
|
},
|
|
483
|
-
selectOptions
|
|
485
|
+
selectOptions,
|
|
484
486
|
);
|
|
485
487
|
|
|
486
488
|
comments = [...rootComments, ...children];
|
|
@@ -488,7 +490,7 @@ module.exports = class extends BaseRest {
|
|
|
488
490
|
|
|
489
491
|
const userModel = this.getModel('Users');
|
|
490
492
|
const user_ids = Array.from(
|
|
491
|
-
new Set(comments.map(({ user_id }) => user_id).filter((v) => v))
|
|
493
|
+
new Set(comments.map(({ user_id }) => user_id).filter((v) => v)),
|
|
492
494
|
);
|
|
493
495
|
let users = [];
|
|
494
496
|
|
|
@@ -497,7 +499,7 @@ module.exports = class extends BaseRest {
|
|
|
497
499
|
{ objectId: ['IN', user_ids] },
|
|
498
500
|
{
|
|
499
501
|
field: ['display_name', 'email', 'url', 'type', 'avatar', 'label'],
|
|
500
|
-
}
|
|
502
|
+
},
|
|
501
503
|
);
|
|
502
504
|
}
|
|
503
505
|
|
|
@@ -511,7 +513,7 @@ module.exports = class extends BaseRest {
|
|
|
511
513
|
countWhere._complex.user_id = ['IN', user_ids];
|
|
512
514
|
}
|
|
513
515
|
const mails = Array.from(
|
|
514
|
-
new Set(comments.map(({ mail }) => mail).filter((v) => v))
|
|
516
|
+
new Set(comments.map(({ mail }) => mail).filter((v) => v)),
|
|
515
517
|
);
|
|
516
518
|
|
|
517
519
|
if (mails.length) {
|
|
@@ -528,7 +530,7 @@ module.exports = class extends BaseRest {
|
|
|
528
530
|
|
|
529
531
|
comments.forEach((cmt) => {
|
|
530
532
|
const countItem = (counts || []).find(({ mail, user_id }) =>
|
|
531
|
-
cmt.user_id ? user_id === cmt.user_id : mail === cmt.mail
|
|
533
|
+
cmt.user_id ? user_id === cmt.user_id : mail === cmt.mail,
|
|
532
534
|
);
|
|
533
535
|
|
|
534
536
|
cmt.level = think.getLevel(countItem?.count);
|
|
@@ -546,7 +548,7 @@ module.exports = class extends BaseRest {
|
|
|
546
548
|
comment,
|
|
547
549
|
users,
|
|
548
550
|
{ ...this.config(), deprecated: this.ctx.state.deprecated },
|
|
549
|
-
userInfo
|
|
551
|
+
userInfo,
|
|
550
552
|
);
|
|
551
553
|
|
|
552
554
|
cmt.children = await Promise.all(
|
|
@@ -560,14 +562,14 @@ module.exports = class extends BaseRest {
|
|
|
560
562
|
...this.config(),
|
|
561
563
|
deprecated: this.ctx.state.deprecated,
|
|
562
564
|
},
|
|
563
|
-
userInfo
|
|
564
|
-
)
|
|
565
|
+
userInfo,
|
|
566
|
+
),
|
|
565
567
|
)
|
|
566
|
-
.reverse()
|
|
568
|
+
.reverse(),
|
|
567
569
|
);
|
|
568
570
|
|
|
569
571
|
return cmt;
|
|
570
|
-
})
|
|
572
|
+
}),
|
|
571
573
|
),
|
|
572
574
|
};
|
|
573
575
|
}
|
|
@@ -609,7 +611,7 @@ module.exports = class extends BaseRest {
|
|
|
609
611
|
|
|
610
612
|
const userModel = this.getModel('Users');
|
|
611
613
|
const user_ids = Array.from(
|
|
612
|
-
new Set(comments.map(({ user_id }) => user_id).filter((v) => v))
|
|
614
|
+
new Set(comments.map(({ user_id }) => user_id).filter((v) => v)),
|
|
613
615
|
);
|
|
614
616
|
|
|
615
617
|
let users = [];
|
|
@@ -619,7 +621,7 @@ module.exports = class extends BaseRest {
|
|
|
619
621
|
{ objectId: ['IN', user_ids] },
|
|
620
622
|
{
|
|
621
623
|
field: ['display_name', 'email', 'url', 'type', 'avatar', 'label'],
|
|
622
|
-
}
|
|
624
|
+
},
|
|
623
625
|
);
|
|
624
626
|
}
|
|
625
627
|
|
|
@@ -635,9 +637,9 @@ module.exports = class extends BaseRest {
|
|
|
635
637
|
cmt,
|
|
636
638
|
users,
|
|
637
639
|
{ ...this.config(), deprecated: this.ctx.state.deprecated },
|
|
638
|
-
userInfo
|
|
639
|
-
)
|
|
640
|
-
)
|
|
640
|
+
userInfo,
|
|
641
|
+
),
|
|
642
|
+
),
|
|
641
643
|
),
|
|
642
644
|
};
|
|
643
645
|
}
|
|
@@ -680,7 +682,7 @@ module.exports = class extends BaseRest {
|
|
|
680
682
|
|
|
681
683
|
const userModel = this.getModel('Users');
|
|
682
684
|
const user_ids = Array.from(
|
|
683
|
-
new Set(comments.map(({ user_id }) => user_id).filter((v) => v))
|
|
685
|
+
new Set(comments.map(({ user_id }) => user_id).filter((v) => v)),
|
|
684
686
|
);
|
|
685
687
|
|
|
686
688
|
let users = [];
|
|
@@ -690,7 +692,7 @@ module.exports = class extends BaseRest {
|
|
|
690
692
|
{ objectId: ['IN', user_ids] },
|
|
691
693
|
{
|
|
692
694
|
field: ['display_name', 'email', 'url', 'type', 'avatar', 'label'],
|
|
693
|
-
}
|
|
695
|
+
},
|
|
694
696
|
);
|
|
695
697
|
}
|
|
696
698
|
|
|
@@ -700,9 +702,9 @@ module.exports = class extends BaseRest {
|
|
|
700
702
|
cmt,
|
|
701
703
|
users,
|
|
702
704
|
{ ...this.config(), deprecated: this.ctx.state.deprecated },
|
|
703
|
-
userInfo
|
|
704
|
-
)
|
|
705
|
-
)
|
|
705
|
+
userInfo,
|
|
706
|
+
),
|
|
707
|
+
),
|
|
706
708
|
);
|
|
707
709
|
}
|
|
708
710
|
|
package/src/controller/db.js
CHANGED
|
@@ -42,17 +42,17 @@ module.exports = class extends BaseRest {
|
|
|
42
42
|
item.insertedAt &&
|
|
43
43
|
(item.insertedAt = think.datetime(
|
|
44
44
|
item.insertedAt,
|
|
45
|
-
'YYYY-MM-DD HH:mm:ss'
|
|
45
|
+
'YYYY-MM-DD HH:mm:ss',
|
|
46
46
|
));
|
|
47
47
|
item.createdAt &&
|
|
48
48
|
(item.createdAt = think.datetime(
|
|
49
49
|
item.createdAt,
|
|
50
|
-
'YYYY-MM-DD HH:mm:ss'
|
|
50
|
+
'YYYY-MM-DD HH:mm:ss',
|
|
51
51
|
));
|
|
52
52
|
item.updatedAt &&
|
|
53
53
|
(item.updatedAt = think.datetime(
|
|
54
54
|
item.updatedAt,
|
|
55
|
-
'YYYY-MM-DD HH:mm:ss'
|
|
55
|
+
'YYYY-MM-DD HH:mm:ss',
|
|
56
56
|
));
|
|
57
57
|
}
|
|
58
58
|
|
package/src/controller/oauth.js
CHANGED
|
@@ -25,7 +25,7 @@ module.exports = class extends think.Controller {
|
|
|
25
25
|
`${oauthUrl}/${type}?${new URLSearchParams({
|
|
26
26
|
redirect: redirectUrl,
|
|
27
27
|
state: this.ctx.state.token || '',
|
|
28
|
-
}).toString()}
|
|
28
|
+
}).toString()}`,
|
|
29
29
|
);
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -54,7 +54,7 @@ module.exports = class extends think.Controller {
|
|
|
54
54
|
headers: {
|
|
55
55
|
'user-agent': '@waline',
|
|
56
56
|
},
|
|
57
|
-
}
|
|
57
|
+
},
|
|
58
58
|
).then((resp) => resp.json());
|
|
59
59
|
|
|
60
60
|
if (!user || !user.id) {
|
|
@@ -68,7 +68,7 @@ module.exports = class extends think.Controller {
|
|
|
68
68
|
|
|
69
69
|
if (redirect) {
|
|
70
70
|
return this.redirect(
|
|
71
|
-
redirect + (redirect.includes('?') ? '&' : '?') + 'token=' + token
|
|
71
|
+
redirect + (redirect.includes('?') ? '&' : '?') + 'token=' + token,
|
|
72
72
|
);
|
|
73
73
|
}
|
|
74
74
|
|
|
@@ -123,7 +123,7 @@ module.exports = class extends think.Controller {
|
|
|
123
123
|
|
|
124
124
|
if (redirect) {
|
|
125
125
|
return this.redirect(
|
|
126
|
-
redirect + (redirect.includes('?') ? '&' : '?') + 'token=' + token
|
|
126
|
+
redirect + (redirect.includes('?') ? '&' : '?') + 'token=' + token,
|
|
127
127
|
);
|
|
128
128
|
}
|
|
129
129
|
|
package/src/controller/user.js
CHANGED
|
@@ -33,7 +33,7 @@ module.exports = class extends BaseRest {
|
|
|
33
33
|
desc: 'createdAt',
|
|
34
34
|
limit: pageSize,
|
|
35
35
|
offset: Math.max((page - 1) * pageSize, 0),
|
|
36
|
-
}
|
|
36
|
+
},
|
|
37
37
|
);
|
|
38
38
|
|
|
39
39
|
return this.success({
|
|
@@ -70,7 +70,7 @@ module.exports = class extends BaseRest {
|
|
|
70
70
|
const hasMailService = SMTP_HOST || SMTP_SERVICE;
|
|
71
71
|
|
|
72
72
|
const token = Array.from({ length: 4 }, () =>
|
|
73
|
-
Math.round(Math.random() * 9)
|
|
73
|
+
Math.round(Math.random() * 9),
|
|
74
74
|
).join('');
|
|
75
75
|
const normalType = hasMailService
|
|
76
76
|
? `verify:${token}:${Date.now() + 1 * 60 * 60 * 1000}`
|
|
@@ -107,7 +107,7 @@ module.exports = class extends BaseRest {
|
|
|
107
107
|
}),
|
|
108
108
|
html: this.locale(
|
|
109
109
|
'Please click <a href="{{url}}">{{url}}<a/> to confirm registration, the link is valid for 1 hour. If you are not registering, please ignore this email.',
|
|
110
|
-
{ url: apiUrl }
|
|
110
|
+
{ url: apiUrl },
|
|
111
111
|
),
|
|
112
112
|
});
|
|
113
113
|
} catch (e) {
|
|
@@ -116,8 +116,8 @@ module.exports = class extends BaseRest {
|
|
|
116
116
|
return this.fail(
|
|
117
117
|
this.locale(
|
|
118
118
|
'Registration confirm mail send failed, please {%- if isAdmin -%}check your mail configuration{%- else -%}check your email address and contact administrator{%- endif -%}.',
|
|
119
|
-
{ isAdmin: think.isEmpty(count) }
|
|
120
|
-
)
|
|
119
|
+
{ isAdmin: think.isEmpty(count) },
|
|
120
|
+
),
|
|
121
121
|
);
|
|
122
122
|
}
|
|
123
123
|
|
|
@@ -189,7 +189,7 @@ module.exports = class extends BaseRest {
|
|
|
189
189
|
},
|
|
190
190
|
{
|
|
191
191
|
group: ['user_id', 'mail'],
|
|
192
|
-
}
|
|
192
|
+
},
|
|
193
193
|
);
|
|
194
194
|
|
|
195
195
|
counts.sort((a, b) => b.count - a.count);
|
|
@@ -226,7 +226,7 @@ module.exports = class extends BaseRest {
|
|
|
226
226
|
if (user.count) {
|
|
227
227
|
const _level = think.findLastIndex(
|
|
228
228
|
this.config('levels'),
|
|
229
|
-
(l) => l <= user.count
|
|
229
|
+
(l) => l <= user.count,
|
|
230
230
|
);
|
|
231
231
|
|
|
232
232
|
if (_level !== -1) {
|
|
@@ -255,7 +255,7 @@ module.exports = class extends BaseRest {
|
|
|
255
255
|
|
|
256
256
|
const comments = await commentModel.select(
|
|
257
257
|
{ mail: count.mail },
|
|
258
|
-
{ limit: 1 }
|
|
258
|
+
{ limit: 1 },
|
|
259
259
|
);
|
|
260
260
|
|
|
261
261
|
if (think.isEmpty(comments)) {
|
package/src/extend/think.js
CHANGED
|
@@ -79,7 +79,7 @@ module.exports = {
|
|
|
79
79
|
const { region } = result;
|
|
80
80
|
const [, , province, city, isp] = region.split('|');
|
|
81
81
|
const address = Array.from(
|
|
82
|
-
new Set([province, city, isp].filter((v) => v))
|
|
82
|
+
new Set([province, city, isp].filter((v) => v)),
|
|
83
83
|
);
|
|
84
84
|
|
|
85
85
|
return address.slice(0, depth).join(' ');
|
|
@@ -155,7 +155,7 @@ module.exports = {
|
|
|
155
155
|
getPluginHook(hookName) {
|
|
156
156
|
return think
|
|
157
157
|
.pluginMap('hooks', (hook) =>
|
|
158
|
-
think.isFunction(hook[hookName]) ? hook[hookName] : undefined
|
|
158
|
+
think.isFunction(hook[hookName]) ? hook[hookName] : undefined,
|
|
159
159
|
)
|
|
160
160
|
.filter((v) => v);
|
|
161
161
|
},
|
package/src/logic/base.js
CHANGED
|
@@ -28,13 +28,13 @@ module.exports = class extends think.Logic {
|
|
|
28
28
|
'api.twitter.com',
|
|
29
29
|
'www.facebook.com',
|
|
30
30
|
'api.weibo.com',
|
|
31
|
-
'graph.qq.com'
|
|
31
|
+
'graph.qq.com',
|
|
32
32
|
);
|
|
33
33
|
|
|
34
34
|
const match = secureDomains.some((domain) =>
|
|
35
35
|
think.isFunction(domain.test)
|
|
36
36
|
? domain.test(referrer)
|
|
37
|
-
: domain === referrer
|
|
37
|
+
: domain === referrer,
|
|
38
38
|
);
|
|
39
39
|
|
|
40
40
|
if (!match) {
|
|
@@ -81,7 +81,7 @@ module.exports = class extends think.Logic {
|
|
|
81
81
|
'2fa',
|
|
82
82
|
'label',
|
|
83
83
|
],
|
|
84
|
-
}
|
|
84
|
+
},
|
|
85
85
|
);
|
|
86
86
|
|
|
87
87
|
if (think.isEmpty(user)) {
|
|
@@ -183,13 +183,13 @@ module.exports = class extends think.Logic {
|
|
|
183
183
|
};
|
|
184
184
|
|
|
185
185
|
const response = await fetch(requestUrl, options).then((resp) =>
|
|
186
|
-
resp.json()
|
|
186
|
+
resp.json(),
|
|
187
187
|
);
|
|
188
188
|
|
|
189
189
|
if (!response.success) {
|
|
190
190
|
think.logger.debug(
|
|
191
191
|
'RecaptchaV3 or Turnstile Result:',
|
|
192
|
-
JSON.stringify(response, null, '\t')
|
|
192
|
+
JSON.stringify(response, null, '\t'),
|
|
193
193
|
);
|
|
194
194
|
|
|
195
195
|
return this.ctx.throw(403);
|
|
@@ -20,7 +20,7 @@ module.exports = () => async (ctx, next) => {
|
|
|
20
20
|
|
|
21
21
|
if (ctx.state.deprecated) {
|
|
22
22
|
think.logger.warn(
|
|
23
|
-
`[Deprecated] ${ctx.path} API will be deprecated in the next major version, please don't use it anymore. If you are using \`@waline/client\` please upgrade to \`@waline/client@3\`. For other scenarios, you can use \`/api${ctx.path}\` to replace it
|
|
23
|
+
`[Deprecated] ${ctx.path} API will be deprecated in the next major version, please don't use it anymore. If you are using \`@waline/client\` please upgrade to \`@waline/client@3\`. For other scenarios, you can use \`/api${ctx.path}\` to replace it.`,
|
|
24
24
|
);
|
|
25
25
|
}
|
|
26
26
|
|
package/src/service/akismet.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const katex = require('katex');
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { inlineTeX, blockTeX } = require('./mathCommon');
|
|
4
4
|
const { escapeHtml } = require('./utils');
|
|
5
5
|
|
|
6
6
|
// set KaTeX as the renderer for markdown-it-simplemath
|
|
@@ -12,7 +12,7 @@ const katexInline = (tex, options) => {
|
|
|
12
12
|
if (options.throwOnError) console.warn(error);
|
|
13
13
|
|
|
14
14
|
return `<span class='katex-error' title='${escapeHtml(
|
|
15
|
-
error.toString()
|
|
15
|
+
error.toString(),
|
|
16
16
|
)}'>${escapeHtml(tex)}</span>`;
|
|
17
17
|
}
|
|
18
18
|
};
|
|
@@ -25,23 +25,23 @@ const katexBlock = (tex, options) => {
|
|
|
25
25
|
if (options.throwOnError) console.warn(error);
|
|
26
26
|
|
|
27
27
|
return `<p class='katex-block katex-error' title='${escapeHtml(
|
|
28
|
-
error.toString()
|
|
28
|
+
error.toString(),
|
|
29
29
|
)}'>${escapeHtml(tex)}</p>`;
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
const katexPlugin = (md, options = { throwOnError: false }) => {
|
|
34
|
-
md.inline.ruler.after('escape', '
|
|
34
|
+
md.inline.ruler.after('escape', 'inlineTeX', inlineTeX);
|
|
35
35
|
|
|
36
36
|
// It’s a workaround here because types issue
|
|
37
|
-
md.block.ruler.after('blockquote', '
|
|
37
|
+
md.block.ruler.after('blockquote', 'blockTeX', blockTeX, {
|
|
38
38
|
alt: ['paragraph', 'reference', 'blockquote', 'list'],
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
md.renderer.rules.
|
|
41
|
+
md.renderer.rules.inlineTeX = (tokens, idx) =>
|
|
42
42
|
katexInline(tokens[idx].content, options);
|
|
43
43
|
|
|
44
|
-
md.renderer.rules.
|
|
44
|
+
md.renderer.rules.blockTeX = (tokens, idx) =>
|
|
45
45
|
`${katexBlock(tokens[idx].content, options)}\n`;
|
|
46
46
|
};
|
|
47
47
|
|
|
@@ -20,7 +20,7 @@ const isValidDelim = (state, pos) => {
|
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
const
|
|
23
|
+
const inlineTeX = (state, silent) => {
|
|
24
24
|
let match;
|
|
25
25
|
let pos;
|
|
26
26
|
let res;
|
|
@@ -83,7 +83,7 @@ const inlineTex = (state, silent) => {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
if (!silent) {
|
|
86
|
-
token = state.push('
|
|
86
|
+
token = state.push('inlineTeX', 'math', 0);
|
|
87
87
|
token.markup = '$';
|
|
88
88
|
token.content = state.src.slice(start, match);
|
|
89
89
|
}
|
|
@@ -93,7 +93,7 @@ const inlineTex = (state, silent) => {
|
|
|
93
93
|
return true;
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
-
const
|
|
96
|
+
const blockTeX = (state, start, end, silent) => {
|
|
97
97
|
let firstLine;
|
|
98
98
|
let lastLine;
|
|
99
99
|
let next;
|
|
@@ -133,7 +133,7 @@ const blockTex = (state, start, end, silent) => {
|
|
|
133
133
|
|
|
134
134
|
state.line = next + 1;
|
|
135
135
|
|
|
136
|
-
const token = state.push('
|
|
136
|
+
const token = state.push('blockTeX', 'math', 0);
|
|
137
137
|
|
|
138
138
|
token.block = true;
|
|
139
139
|
token.content =
|
|
@@ -151,6 +151,6 @@ const blockTex = (state, start, end, silent) => {
|
|
|
151
151
|
};
|
|
152
152
|
|
|
153
153
|
module.exports = {
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
inlineTeX,
|
|
155
|
+
blockTeX,
|
|
156
156
|
};
|
|
@@ -5,7 +5,7 @@ const { TeX } = require('mathjax-full/js/input/tex.js');
|
|
|
5
5
|
const { mathjax } = require('mathjax-full/js/mathjax');
|
|
6
6
|
const { SVG } = require('mathjax-full/js/output/svg.js');
|
|
7
7
|
|
|
8
|
-
const {
|
|
8
|
+
const { inlineTeX, blockTeX } = require('./mathCommon');
|
|
9
9
|
const { escapeHtml } = require('./utils');
|
|
10
10
|
|
|
11
11
|
// set MathJax as the renderer
|
|
@@ -30,7 +30,7 @@ class MathToSvg {
|
|
|
30
30
|
const errorTitle = svg.match(/<title>(.*?)<\/title>/)[1];
|
|
31
31
|
|
|
32
32
|
svg = `<span class='mathjax-error' title='${escapeHtml(
|
|
33
|
-
errorTitle
|
|
33
|
+
errorTitle,
|
|
34
34
|
)}'>${escapeHtml(tex)}</span>`;
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -45,7 +45,7 @@ class MathToSvg {
|
|
|
45
45
|
const errorTitle = svg.match(/<title>(.*?)<\/title>/)[1];
|
|
46
46
|
|
|
47
47
|
svg = `<p class='mathjax-block mathjax-error' title='${escapeHtml(
|
|
48
|
-
errorTitle
|
|
48
|
+
errorTitle,
|
|
49
49
|
)}'>${escapeHtml(tex)}</p>`;
|
|
50
50
|
} else {
|
|
51
51
|
svg = svg.replace(/(width=".*?")/, 'width="100%"');
|
|
@@ -59,17 +59,17 @@ class MathToSvg {
|
|
|
59
59
|
const mathjaxPlugin = (md) => {
|
|
60
60
|
const mathToSvg = new MathToSvg();
|
|
61
61
|
|
|
62
|
-
md.inline.ruler.after('escape', '
|
|
62
|
+
md.inline.ruler.after('escape', 'inlineTeX', inlineTeX);
|
|
63
63
|
|
|
64
64
|
// It’s a workaround here because types issue
|
|
65
|
-
md.block.ruler.after('blockquote', '
|
|
65
|
+
md.block.ruler.after('blockquote', 'blockTeX', blockTeX, {
|
|
66
66
|
alt: ['paragraph', 'reference', 'blockquote', 'list'],
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
md.renderer.rules.
|
|
69
|
+
md.renderer.rules.inlineTeX = (tokens, idx) =>
|
|
70
70
|
mathToSvg.inline(tokens[idx].content);
|
|
71
71
|
|
|
72
|
-
md.renderer.rules.
|
|
72
|
+
md.renderer.rules.blockTeX = (tokens, idx) =>
|
|
73
73
|
`${mathToSvg.block(tokens[idx].content)}\n`;
|
|
74
74
|
};
|
|
75
75
|
|