generated from githubnext/blocks-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a1016c
commit 3dc1ff9
Showing
4 changed files
with
275 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,41 @@ | ||
import { FileBlockProps, getLanguageFromFilename } from "@githubnext/blocks"; | ||
import { Button, Box } from "@primer/react"; | ||
import {evaluateSync} from '@mdx-js/mdx' | ||
import * as runtime from 'react/jsx-runtime' | ||
import * as provider from '@mdx-js/react' | ||
import { FileBlockProps } from "@githubnext/blocks"; | ||
import { Box } from "@primer/react"; | ||
import { compile, CompileOptions, run } from "@mdx-js/mdx"; | ||
import { remarkCodeHike } from "@code-hike/mdx"; | ||
import * as runtime from "react/jsx-runtime"; | ||
// @ts-ignore | ||
import theme from "shiki/themes/github-dark.json"; | ||
import { PluggableList } from "@mdx-js/mdx/lib/core"; | ||
import { Fragment, useEffect, useState } from "react"; | ||
import { CH } from "@code-hike/mdx/components"; | ||
import "@code-hike/mdx/styles.css"; | ||
|
||
export default function (props: FileBlockProps) { | ||
const { context, content, metadata, onUpdateMetadata } = props; | ||
const { content } = props; | ||
const [mdxComponent, setMdxComponent] = useState<any>(undefined); | ||
|
||
// @ts-ignore | ||
const {default: Content} = evaluateSync(content, {...provider, ...runtime}); | ||
const remarkPlugins: PluggableList = [[remarkCodeHike, { theme: theme, lineNumbers: true, autoImport: false, }]]; | ||
const options: CompileOptions = { | ||
remarkPlugins, | ||
outputFormat: "function-body" | ||
}; | ||
|
||
const getContentComponent = async () => { | ||
console.log("getContentComponent"); | ||
const m = await compile(content, options); | ||
const r = await run(String(m), runtime); | ||
setMdxComponent(r); | ||
}; | ||
|
||
useEffect(() => { | ||
getContentComponent(); | ||
}, []); | ||
|
||
let component = mdxComponent ? <mdxComponent.default components={{ CH }}/> : <Fragment />; | ||
|
||
return ( | ||
<Content /> | ||
<Box style={{padding: 20}}> | ||
{component} | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.