示例#1
0
文件: MDXAsset.js 项目: ntaylor89/mdx
  async generate() {
    const config = await this.getConfig(
      ['.mdxrc', 'mdx.config.js', 'package.json'],
      {packageKey: 'mdx'}
    )
    const compiled = await mdx(this.contents, config)
    const fullCode = `
import React from 'react';
import { MDXTag } from '@mdx-js/tag';
${compiled}
`
    return [
      {
        type: 'js',
        value: fullCode,
        sourceMap: undefined
      }
    ]
  }
示例#2
0
文件: index.js 项目: ntaylor89/mdx
module.exports = async function(content) {
  const callback = this.async()
  const options = Object.assign({}, getOptions(this), {
    filepath: this.resourcePath
  })
  let result

  try {
    result = await mdx(content, options)
  } catch (err) {
    return callback(err)
  }

  const code = `
  import React from 'react'
  import { MDXTag } from '@mdx-js/tag'
  ${result}
  `

  return callback(null, code)
}
示例#3
0
 const compile = (src, o = {}) =>
   mdx(src, {
     mdPlugins: options.mdPlugins || [],
     hastPlugins: [...(options.hastPlugins || []), syncAstNodes(ast, options.filePath)],
   })