chore: added custom component

This commit is contained in:
wonderlandpark 2021-03-07 21:49:22 +09:00
parent cde1b1f11e
commit 28d7642428

View File

@ -31,7 +31,7 @@ const Docs: NextPage<DocsProps> = ({ docs }) => {
<div className='px-2'>
{
!document ? ''
: <Markdown text={document.text} options={{ openLinksInNewWindow: false }} components={{ message: Message }} allowedTag={['message']} />
: <Markdown text={document.text} options={{ openLinksInNewWindow: false }} components={{ message: Message, code }} allowedTag={['message']} />
}
</div>
</DeveloperLayout>
@ -72,6 +72,18 @@ export async function getStaticProps () {
}
}
function code({ children }:{ children: string }):JSX.Element {
const methods = {
get: 'text-green-400',
post: 'text-yellow-400',
put: 'text-blue-500',
patch: 'text-yellow-400',
delete: 'text-red-500'
}
return <code className={`${methods[String(children).toLowerCase()]}`}>
{children}
</code>
}
function highlightBlocks() {
const nodes = window.document.querySelectorAll('pre code')
nodes.forEach(el => {