From 26870c681693ab48d101cceef9033178c7854ea5 Mon Sep 17 00:00:00 2001 From: yndx-birman <62902338+yndx-birman@users.noreply.github.com> Date: Fri, 17 Sep 2021 02:32:24 +0300 Subject: [PATCH] fix: resolve conflict with markdown-it-katex plugin Related issue https://github.com/waylonflinn/markdown-it-katex/issues/24 --- package-lock.json | 24 ++++++++++++++++++++++++ package.json | 1 + patterns.js | 2 +- test.js | 8 ++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 2c34ebf..d6b7f2b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3154,6 +3154,15 @@ "verror": "1.10.0" } }, + "katex": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/katex/-/katex-0.6.0.tgz", + "integrity": "sha1-EkGOCRIcBckgQbazuftrqyE8tvM=", + "dev": true, + "requires": { + "match-at": "^0.1.0" + } + }, "labeled-stream-splicer": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/labeled-stream-splicer/-/labeled-stream-splicer-2.0.1.tgz", @@ -3335,6 +3344,21 @@ "integrity": "sha512-ykLQZmhy8QnNEm6NgImIrr+/QMe7gSnHgLhNAjz9GGCNdSLR7C/SLFNwGdUZq7vK3a0myWiOYE0tpaZuB0rWWw==", "dev": true }, + "markdown-it-katex": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/markdown-it-katex/-/markdown-it-katex-2.0.3.tgz", + "integrity": "sha1-17hqGuoLnWSW+rTnkZoY/e9YnDk=", + "dev": true, + "requires": { + "katex": "^0.6.0" + } + }, + "match-at": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/match-at/-/match-at-0.1.1.tgz", + "integrity": "sha512-h4Yd392z9mST+dzc+yjuybOGFNOZjmXIPKWjxBd1Bb23r4SmDOsk2NYCU2BMUBGbSpZqwVsZYNq26QS3xfaT3Q==", + "dev": true + }, "md5.js": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz", diff --git a/package.json b/package.json index 6eb9f04..0818545 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "eslint": "^5.16.0", "markdown-it": "^12.0.2", "markdown-it-implicit-figures": "^0.9.0", + "markdown-it-katex": "^2.0.3", "mocha": "^7.1.1", "nyc": "^14.1.1" }, diff --git a/patterns.js b/patterns.js index 057254b..0744a7b 100644 --- a/patterns.js +++ b/patterns.js @@ -313,7 +313,7 @@ module.exports = options => { { position: -1, content: utils.hasDelimiters('end', options), - type: (t) => t !== 'code_inline' + type: (t) => t !== 'code_inline' && t !== 'math_inline' } ] } diff --git a/test.js b/test.js index 0379fb7..5589436 100644 --- a/test.js +++ b/test.js @@ -3,6 +3,7 @@ const assert = require('assert'); const Md = require('markdown-it'); const implicitFigures = require('markdown-it-implicit-figures'); +const katex = require('markdown-it-katex'); const attrs = require('./'); const utils = require('./utils.js'); @@ -320,6 +321,13 @@ function describeTestsWithOptions(options, postText) { assert.equal(md.render(replaceDelimiters(src, options)), expected); }); + it(replaceDelimiters('should work with plugin katex', options), () => { + md = md.use(katex); + const mdWithOnlyKatex = Md().use(katex); + src = '$\\sqrt{a}$'; + assert.equal(md.render(src), mdWithOnlyKatex.render(src)); + }); + it(replaceDelimiters('should not apply inside `code{.red}`', options), () => { src = 'paragraph `code{.red}`'; expected = '

paragraph code{.red}

\n';