@mdx-js/mdx
Advanced tools
Comparing version 0.15.0 to 0.15.1
function toJSX(node, parentNode = {}, options = {}) { | ||
const { | ||
// default options | ||
skipExport = false, | ||
preserveNewlines = false, | ||
} = options | ||
let children = '' | ||
@@ -39,3 +44,5 @@ | ||
'\n' + | ||
(options.skipExport ? '' : 'export default ({components, ...props}) => ') + | ||
(skipExport | ||
? '' | ||
: 'export default ({components, ...props}) => ') + | ||
`<MDXTag name="wrapper" ${ | ||
@@ -51,3 +58,10 @@ layout ? `Layout={${layout}} layoutProps={props}` : '' | ||
if (node.children) { | ||
children = node.children.map(childNode => toJSX(childNode, node)).join('') | ||
children = node.children.map(childNode => { | ||
const childOptions = { | ||
...options, | ||
// tell all children inside <pre> tags to preserve newlines as text nodes | ||
preserveNewlines: preserveNewlines || node.tagName === 'pre', | ||
} | ||
return toJSX(childNode, node, childOptions) | ||
}).join('') | ||
} | ||
@@ -71,7 +85,10 @@ | ||
// Wraps all text nodes except new lines inside template string, so that we don't run into escaping issues. | ||
// Wraps text nodes inside template string, so that we don't run into escaping issues. | ||
if (node.type === 'text') { | ||
return node.value === '\n' | ||
? node.value | ||
: '{`' + node.value.replace(/`/g, '\\`').replace(/\$/g, '\\$') + '`}' | ||
// Don't wrap newlines unless specifically instructed to by the flag, | ||
// to avoid issues like React warnings caused by text nodes in tables. | ||
if (node.value === '\n' && !preserveNewlines) { | ||
return node.value | ||
} | ||
return '{`' + node.value.replace(/`/g, '\\`').replace(/\$/g, '\\$') + '`}' | ||
} | ||
@@ -78,0 +95,0 @@ |
{ | ||
"name": "@mdx-js/mdx", | ||
"version": "0.15.0", | ||
"version": "0.15.1", | ||
"license": "MIT", | ||
@@ -35,2 +35,3 @@ "repository": "mdx-js/mdx", | ||
"@babel/plugin-syntax-jsx": "^7.0.0-beta.44", | ||
"@mapbox/rehype-prism": "^0.2.0", | ||
"hast-util-select": "^1.0.1", | ||
@@ -37,0 +38,0 @@ "jest": "^22.4.3", |
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
9736
248
7