Socket
Socket
Sign inDemoInstall

@mdx-js/mdx

Package Overview
Dependencies
Maintainers
2
Versions
210
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mdx-js/mdx - npm Package Compare versions

Comparing version 0.15.0 to 0.15.1

29

mdx-hast-to-jsx.js
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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc