1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-06 09:19:22 +02:00

Desktop: Fixes #3791: Add stricter rules for katex blocks (#3795)

This commit is contained in:
Caleb John
2020-09-22 06:16:37 -06:00
committed by GitHub
parent 7202066c1f
commit 48c9b86d2b

View File

@@ -21,7 +21,8 @@ export default function useJoplinMode(CodeMirror: any) {
const inlineKatexOpenRE = /(?<!\S)\$(?=[^\s$].*?[^\\\s$]\$(?!\S))/;
const inlineKatexCloseRE = /(?<![\\\s$])\$(?!\S)/;
const blockKatexRE = /(?<!\\)\$\$/;
const blockKatexOpenRE = /(?<!\S)\$\$/;
const blockKatexCloseRE = /(?<![\\\s])\$\$/;
// Find token will search for a valid katex start or end token
// If found then it will return the index, otherwise -1
@@ -55,19 +56,19 @@ export default function useJoplinMode(CodeMirror: any) {
let nextTokenPos = stream.string.length;
let closing = false;
const blockPos = findToken(stream, blockKatexRE);
if (state.openCharacter) {
currentMode = stex;
currentState = state.inner;
tokenLabel = 'katex-marker-close';
closing = true;
const blockPos = findToken(stream, blockKatexCloseRE);
const inlinePos = findToken(stream, inlineKatexCloseRE);
if (state.openCharacter === '$$' && blockPos !== -1) nextTokenPos = blockPos;
if (state.openCharacter === '$' && inlinePos !== -1) nextTokenPos = inlinePos;
} else {
} else if (!currentState.code) {
const blockPos = findToken(stream, blockKatexOpenRE);
const inlinePos = findToken(stream, inlineKatexOpenRE);
if (blockPos !== -1) nextTokenPos = blockPos;