From 1922f1d7327e7bed3ef9cf990226599b884c8000 Mon Sep 17 00:00:00 2001 From: Waylon Flinn Date: Sat, 19 Mar 2016 10:24:41 -0500 Subject: [PATCH] allow KaTeX options --- README.md | 5 +++++ index.js | 11 ++++++++--- package.json | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 52b8c23..22c1ea9 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,11 @@ If you're using the default markdown-it parser, I also recommend the [github sty ``` +`KaTeX` options can be supplied with the second argument to use. +```javascript +md.use(mk, {"throwOnError" : false, "errorColor" : " #cc0000"}); +``` + ## Examples ### Inline diff --git a/index.js b/index.js index 5df6286..8a0637f 100644 --- a/index.js +++ b/index.js @@ -220,16 +220,20 @@ function makeMath_block(open, close) { } -module.exports = function math_plugin(md) { +module.exports = function math_plugin(md, options) { // Default options var inlineOpen = '$', inlineClose = '$', blockOpen = '$$', blockClose = '$$'; + + options = options || {}; + // set KaTeX as the renderer for markdown-it-simplemath var katexInline = function(latex){ - return katex.renderToString(latex, {"displayMode" : false}); + options.displayMode = false; + return katex.renderToString(latex, options); }; var inlineRenderer = function(tokens, idx){ @@ -237,7 +241,8 @@ module.exports = function math_plugin(md) { }; var katexBlock = function(latex){ - return katex.renderToString(latex, {"displayMode" : true}); + options.displayMode = true; + return katex.renderToString(latex, options); } var blockRenderer = function(tokens, idx){ diff --git a/package.json b/package.json index 54f995e..9ce9a9f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "markdown-it-katex", - "version": "1.0.9", + "version": "1.1.0", "description": "Fast math support for markdown-it with KaTeX", "main": "index.js", "scripts": {