mirror of
https://github.com/jxnblk/mdx-deck.git
synced 2024-09-20 19:37:27 +03:00
commit
2e83b0465c
@ -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
6
package-lock.json
generated
@ -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",
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user