Skip to content

Commit

Permalink
fix: remove positions to avoid error with next/mdx
Browse files Browse the repository at this point in the history
  • Loading branch information
timlrx committed Jul 5, 2022
1 parent 1296061 commit 4675689
Showing 1 changed file with 14 additions and 0 deletions.
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

1 comment on commit 4675689

@jaywcjlove
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.