Skip to content

Commit d55c5e2

Browse files
docs: add storybook examples for useRemarkSync
1 parent 64f450f commit d55c5e2

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

stories/remark-hook-async.stories.tsx

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
};

stories/remark-hook.stories.tsx renamed to stories/remark-hook-sync.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'katex/dist/katex.min.css';
99
import { useRemark } from '../src';
1010

1111
export default {
12-
title: 'Remark Hook',
12+
title: 'Remark Hooks/standard use with useRemark',
1313
component: useRemark,
1414
};
1515

0 commit comments

Comments
 (0)