mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function escapeHtml(unsafe) {
|
||||||
|
return unsafe
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/'/g, ''');
|
||||||
|
}
|
||||||
|
|
||||||
function block(state, start, end, silent) {
|
function block(state, start, end, silent) {
|
||||||
let lastLine;
|
let lastLine;
|
||||||
let lastPos;
|
let lastPos;
|
||||||
@@ -109,7 +118,7 @@ module.exports = function plugin(md) {
|
|||||||
return katex.renderToString(latex, options);
|
return katex.renderToString(latex, options);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (options.throwOnError) logger.error(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) {
|
const inlineRenderer = function (tokens, idx) {
|
||||||
@@ -122,7 +131,7 @@ module.exports = function plugin(md) {
|
|||||||
return `<p>${katex.renderToString(latex, options)}</p>`;
|
return `<p>${katex.renderToString(latex, options)}</p>`;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (options.throwOnError) logger.error(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