rehype-highlight-code-lines
Advanced tools
Comparing version
@@ -26,15 +26,16 @@ import { visit, CONTINUE } from "unist-util-visit"; | ||
const node = children[i]; | ||
console.log(node); | ||
if (node.type !== "element") { | ||
newTree = newTree.concat([node]); | ||
} | ||
else if (node.children.length === 1 && node.children[0].type !== "element") { | ||
// @ts-expect-error | ||
node.properties.className = className.concat(node.properties.className); | ||
newTree = newTree.concat([node]); | ||
} | ||
else { | ||
// @ts-expect-error | ||
// /* v8 ignore next */ | ||
const classNames = className.concat(node.properties?.className || []); | ||
newTree = newTree.concat(flattenCodeTree(node.children, classNames)); | ||
if (node.children.length === 1 && node.children[0].type !== "element") { | ||
node.properties.className = classNames; | ||
newTree = newTree.concat([node]); | ||
} | ||
else { | ||
newTree = newTree.concat(flattenCodeTree(node.children, classNames)); | ||
} | ||
} | ||
@@ -159,5 +160,13 @@ } | ||
} | ||
if (settings.showLineNumbers) { | ||
if (!meta) { | ||
meta = "showlinenumbers"; | ||
} | ||
else if (!meta.includes("showlinenumbers")) { | ||
meta = meta + " showlinenumbers"; | ||
} | ||
} | ||
if (!meta) | ||
return; | ||
const showLineNumbers = settings.showLineNumbers || meta.includes("showlinenumbers"); | ||
const showLineNumbers = meta.includes("showlinenumbers"); | ||
// find number range string within curly braces and parse it | ||
@@ -164,0 +173,0 @@ const RE = /{(?<lines>[\d\s,-]+)}/g; |
{ | ||
"name": "rehype-highlight-code-lines", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Rehype plugin to add line numbers to code blocks and allow highlighting of desired code lines", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -59,13 +59,15 @@ import type { Plugin } from "unified"; | ||
const node = children[i]; | ||
console.log(node); | ||
if (node.type !== "element") { | ||
newTree = newTree.concat([node]); | ||
} else if (node.children.length === 1 && node.children[0].type !== "element") { | ||
// @ts-expect-error | ||
node.properties.className = className.concat(node.properties.className); | ||
newTree = newTree.concat([node]); | ||
} else { | ||
// @ts-expect-error | ||
// /* v8 ignore next */ | ||
const classNames = className.concat(node.properties?.className || []); | ||
newTree = newTree.concat(flattenCodeTree(node.children, classNames)); | ||
if (node.children.length === 1 && node.children[0].type !== "element") { | ||
node.properties.className = classNames; | ||
newTree = newTree.concat([node]); | ||
} else { | ||
newTree = newTree.concat(flattenCodeTree(node.children, classNames)); | ||
} | ||
} | ||
@@ -226,5 +228,13 @@ } | ||
if (settings.showLineNumbers) { | ||
if (!meta) { | ||
meta = "showlinenumbers"; | ||
} else if (!meta.includes("showlinenumbers")) { | ||
meta = meta + " showlinenumbers"; | ||
} | ||
} | ||
if (!meta) return; | ||
const showLineNumbers = settings.showLineNumbers || meta.includes("showlinenumbers"); | ||
const showLineNumbers = meta.includes("showlinenumbers"); | ||
@@ -231,0 +241,0 @@ // find number range string within curly braces and parse it |
Sorry, the diff of this file is not supported yet
35544
1.59%402
4.42%