Jelajahi Sumber

Merge pull request #45 from timlrx/fix/remove-positions

Fix/remove positions
Timothy 3 tahun lalu
induk
melakukan
4ccceff77f
3 mengubah file dengan 16 tambahan dan 2 penghapusan
  1. 1 1
      package-lock.json
  2. 1 1
      package.json
  3. 14 0
      src/generator.js

+ 1 - 1
package-lock.json

@@ -1,6 +1,6 @@
 {
   "name": "rehype-prism-plus",
-  "version": "1.3.2",
+  "version": "1.4.2",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {

+ 1 - 1
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": [

+ 14 - 0
src/generator.js

@@ -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
@@ -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)
     }
   }
 }