mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
ui: katex: show render errors
This commit is contained in:
1 file changed
+11
-2
@@ -61,6 +61,15 @@ function inline(state, silent) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function escapeHtml(unsafe) {
|
||||
return unsafe
|
||||
.replace(/&/g, '&')
|
||||
.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 `<p class='katex-error' title='${escapeHtml(error.toString())}'>${escapeHtml(latex)}</p>`;
|
||||
}
|
||||
};
|
||||
const inlineRenderer = function (tokens, idx) {
|
||||
@@ -122,7 +131,7 @@ module.exports = function plugin(md) {
|
||||
return `<p>${katex.renderToString(latex, options)}</p>`;
|
||||
} catch (error) {
|
||||
if (options.throwOnError) logger.error(error);
|
||||
return latex;
|
||||
return `<p class='katex-block katex-error' title='${escapeHtml(error.toString())}'>${escapeHtml(latex)}</p > `;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user