support multi-line and escaped $

This commit is contained in:
Aleks Kissinger 2020-09-21 09:00:24 +01:00
parent 1f24b5b90c
commit 24a1834f9b
2 changed files with 6 additions and 6 deletions

View File

@ -415,12 +415,12 @@ export function bodyToHtml(content: IContent, highlights: string[], opts: IOpts
safeBody = sanitizeHtml(formattedBody, sanitizeParams);
if (SdkConfig.get()['latex_maths']) {
const mathDelimiters = [
{ left: "<div data-mx-maths=\"", right: "\">.*?</div>", display: true },
{ left: "<span data-mx-maths=\"", right: "\">.*?</span>", display: false }
{ pattern: "<div data-mx-maths=\"([^\"]*)\">(.|\\s)*?</div>", display: true },
{ pattern: "<span data-mx-maths=\"([^\"]*)\">(.|\\s)*?</span>", display: false }
];
mathDelimiters.forEach(function (d) {
var reg = RegExp(d.left + "(.*?)" + d.right, "g");
var reg = RegExp(d.pattern, "gm");
safeBody = safeBody.replace(reg, function(match, p1) {
return katex.renderToString(

View File

@ -44,12 +44,12 @@ export function htmlSerializeIfNeeded(model: EditorModel, {forceHTML = false} =
if (SdkConfig.get()['latex_maths']) {
const mathDelimiters = [ // TODO: make customizable
{ left: "\\$\\$\\$", right: "\\$\\$\\$", display: true },
{ left: "\\$\\$", right: "\\$\\$", display: false }
{ pattern: "\\$\\$\\$(([^$]|\\\\\\$)*)\\$\\$\\$", display: true },
{ pattern: "\\$\\$(([^$]|\\\\\\$)*)\\$\\$", display: false }
];
mathDelimiters.forEach(function (d) {
var reg = RegExp(d.left + "(.*?)" + d.right, "g");
var reg = RegExp(d.pattern, "gm");
md = md.replace(reg, function(match, p1) {
const p1e = AllHtmlEntities.encode(p1);
if (d.display == true) {