From 0cdae301e6be51900f60ad5dd50b495376e1cd90 Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Mon, 15 Oct 2018 14:48:29 -0700 Subject: [PATCH] Fix: Ignore anything after space in code fence's language (fixes #98) --- lib/processor.js | 2 +- tests/lib/processor.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/processor.js b/lib/processor.js index 113b289a..8ded5d41 100644 --- a/lib/processor.js +++ b/lib/processor.js @@ -80,7 +80,7 @@ function preprocess(text) { var comments = []; var index, previousNode, comment; - if (node.lang && SUPPORTED_SYNTAXES.indexOf(node.lang.toLowerCase()) >= 0) { + if (node.lang && SUPPORTED_SYNTAXES.indexOf(node.lang.split(" ")[0].toLowerCase()) >= 0) { index = parent.children.indexOf(node) - 1; previousNode = parent.children[index]; while (previousNode && previousNode.type === "html") { diff --git a/tests/lib/processor.js b/tests/lib/processor.js index eeed1973..5b15b4d7 100644 --- a/tests/lib/processor.js +++ b/tests/lib/processor.js @@ -257,6 +257,17 @@ describe("processor", function() { assert.equal(blocks.length, 1); }); + it("should ignore anything after the first word of the info string", function() { + var code = [ + "```js more words are ignored", + "var answer = 6 * 7;", + "```" + ].join("\n"); + var blocks = processor.preprocess(code); + + assert.equal(blocks.length, 1); + }); + it("should find code fences not surrounded by blank lines", function() { var code = [ "",