mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
markdown-it: support \begin...\end for MathJax
This commit is contained in:
parent
aeb2263be3
commit
bdf4e10c6e
@ -109,7 +109,7 @@ mdit = mdit.use(window.markdownitFootnote);
|
|||||||
mdit = mdit.use(window["markdown-it-imsize.js"]);
|
mdit = mdit.use(window["markdown-it-imsize.js"]);
|
||||||
|
|
||||||
if (typeof texmath != 'undefined') {
|
if (typeof texmath != 'undefined') {
|
||||||
mdit = mdit.use(texmath, { delimiters: 'dollars' });
|
mdit = mdit.use(texmath, { delimiters: ['dollars', 'raw'] });
|
||||||
}
|
}
|
||||||
|
|
||||||
var mdHasTocSection = function(markdown) {
|
var mdHasTocSection = function(markdown) {
|
||||||
|
@ -8,21 +8,27 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function texmath(md, options) {
|
function texmath(md, options) {
|
||||||
let delimiters = options && options.delimiters || 'dollars';
|
let delimiters = ['dollars'];
|
||||||
|
if (options && options.delimiters) {
|
||||||
|
delimiters = options.delimiters;
|
||||||
|
}
|
||||||
|
|
||||||
if (delimiters in texmath.rules) {
|
for (let i = 0; i < delimiters.length; ++i) {
|
||||||
for (let rule of texmath.rules[delimiters].inline) {
|
let deli = delimiters[i];
|
||||||
|
if (deli in texmath.rules) {
|
||||||
|
for (let rule of texmath.rules[deli].inline) {
|
||||||
md.inline.ruler.before('escape', rule.name, texmath.inline(rule)); // ! important
|
md.inline.ruler.before('escape', rule.name, texmath.inline(rule)); // ! important
|
||||||
md.renderer.rules[rule.name] = (tokens, idx) => rule.tmpl.replace(/\$1/,texmath.render(tokens[idx].content,false));
|
md.renderer.rules[rule.name] = (tokens, idx) => rule.tmpl.replace(/\$1/,texmath.render(tokens[idx].content,false));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let rule of texmath.rules[delimiters].block) {
|
for (let rule of texmath.rules[deli].block) {
|
||||||
md.block.ruler.before('fence', rule.name, texmath.block(rule));
|
md.block.ruler.before('fence', rule.name, texmath.block(rule));
|
||||||
md.renderer.rules[rule.name] = (tokens, idx) => rule.tmpl.replace(/\$2/,tokens[idx].info) // equation number
|
md.renderer.rules[rule.name] = (tokens, idx) => rule.tmpl.replace(/\$2/,tokens[idx].info) // equation number
|
||||||
.replace(/\$1/,texmath.render(tokens[idx].content,true));
|
.replace(/\$1/,texmath.render(tokens[idx].content,true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
texmath.applyRule = function(rule, str, beg) {
|
texmath.applyRule = function(rule, str, beg) {
|
||||||
let pre, match, post;
|
let pre, match, post;
|
||||||
@ -166,6 +172,17 @@ texmath.rules = {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
raw: {
|
||||||
|
inline: [],
|
||||||
|
block: [
|
||||||
|
{
|
||||||
|
name: 'math_block',
|
||||||
|
rex: /(\\begin\s*\{([^{}\s\r\n]+)\}(?:[^\\]|\\(?!end\s*\{\2\}))*\\end\s*\{\2\})\s*$/gmy,
|
||||||
|
tmpl: '<x-eqn class="tex-to-render">$1</x-eqn>',
|
||||||
|
tag: '\\begin'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof module === "object" && module.exports)
|
if (typeof module === "object" && module.exports)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user