diff options
-rw-r--r-- | app/assets/javascripts/notebook/cells/markdown.vue | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/app/assets/javascripts/notebook/cells/markdown.vue b/app/assets/javascripts/notebook/cells/markdown.vue index 3e8240d10ec..53761c16de3 100644 --- a/app/assets/javascripts/notebook/cells/markdown.vue +++ b/app/assets/javascripts/notebook/cells/markdown.vue @@ -30,7 +30,7 @@ | \\s\\$(?!\\$) ) - (.+?) + ((.|\\n)+?) ( \\s\\\\end{[a-zA-Z]+}$ | @@ -45,15 +45,23 @@ let inline = false; if (typeof katex !== 'undefined') { - const katexString = text.replace(/\\/g, '\\'); - const matches = new RegExp(katexRegexString, 'gi').exec(katexString); + const katexString = text.replace(/&/g, '&') + .replace(/&=&/g, '\\&=\\&') + .replace(/<(\/?)em>/g, ''); + const regex = new RegExp(katexRegexString, 'gi'); + const numberOfMatches = katexString.match(regex); - if (matches && matches.length > 0) { - if (matches[1].trim() === '$' && matches[3].trim() === '$') { + if (numberOfMatches && numberOfMatches.length !== 0) { + if (numberOfMatches.length > 1) { + let matches = regex.exec(katexString); inline = true; - text = `${katexString.replace(matches[0], '')} ${katex.renderToString(matches[2])}`; + while (matches !== null) { + text = `${text.replace(matches[0], katex.renderToString(matches[0].replace(/\$/g, '')))}`; + matches = regex.exec(katexString); + } } else { + const matches = regex.exec(katexString); text = katex.renderToString(matches[2]); } } @@ -79,7 +87,7 @@ }, computed: { markdown() { - return marked(this.cell.source.join('')); + return marked(this.cell.source.join('').replace(/\\/g, '\\\\')); }, }, }; |