mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-18 14:44:58 +08:00
support multi-line and escaped $
This commit is contained in:
parent
1f24b5b90c
commit
24a1834f9b
@ -415,12 +415,12 @@ export function bodyToHtml(content: IContent, highlights: string[], opts: IOpts
|
|||||||
safeBody = sanitizeHtml(formattedBody, sanitizeParams);
|
safeBody = sanitizeHtml(formattedBody, sanitizeParams);
|
||||||
if (SdkConfig.get()['latex_maths']) {
|
if (SdkConfig.get()['latex_maths']) {
|
||||||
const mathDelimiters = [
|
const mathDelimiters = [
|
||||||
{ left: "<div data-mx-maths=\"", right: "\">.*?</div>", display: true },
|
{ pattern: "<div data-mx-maths=\"([^\"]*)\">(.|\\s)*?</div>", display: true },
|
||||||
{ left: "<span data-mx-maths=\"", right: "\">.*?</span>", display: false }
|
{ pattern: "<span data-mx-maths=\"([^\"]*)\">(.|\\s)*?</span>", display: false }
|
||||||
];
|
];
|
||||||
|
|
||||||
mathDelimiters.forEach(function (d) {
|
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) {
|
safeBody = safeBody.replace(reg, function(match, p1) {
|
||||||
return katex.renderToString(
|
return katex.renderToString(
|
||||||
|
@ -44,12 +44,12 @@ export function htmlSerializeIfNeeded(model: EditorModel, {forceHTML = false} =
|
|||||||
|
|
||||||
if (SdkConfig.get()['latex_maths']) {
|
if (SdkConfig.get()['latex_maths']) {
|
||||||
const mathDelimiters = [ // TODO: make customizable
|
const mathDelimiters = [ // TODO: make customizable
|
||||||
{ left: "\\$\\$\\$", right: "\\$\\$\\$", display: true },
|
{ pattern: "\\$\\$\\$(([^$]|\\\\\\$)*)\\$\\$\\$", display: true },
|
||||||
{ left: "\\$\\$", right: "\\$\\$", display: false }
|
{ pattern: "\\$\\$(([^$]|\\\\\\$)*)\\$\\$", display: false }
|
||||||
];
|
];
|
||||||
|
|
||||||
mathDelimiters.forEach(function (d) {
|
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) {
|
md = md.replace(reg, function(match, p1) {
|
||||||
const p1e = AllHtmlEntities.encode(p1);
|
const p1e = AllHtmlEntities.encode(p1);
|
||||||
if (d.display == true) {
|
if (d.display == true) {
|
||||||
|
Loading…
Reference in New Issue
Block a user