rehype-highlight-code-lines
Advanced tools
Comparing version
@@ -20,3 +20,6 @@ import { visit } from "unist-util-visit"; | ||
function isElementWithTextNode(node) { | ||
return (node?.type === "element" && node.children[0]?.type === "text" && "value" in node.children[0]); | ||
return (node?.type === "element" && | ||
node.children.length === 1 && | ||
node.children[0].type === "text" && | ||
"value" in node.children[0]); | ||
} | ||
@@ -125,4 +128,2 @@ function hasClassName(node, className) { | ||
continue; | ||
if (!hasClassName(child, "comment")) | ||
continue; | ||
const textNode = child.children[0]; | ||
@@ -190,4 +191,4 @@ if (!REGEX_LINE_BREAKS.test(textNode.value)) | ||
hasFlatteningNeed(code) && flattenCodeTree(code); // mutates the code | ||
handleFirstElementContent(code); // mutates the code | ||
handleMultiLineComments(code); // mutates the code | ||
handleFirstElementContent(code); // mutates the code | ||
handleTrimmingBlankLines(code, directiveTrimBlankLines); | ||
@@ -194,0 +195,0 @@ const replacement = []; |
{ | ||
"name": "rehype-highlight-code-lines", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "Rehype plugin to add line numbers to code blocks and allow highlighting of desired code lines", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -17,3 +17,3 @@ import type { Plugin } from "unified"; | ||
type ElementWithTextNode = Element & { | ||
children: [Text, ...ElementContent[]]; | ||
children: [Text]; | ||
}; | ||
@@ -63,3 +63,6 @@ | ||
return ( | ||
node?.type === "element" && node.children[0]?.type === "text" && "value" in node.children[0] | ||
node?.type === "element" && | ||
node.children.length === 1 && | ||
node.children[0].type === "text" && | ||
"value" in node.children[0] | ||
); | ||
@@ -194,3 +197,2 @@ } | ||
if (!isElementWithTextNode(child)) continue; | ||
if (!hasClassName(child, "comment")) continue; | ||
@@ -275,6 +277,6 @@ const textNode = child.children[0]; | ||
handleFirstElementContent(code); // mutates the code | ||
handleMultiLineComments(code); // mutates the code | ||
handleFirstElementContent(code); // mutates the code | ||
handleTrimmingBlankLines(code, directiveTrimBlankLines); | ||
@@ -281,0 +283,0 @@ |
Sorry, the diff of this file is not supported yet
728
0.41%56363
-0.12%