Socket
Socket
Sign inDemoInstall

@mdx-js/mdx

Package Overview
Dependencies
Maintainers
3
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.16.0 to 0.16.1

16

index.js

@@ -60,3 +60,3 @@ const unified = require('unified')

mdPlugins.forEach(plugin => {
// handle [plugin, pluginOptions] syntax
// Handle [plugin, pluginOptions] syntax
if (Array.isArray(plugin) && plugin.length > 1) {

@@ -79,3 +79,3 @@ fn.use(plugin[0], plugin[1])

hastPlugins.forEach(plugin => {
// handle [plugin, pluginOptions] syntax
// Handle [plugin, pluginOptions] syntax
if (Array.isArray(plugin) && plugin.length > 1) {

@@ -108,8 +108,8 @@ compiler.use(plugin[0], plugin[1])

const fileOpts = { contents: mdx };
const fileOpts = {contents: mdx}
if (opts.filepath) {
fileOpts.path = opts.filepath;
fileOpts.path = opts.filepath
}
const { contents } = compiler.processSync(fileOpts)
const {contents} = compiler.processSync(fileOpts)

@@ -123,8 +123,8 @@ return contents

const fileOpts = { contents: mdx };
const fileOpts = {contents: mdx}
if (opts.filepath) {
fileOpts.path = opts.filepath;
fileOpts.path = opts.filepath
}
const { contents } = await compiler.process(fileOpts)
const {contents} = await compiler.process(fileOpts)

@@ -131,0 +131,0 @@ return contents

@@ -5,6 +5,3 @@ const visit = require('unist-util-visit')

visit(tree, 'html', node => {
if (
node.value.startsWith('<!--') &&
node.value.endsWith('-->')
) {
if (node.value.startsWith('<!--') && node.value.endsWith('-->')) {
node.type = 'comment'

@@ -11,0 +8,0 @@ } else {

@@ -5,3 +5,3 @@ const toHAST = require('mdast-util-to-hast')

module.exports = function mdxAstToMdxHast() {
function mdxAstToMdxHast() {
return (tree, file) => {

@@ -25,5 +25,4 @@ const handlers = {

code(h, node) {
const langRegex = /^[^ \t]+(?=[ \t]|$)/
const value = node.value ? detab(node.value + '\n') : ''
const lang = node.lang && node.lang.match(langRegex)
const lang = node.lang
const props = {}

@@ -34,8 +33,8 @@

}
props.metastring = node.lang && node.lang.replace(langRegex, '').trim()
props.metastring = node.meta
const meta =
props.metastring &&
props.metastring.split(' ').reduce((acc, cur) => {
node.meta &&
node.meta.split(' ').reduce((acc, cur) => {
if (cur.split('=').length > 1) {

@@ -45,9 +44,12 @@ const t = cur.split('=')

return acc
} else {
acc[cur] = true
return acc
}
acc[cur] = true
return acc
}, {})
meta && Object.keys(meta).forEach(key => (props[key] = meta[key]))
if (meta) {
Object.keys(meta).forEach(key => {
props[key] = meta[key]
})
}

@@ -87,1 +89,3 @@ return h(node.position, 'pre', [

}
module.exports = mdxAstToMdxHast
const toStyleObject = require('to-style').object
const { paramCase } = require('change-case')
const {paramCase} = require('change-case')
// eslint-disable-next-line complexity
function toJSX(node, parentNode = {}, options = {}) {
const {
// default options
// Default options
skipExport = false,
preserveNewlines = false,
preserveNewlines = false
} = options

@@ -14,13 +15,17 @@ let children = ''

if (typeof node.properties.style === 'string') {
node.properties.style = toStyleObject(node.properties.style, { camelize: true })
node.properties.style = toStyleObject(node.properties.style, {
camelize: true
})
}
// ariaProperty => aria-property
// AriaProperty => aria-property
// dataProperty => data-property
const paramCaseRe = /^(aria[A-Z])|(data[A-Z])/
node.properties = Object.entries(node.properties).reduce((properties, [key, value]) => Object.assign(
{},
properties,
{ [paramCaseRe.test(key) ? paramCase(key) : key]: value },
), {})
node.properties = Object.entries(node.properties).reduce(
(properties, [key, value]) =>
Object.assign({}, properties, {
[paramCaseRe.test(key) ? paramCase(key) : key]: value
}),
{}
)
}

@@ -53,2 +58,3 @@

// eslint-disable-next-line max-depth
if (/\}\s*from\s+/.test(childNode.value)) {

@@ -77,7 +83,11 @@ example = `

throw new Error(`
throw new Error(
`
MDX doesn't support using "default" as a named export, use "export default" statement instead.
${example}
`.trim().replace(/^ +/gm, ''))
`
.trim()
.replace(/^ +/gm, '')
)
}

@@ -91,3 +101,2 @@

}
return (

@@ -98,22 +107,31 @@ importNodes.map(childNode => toJSX(childNode, node)).join('\n') +

'\n' +
(skipExport
? ''
: 'export default ({components, ...props}) => ') +
`<MDXTag name="wrapper" ${
layout ? `Layout={${layout}} layoutProps={props}` : ''
} components={components}>${jsxNodes
.map(childNode => toJSX(childNode, node))
.join('')}</MDXTag>`
`${
skipExport ? '' : 'export default'
} class MDXContent extends React.Component {
constructor() {
this.layout = ${layout}
}
render() {
return <MDXTag
name="wrapper"
${layout ? `Layout={this.layout} layoutProps={props}` : ''}
components={components}>${jsxNodes
.map(childNode => toJSX(childNode, node))
.join('')}
</MDXTag>
}
}`
)
}
// recursively walk through children
// Recursively walk through children
if (node.children) {
children = node.children.map(childNode => {
const childOptions = Object.assign({}, options, {
// tell all children inside <pre> tags to preserve newlines as text nodes
preserveNewlines: preserveNewlines || node.tagName === 'pre',
children = node.children
.map(childNode => {
const childOptions = Object.assign({}, options, {
// Tell all children inside <pre> tags to preserve newlines as text nodes
preserveNewlines: preserveNewlines || node.tagName === 'pre'
})
return toJSX(childNode, node, childOptions)
})
return toJSX(childNode, node, childOptions)
}).join('')
.join('')
}

@@ -148,5 +166,3 @@

if (node.type === 'comment') {
return node.value
.replace('<!--', '{/*')
.replace('-->', '*/}')
return node.value.replace('<!--', '{/*').replace('-->', '*/}')
}

@@ -153,0 +169,0 @@

{
"name": "@mdx-js/mdx",
"version": "0.16.0",
"version": "0.16.1",
"description": "Parse MDX and transpile to JSX",
"license": "MIT",
"keywords": [
"mdx",
"markdown",
"react",
"jsx",
"remark",
"mdxast"
],
"homepage": "https://mdxjs.com",
"repository": "mdx-js/mdx",
"description": "Parse MDX and transpile to JSX",
"bugs": "https://github.com/mdx-js/mdx/issues",
"author": "John Otander <johnotander@gmail.com> (http://johnotander.com)",
"contributors": [
"John Otander <johnotander@gmail.com> (http://johnotander.com)",
"Tim Neutkens <tim@zeit.co>",
"Matija Marohnić <matija.marohnic@gmail.com>",
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"files": [

@@ -14,20 +31,10 @@ "index.js",

],
"scripts": {
"test": "jest"
},
"keywords": [
"react",
"markdown",
"remark",
"mdxast",
"mdx"
],
"dependencies": {
"change-case": "^3.0.2",
"detab": "^2.0.0",
"mdast-util-to-hast": "^3.0.0",
"remark-parse": "^5.0.0",
"mdast-util-to-hast": "^4.0.0",
"remark-parse": "^6.0.0",
"remark-squeeze-paragraphs": "^3.0.1",
"to-style": "^1.3.3",
"unified": "^6.1.6",
"unified": "^7.0.0",
"unist-builder": "^1.0.1",

@@ -37,16 +44,19 @@ "unist-util-visit": "^1.3.0"

"devDependencies": {
"@babel/core": "^7.0.0-beta.44",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.44",
"@babel/plugin-syntax-jsx": "^7.0.0-beta.44",
"@mapbox/rehype-prism": "^0.2.0",
"hast-util-select": "^1.0.1",
"jest": "^22.4.3",
"@babel/core": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/plugin-syntax-jsx": "^7.0.0",
"@mapbox/rehype-prism": "^0.3.0",
"hast-util-select": "^3.0.0",
"jest": "^23.6.0",
"prettier": "^1.14.2",
"rehype-katex": "^1.1.1",
"remark-math": "^1.0.4",
"request-image-size": "^2.1.0"
"remark-math": "^1.0.4"
},
"scripts": {
"test": "jest"
},
"jest": {
"testEnvironment": "node"
},
"gitHead": "2c1c8676327f97b060283c5a9047574d8ada11ec"
"gitHead": "b69654652e22043592da6db45bc8306b05c783ad"
}

@@ -1,11 +0,78 @@

# @mdx-js/mdx
# `@mdx-js/mdx`
MDX implementation using Remark.
[![Build Status][build-badge]][build]
[![lerna][lerna-badge]][lerna]
[![Join the community on Spectrum][spectrum-badge]][spectrum]
https://github.com/mdx-js/mdx
[MDX][] implementation using [remark][].
## Installation
[npm][]:
```sh
npm i -S @mdx-js/mdx
```
## Usage
```js
const mdx = require('@mdx-js/mdx')
const result = await mdx(`
# Hello, MDX
I <3 Markdown and JSX
`)
console.log(result)
```
Yields:
```js
export default ({components, ...props}) => <MDXTag name="wrapper" components={components}><MDXTag name="h1" components={components}>{`Hello, MDX`}</MDXTag>
<MDXTag name="p" components={components}>{`I <3 Markdown and JSX`}</MDXTag></MDXTag>
```
## Contribute
See [`contributing.md` in `mdx-js/mdx`][contributing] for ways to get started.
This organisation has a [Code of Conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][] © [Compositor][] and [ZEIT][]
<!-- Definitions -->
[build]: https://travis-ci.org/mdx-js/mdx
[build-badge]: https://travis-ci.org/mdx-js/mdx.svg?branch=master
[lerna]: https://lernajs.io/
[lerna-badge]: https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg
[spectrum]: https://spectrum.chat/mdx
[spectrum-badge]: https://withspectrum.github.io/badge/badge.svg
[contributing]: https://github.com/mdx-js/mdx/blob/master/contributing.md
[coc]: https://github.com/mdx-js/mdx/blob/master/code-of-conduct.md
[mit]: license
[remark]: https://github.com/remarkjs/remark
[compositor]: https://compositor.io
[zeit]: https://zeit.co
[mdx]: https://github.com/mdx-js/mdx
[npm]: https://docs.npmjs.com/cli/install
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