diff --git a/packages/ui-default/backendlib/markdown-it-katex.js b/packages/ui-default/backendlib/markdown-it-katex.js index 5e1ebff26..facbb97c6 100644 --- a/packages/ui-default/backendlib/markdown-it-katex.js +++ b/packages/ui-default/backendlib/markdown-it-katex.js @@ -61,6 +61,15 @@ function inline(state, silent) { return true; } +function escapeHtml(unsafe) { + return unsafe + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, '''); +} + function block(state, start, end, silent) { let lastLine; let lastPos; @@ -109,7 +118,7 @@ module.exports = function plugin(md) { return katex.renderToString(latex, options); } catch (error) { if (options.throwOnError) logger.error(error); - return latex; + return `

${escapeHtml(latex)}

`; } }; const inlineRenderer = function (tokens, idx) { @@ -122,7 +131,7 @@ module.exports = function plugin(md) { return `

${katex.renderToString(latex, options)}

`; } catch (error) { if (options.throwOnError) logger.error(error); - return latex; + return `

${escapeHtml(latex)}

`; } };