Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

components prop to allow using React component in Markdown #12

Open
yhatt opened this issue Jun 22, 2019 · 1 comment
Open

components prop to allow using React component in Markdown #12

yhatt opened this issue Jun 22, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@yhatt
Copy link
Member

yhatt commented Jun 22, 2019

By custom function binding in HTM, we might support React component written in HTML block of plain Markdown.

import { Chart } from 'someone-react-chart-component'

const markdown = `
# Hello

<Chart type="line" data="5,8,4,9,7,2,6" />
`

ReactDOM.render(
  <Marp markdown={markdown} components={{ Chart }} />,
  document.getElementById('app')
)

⚠️ It is different from MDX. Marp React is a runtime component to support for live rendering, but MDX has no runtime (Actually it is there but not recommended). There are difference to each Markdown architectures too (markdown-it vs remark), and using Marp parser in MDX would be difficult. Thus, we have no idea to support MDX for now.

@yhatt yhatt added the enhancement New feature or request label Jun 22, 2019
@yhatt
Copy link
Member Author

yhatt commented Jun 22, 2019

The other idea is using JSX in interpolation of tagged template literal to allow using components in local scope. It won't require explicit component passing.

import { Marp, jsx } from '@marp-team/marp-react'
import { BarChart, Bar } from 'someone-react-chart-component'

// Returns something with interpolated components for parsing in Marp component
const markdown = jsx`
# Bar chart

${(
  <BarChart title="Example bar chart">
    <Bar value="5" />
    <Bar value="8" />
    <Bar value="4" />
    <Bar value="9" />
    <Bar value="7" />
    <Bar value="2" />
    <Bar value="6" />
  </BarChart>
)}
`

// Usage of Marp component is same as Markdown by plain string
ReactDOM.render(
  <Marp markdown={markdown} />,
  document.getElementById('app')
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant