Skip to content
Snippets Groups Projects
Unverified Commit 90e1a022 authored by Takahiro Ethan Ikeuchi's avatar Takahiro Ethan Ikeuchi Committed by GitHub
Browse files

Merge pull request #1 from OpportunityLiu/patch-1

Update error output
parents 18f153e1 4ceb2b74
No related branches found
No related tags found
No related merge requests found
...@@ -152,6 +152,15 @@ function math_block(state, start, end, silent){ ...@@ -152,6 +152,15 @@ function math_block(state, start, end, silent){
return true; return true;
} }
function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}
module.exports = function math_plugin(md, options) { module.exports = function math_plugin(md, options) {
// Default options // Default options
...@@ -165,7 +174,7 @@ module.exports = function math_plugin(md, options) { ...@@ -165,7 +174,7 @@ module.exports = function math_plugin(md, options) {
} }
catch(error){ catch(error){
if(options.throwOnError){ console.log(error); } if(options.throwOnError){ console.log(error); }
return latex; return `<span class='katex-error' title='${escapeHtml(error.toString())}'>${escapeHtml(latex)}</span>`;
} }
}; };
...@@ -176,11 +185,11 @@ module.exports = function math_plugin(md, options) { ...@@ -176,11 +185,11 @@ module.exports = function math_plugin(md, options) {
var katexBlock = function(latex){ var katexBlock = function(latex){
options.displayMode = true; options.displayMode = true;
try{ try{
return "<p>" + katex.renderToString(latex, options) + "</p>"; return "<p class='katex-block'>" + katex.renderToString(latex, options) + "</p>";
} }
catch(error){ catch(error){
if(options.throwOnError){ console.log(error); } if(options.throwOnError){ console.log(error); }
return latex; return `<p class='katex-block katex-error' title='${escapeHtml(error.toString())}'>${escapeHtml(latex)}</p>`;
} }
} }
......
{ {
"name": "@iktakahiro/markdown-it-katex", "name": "@iktakahiro/markdown-it-katex",
"version": "3.0.2", "version": "3.0.3",
"description": "Fast math support for markdown-it with KaTeX", "description": "Fast math support for markdown-it with KaTeX",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment