Skip to content

Commit

Permalink
feat(markdown-renderer): add antd.Button external render
Browse files Browse the repository at this point in the history
  • Loading branch information
UNIkeEN committed May 9, 2024
1 parent d3b12b6 commit a913434
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions frontend/src/components/markdown-renderer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {useContext} from 'react';
import { Button } from 'antd';
import ReactMarkdown from 'react-markdown';
import remarkGfm from 'remark-gfm';
import remarkHtml from 'remark-html';
Expand All @@ -9,13 +10,33 @@ const MarkdownRenderer = ({content} : any) =>{

const themeCtx = useContext(ThemeContext);

const externalRender = {
// replace html button to antd.Button
button({node, antd_type, className, children, ...props}) {
return (
<Button
className={className} type={antd_type}
style={{padding: '0 10px'}}
{...props}
>
{children}
</Button>
)
},
}

const renderers = {
...externalRender,
};

return(
<div style={{ wordWrap: 'break-word', overflowWrap: 'break-word'}} className={themeCtx.userTheme}>
<ReactMarkdown
className={'markdown-body-' + (themeCtx.userTheme === 'dark' ? 'dark' : 'light')}
remarkPlugins={[remarkGfm, remarkHtml]}
rehypePlugins={[rehypeRaw]}
skipHtml={false}
components={renderers}
>
{content}
</ReactMarkdown>
Expand Down

0 comments on commit a913434

Please sign in to comment.