Skip to content

Commit 7488423

Browse files
docs: add remark math example
1 parent 973853f commit 7488423

File tree

4 files changed

+178
-11
lines changed

4 files changed

+178
-11
lines changed

package-lock.json

Lines changed: 124 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@
4949
"babel-loader": "^8.1.0",
5050
"husky": "^4.2.5",
5151
"jest-environment-jsdom-sixteen": "^1.0.3",
52+
"katex": "^0.11.1",
5253
"react": "^16.13.1",
5354
"react-docgen-typescript-loader": "^3.7.2",
5455
"react-dom": "^16.13.1",
5556
"react-is": "^16.13.1",
5657
"react-test-renderer": "^16.13.1",
58+
"rehype-katex": "^3.0.0",
59+
"remark-math": "^2.0.1",
5760
"ts-loader": "^7.0.4",
5861
"tsdx": "^0.13.2",
5962
"tslib": "^2.0.0",

stories/remark-component.stories.tsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
11
import React from 'react';
22
import { text } from '@storybook/addon-knobs';
3+
import remarkMath from 'remark-math';
4+
import rehypeKatex from 'rehype-katex';
5+
import 'katex/dist/katex.min.css';
6+
37
import { Remark } from '../src';
48

59
export default {
610
title: 'Remark Component',
711
component: Remark,
812
};
913

10-
export const Default = () =>
11-
// prettier-ignore
14+
export const Default = () => (
1215
<Remark>
13-
{text("content", `# header
16+
{text(
17+
'content',
18+
`# header
1419
1520
1. ordered
1621
2. list
1722
1823
* unordered
19-
* list
24+
* list`
25+
)}
26+
</Remark>
27+
);
28+
29+
export const Math = () => (
30+
<Remark remarkPlugins={[remarkMath]} rehypePlugins={[rehypeKatex]}>
31+
{text(
32+
'content',
33+
`Lift($L$) can be determined by Lift Coefficient ($C_L$) like the following equation.
2034
21-
`)}
22-
</Remark>;
35+
$$
36+
L = \\frac{1}{2} \\rho v^2 S C_L
37+
$$`
38+
)}
39+
</Remark>
40+
);

stories/remark-hook.stories.tsx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
2-
31
import { useEffect } from 'react';
42
import { text } from '@storybook/addon-knobs';
3+
import remarkMath from 'remark-math';
4+
import rehypeKatex from 'rehype-katex';
5+
import 'katex/dist/katex.min.css';
6+
57
import { useRemark } from '../src';
68

79
export default {
810
title: 'Remark Hook',
9-
component: useRemark
11+
component: useRemark,
1012
};
1113

1214
export const Default = () => {
@@ -18,4 +20,25 @@ export const Default = () => {
1820
}, [markdownSource]);
1921

2022
return reactContent;
21-
};
23+
};
24+
25+
export const Math = () => {
26+
const [reactContent, setMarkdownSource] = useRemark({
27+
remarkPlugins: [remarkMath],
28+
rehypePlugins: [rehypeKatex],
29+
});
30+
const markdownSource = text(
31+
'markdown',
32+
`Lift($L$) can be determined by Lift Coefficient ($C_L$) like the following equation.
33+
34+
$$
35+
L = \\frac{1}{2} \\rho v^2 S C_L
36+
$$`
37+
);
38+
39+
useEffect(() => {
40+
setMarkdownSource(markdownSource);
41+
}, [markdownSource]);
42+
43+
return reactContent;
44+
};

0 commit comments

Comments
 (0)