项目作者: jxnblk

项目描述 :
💫 Convert markdown to live React demos
高级语言: JavaScript
项目地址: git://github.com/jxnblk/live-doc.git
创建时间: 2017-07-16T17:15:42Z
项目社区:https://github.com/jxnblk/live-doc

开源协议:

下载


No longer maintained see https://mdxjs.com for a better alternative

live-doc

Convert markdown to live React demos http://jxnblk.com/live-doc

Built with: react-markdown, React Live, Rebass, and styled-components

Getting Started

  1. npm i -g live-doc

Convert a markdown file to a React app and save as index.html:

  1. doc README.md

Live Code Example

By using the .jsx language attribute at the beginning of a code block,
live-doc will convert the example into a live-editable example using React Live.

  1. <div>
  2. <Heading color='tomato'>
  3. Hello! Edit me
  4. </Heading>
  5. <button
  6. onClick={e => {
  7. alert('Hello')
  8. }}
  9. children='Beep'
  10. />
  11. </div>

In this example, the Rebass Heading component has been added to the scope in the docs/config.js file,
making it available to the React Live preview.

React Live noInline Mode

To enable the noInline mode
in React Live, use the ..jsx language attribute at the beginning of a code block.

  1. const Hello = () => <h1>Hello</h1>
  2. const App = () => (
  3. <div>
  4. <Hello ></Hello>
  5. <button
  6. onClick={e => {
  7. alert('Beep')
  8. }}
  9. children='Beep'
  10. />
  11. </div>
  12. )
  13. render(<App ></App>)

CLI Options

  1. -d --out-dir Output directory
  2. -c --config Path to config file

Configuration

To customize the output React app, create a config file that exports an object.

  1. // config.js
  2. module.exports = {
  3. // Scope for react-live previews
  4. scope: {
  5. foo: 'Hello'
  6. },
  7. title: 'Page Title',
  8. css: 'body { color: tomato }',
  9. script: 'console.log("Hello");',
  10. // Meta tags
  11. meta: [
  12. {
  13. name: 'og:image',
  14. content: 'kitten.jpg'
  15. }
  16. ]
  17. }

Then pass the file with the --config flag to the CLI.

  1. doc README.md --config config.js

GitHub
Made by Jxnblk

MIT License