remark-mdx
Advanced tools
Comparing version 0.18.2 to 0.20.3
@@ -52,6 +52,39 @@ const {transformSync} = require('@babel/core') | ||
return sortedNodes.map(({start: _, ...node}, i) => { | ||
const allNodes = sortedNodes.map(({start: _, ...node}, i) => { | ||
const value = values[i] | ||
return {...node, value} | ||
}) | ||
// Group adjacent nodes of the same type so that they can be combined | ||
// into a single node later, this also ensures that order is preserved | ||
let currType = allNodes[0].type | ||
const groupedNodes = allNodes.reduce( | ||
(acc, curr) => { | ||
// Default export nodes shouldn't be grouped with other exports | ||
// because they're handled specially by MDX | ||
if (curr.default) { | ||
currType = 'default' | ||
return [...acc, [curr]] | ||
} | ||
if (curr.type === currType) { | ||
const lastNodes = acc.pop() | ||
return [...acc, [...lastNodes, curr]] | ||
} | ||
currType = curr.type | ||
return [...acc, [curr]] | ||
}, | ||
[[]] | ||
) | ||
// Combine adjacent nodes into a single node | ||
return groupedNodes | ||
.filter(a => a.length) | ||
.reduce((acc, curr) => { | ||
const node = curr.reduce((acc, curr) => ({ | ||
...acc, | ||
value: acc.value + curr.value | ||
})) | ||
return [...acc, node] | ||
}, []) | ||
} |
@@ -98,3 +98,3 @@ const isAlphabetical = require('is-alphabetical') | ||
function stringifyEsSyntax(node) { | ||
return node.value | ||
return node.value.trim() | ||
} | ||
@@ -101,0 +101,0 @@ |
{ | ||
"name": "remark-mdx", | ||
"version": "0.18.2", | ||
"version": "0.20.3", | ||
"description": "Support import, export, and JSX in markdown", | ||
@@ -49,3 +49,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "5938d62f831141a98eff52ddafca7d302ce9b78a" | ||
"gitHead": "f7a232c19a6f35f347a4bfbceecde6ef362d36ba" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12631
301