Skip to content

Commit

Permalink
Merge pull request #45 from timlrx/fix/remove-positions
Browse files Browse the repository at this point in the history
Fix/remove positions
  • Loading branch information
timlrx committed Jul 5, 2022
2 parents 1296061 + a8ce18f commit 4ccceff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "rehype-prism-plus",
"version": "1.4.1",
"version": "1.4.2",
"description": "rehype plugin to highlight code blocks in HTML with Prism (via refractor) with line highlighting and line numbers",
"source": "index.js",
"files": [
Expand Down
14 changes: 14 additions & 0 deletions src/generator.js
Expand Up @@ -51,6 +51,16 @@ const calculateLinesToHighlight = (meta) => {
}
}

const recursivelyStripPositions = (node) => {
delete node.position

if (!node.children || node.children.length === 0) return node

node.children = node.children.map((x) => recursivelyStripPositions(x))

return node
}

/**
* Check if we want to start the line numbering from a given number or 1
* showLineNumbers=5, will start the numbering from 5
Expand Down Expand Up @@ -282,6 +292,10 @@ const rehypePrismGenerator = (refractor) => {
}

node.children = codeLineArray

// Removing remnant positions info as it causes some problems in @next/mdx
// https://github.com/timlrx/rehype-prism-plus/issues/44
recursivelyStripPositions(node)
}
}
}
Expand Down

0 comments on commit 4ccceff

Please sign in to comment.