diff --git a/lib/processor.js b/lib/processor.js index 41f6f7a..57428d6 100644 --- a/lib/processor.js +++ b/lib/processor.js @@ -22,25 +22,27 @@ let blocks = []; * Performs a depth-first traversal of the Markdown AST. * @param {ASTNode} node A Markdown AST node. * @param {Object} callbacks A map of node types to callbacks. - * @param {Object} [parent] The node's parent AST node. * @returns {void} */ -function traverse(node, callbacks, parent) { +function traverse(node, callbacks) { if (callbacks[node.type]) { - callbacks[node.type](node, parent); + callbacks[node.type](node); + } else { + callbacks["*"](); } if (typeof node.children !== "undefined") { for (let i = 0; i < node.children.length; i++) { - traverse(node.children[i], callbacks, node); + traverse(node.children[i], callbacks); } } } /** - * Converts leading HTML comments to JS block comments. + * Extracts `eslint-*` or `global` comments from HTML comments if present. * @param {string} html The text content of an HTML AST node. - * @returns {string[]} An array of JS block comments. + * @returns {string} The comment's text without the opening and closing tags or + * an empty string if the text is not an ESLint HTML comment. */ function getComment(html) { const commentStart = "", + "```js", + "console.log(\"Blank line\");", + "```", + "", + "* List item without a blank line", + "", + "```js", + "console.log(\"No blank line\");", + "```" + ].join("\n"); + const blocks = processor.preprocess(code); + + assert.strictEqual(blocks.length, 2); + assert.strictEqual(blocks[0].text, [ + "/* eslint-disable no-console */", + "console.log(\"Blank line\");", + "" + ].join("\n")); + assert.strictEqual(blocks[1].text, [ + "/* eslint-disable no-console */", + "console.log(\"No blank line\");", + "" + ].join("\n")); + }); + it("should ignore non-eslint comments", () => { const code = [ "",