|
| 1 | +import { useEffect } from 'react'; |
| 2 | +import remarkGfm from 'remark-gfm'; |
| 3 | +import remarkMath from 'remark-math'; |
| 4 | +import rehypeKatex from 'rehype-katex'; |
| 5 | +import rehypeRaw from 'rehype-raw'; |
| 6 | +import rehypeSanitize from 'rehype-sanitize'; |
| 7 | +import 'katex/dist/katex.min.css'; |
| 8 | + |
| 9 | +import { useRemarkSync } from '../src'; |
| 10 | + |
| 11 | +export default { |
| 12 | + title: 'Remark Hooks/sync and ssr with useRemarkSync', |
| 13 | + component: useRemarkSync, |
| 14 | +}; |
| 15 | + |
| 16 | +export const CommonMark = ({ content }) => { |
| 17 | + return useRemarkSync(content); |
| 18 | +}; |
| 19 | +CommonMark.args = { |
| 20 | + content: `# header |
| 21 | +
|
| 22 | +1. ordered |
| 23 | +2. list |
| 24 | +
|
| 25 | +* unordered |
| 26 | +* list`, |
| 27 | +}; |
| 28 | + |
| 29 | +export const GithubFlavoredMarkdown = ({ content }) => { |
| 30 | + return ( |
| 31 | + useRemarkSync(content, { |
| 32 | + remarkPlugins: [remarkGfm], |
| 33 | + }) || <></> |
| 34 | + ); |
| 35 | +}; |
| 36 | +GithubFlavoredMarkdown.args = { |
| 37 | + content: `# header |
| 38 | +
|
| 39 | +| column 1 | column 2 | |
| 40 | +| -------- | -------- | |
| 41 | +| first | row | |
| 42 | +`, |
| 43 | +}; |
| 44 | + |
| 45 | +export const MarkdownWithMath = ({ content }) => { |
| 46 | + return useRemarkSync(content, { |
| 47 | + remarkPlugins: [remarkMath], |
| 48 | + rehypePlugins: [rehypeKatex], |
| 49 | + }); |
| 50 | +}; |
| 51 | +MarkdownWithMath.args = { |
| 52 | + content: `Lift($L$) can be determined by Lift Coefficient ($C_L$) like the following equation. |
| 53 | +
|
| 54 | +$$ |
| 55 | +L = \\frac{1}{2} \\rho v^2 S C_L |
| 56 | +$$`, |
| 57 | +}; |
| 58 | + |
| 59 | +export const MixedHTMLSanitized = ({ content }) => { |
| 60 | + return useRemarkSync(content, { |
| 61 | + remarkToRehypeOptions: { allowDangerousHtml: true }, |
| 62 | + rehypePlugins: [rehypeRaw, rehypeSanitize], |
| 63 | + }); |
| 64 | +}; |
| 65 | +MixedHTMLSanitized.args = { |
| 66 | + content: `# header |
| 67 | +
|
| 68 | +<strong>mixed</strong> |
| 69 | +<em>with</em> |
| 70 | +<kbd>html</kbd>`, |
| 71 | +}; |
0 commit comments