feat: 添加 \\(...\\) 内联数学公式支持

This commit is contained in:
ViperEkura 2026-05-07 22:33:14 +08:00
parent f7b48027ce
commit 97355cefad
1 changed files with 20 additions and 0 deletions

View File

@ -121,6 +121,25 @@ const blockMathExtension = {
}, },
}; };
// marked extension for inline math \(...\)
const bracketInlineMathExtension = {
name: 'bracketInlineMath',
level: 'inline',
start(src) {
const idx = src.indexOf('\\(');
return idx === -1 ? undefined : idx;
},
tokenizer(src) {
const match = src.match(/^\\\((.+?)\\\)/);
if (match) {
return { type: 'bracketInlineMath', raw: match[0], text: match[1].trim() };
}
},
renderer(token) {
return renderMath(token.text, false);
},
};
// marked extension for \[...\] block math // marked extension for \[...\] block math
const bracketMathExtension = { const bracketMathExtension = {
name: 'bracketMath', name: 'bracketMath',
@ -186,6 +205,7 @@ marked.use({
extensions: [ extensions: [
blockMathExtension, blockMathExtension,
bracketMathExtension, bracketMathExtension,
bracketInlineMathExtension,
envMathExtension, envMathExtension,
mathExtension, mathExtension,
], ],