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

Add more options to playground, directives, format, etc #2295

Merged
merged 15 commits into from
Jun 10, 2023
Merged
Prev Previous commit
Next Next commit
Add rehype-raw option
  • Loading branch information
slorber committed May 11, 2023
commit 07a1ddb6cba85b533182f46480e4b3a6deed4a12
23 changes: 20 additions & 3 deletions docs/_component/editor.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {statistics} from 'vfile-statistics'
import {reporter} from 'vfile-reporter'
import {evaluate} from '@mdx-js/mdx'
import remarkGfm from 'remark-gfm'
import rehypeRaw from 'rehype-raw'
import remarkFrontmatter from 'remark-frontmatter'
import remarkDirective from 'remark-directive'
import remarkMath from 'remark-math'
Expand Down Expand Up @@ -52,21 +53,23 @@ function useMdx(defaults) {
}

const remarkPlugins = []

if (config.gfm) remarkPlugins.push(remarkGfm)
if (config.frontmatter) remarkPlugins.push(remarkFrontmatter)
if (config.math) remarkPlugins.push(remarkMath)
if (config.directive) remarkPlugins.push(remarkDirective)

remarkPlugins.push(capture('mdast'))

const rehypePlugins = []
if (config.rehypeRaw) rehypePlugins.push(rehypeRaw)
slorber marked this conversation as resolved.
Show resolved Hide resolved
rehypePlugins.push(capture('hast'))

try {
file.result = (
await evaluate(file, {
...runtime,
useDynamicImport: true,
remarkPlugins,
rehypePlugins: [capture('hast')],
rehypePlugins,
recmaPlugins: [capture('esast')]
})
).default
Expand Down Expand Up @@ -133,6 +136,7 @@ export function Editor({children}) {
frontmatter: false,
directive: false,
math: false,
rehypeRaw: false,
value: defaultValue
})
const onUpdate = useCallback(
Expand Down Expand Up @@ -272,6 +276,19 @@ export function Editor({children}) {
<code>remark-directive</code>
</a>
</label>
<label>
<input
checked={state.rehypeRaw}
type="checkbox"
onChange={() =>
setConfig({...state, rehypeRaw: !state.rehypeRaw})
}
/>{' '}
Use{' '}
<a href="https://github.com/rehypejs/rehype-raw">
<code>rehype-raw</code>
</a>
</label>
</form>
</TabPanel>
</Tabs>
Expand Down