1
1
mirror of https://github.com/jxnblk/mdx-deck.git synced 2024-09-20 19:37:27 +03:00

Merge pull request #110 from jxnblk/fix-exports

Fix exports
This commit is contained in:
Brent Jackson 2018-08-15 10:10:08 -04:00 committed by GitHub
commit 2e83b0465c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 23 deletions

1
.npmrc Normal file
View File

@ -0,0 +1 @@
package-lock=true

View File

@ -4,41 +4,35 @@ const matter = require('gray-matter')
const stringifyObject = require('stringify-object')
const normalizeNewline = require('normalize-newline')
const EXREG = /export\sdefault\s\(/g
const MODREG = /^(import|export)\s/
const SLIDEREG = /\n---\n/
module.exports = async function (src) {
const callback = this.async()
const options = getOptions(this) || {}
options.skipExport = true
const { data, content } = matter(src)
const inlineModules = []
const modules = []
const slides = normalizeNewline(content)
.split(SLIDEREG)
.map(str => mdx.sync(str, options))
.map(str => str.trim())
.map(str => str.replace(EXREG, '('))
.map(str => {
const lines = str.split('\n')
inlineModules.push(
...lines.filter(str => MODREG.test(str))
const code = mdx.sync(str, options)
const lines = code.split('\n')
const tagIndex = lines.findIndex(str => /^</.test(str))
modules.push(
...lines.slice(0, tagIndex)
.filter(Boolean)
)
return lines.filter(str => !MODREG.test(str))
.filter(Boolean)
.join('\n')
})
const jsx = lines.slice(tagIndex).join('\n')
const {
modules = []
} = data
return `({ components, ...props }) => ${jsx}`
})
.map(str => str.trim())
const code = `import React from 'react'
import { MDXTag } from '@mdx-js/tag'
${modules.join('\n')}
${inlineModules.join('\n')}
export const meta = ${stringifyObject(data)}
export default [

6
package-lock.json generated
View File

@ -54,9 +54,9 @@
}
},
"@mdx-js/tag": {
"version": "0.14.1",
"resolved": "https://registry.npmjs.org/@mdx-js/tag/-/tag-0.14.1.tgz",
"integrity": "sha512-sZAfE6SER0wT0nYUt2wfi+RzBAfs5VNvJ1BBsJ2gNA+wHkMjd8JW4J6zAhD+ufVbYKFTUYbb6BVxImLWUFopRA==",
"version": "0.15.0",
"resolved": "https://registry.npmjs.org/@mdx-js/tag/-/tag-0.15.0.tgz",
"integrity": "sha512-W5HVjced5SMJDoV56aVkZjIfTRM/R1RBpdcDdHMdoza0rSU6lorj7xM5VJtD1AMYRRFuDUu2idkuAJaNosO4Gw==",
"requires": {
"create-react-context": "^0.2.2",
"hoist-non-react-statics": "^2.5.5",

View File

@ -22,8 +22,8 @@
"license": "MIT",
"dependencies": {
"@compositor/webfont": "^1.0.39",
"@mdx-js/mdx": "^0.15.0-1",
"@mdx-js/tag": "^0.14.1",
"@mdx-js/mdx": "^0.15.0",
"@mdx-js/tag": "^0.15.0",
"ansi-html": "0.0.7",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",