Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 1b4db29

Browse files
author
Anders Fredrik Kiær
committed
Math in dcc.Markdown using KaTeX
1 parent b35a560 commit 1b4db29

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

demo/Demo.react.js

+11
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ Some code
5858
\\\`\\\`\\\`
5959
6060
Inline \\\`code\\\` example.
61+
62+
***
63+
64+
Some block mathematics:
65+
66+
$$
67+
e^{ix} = \\\\cos x + i\\\\sin x.
68+
$$
69+
70+
Some inline mathematics $\\\\alpha=2$ and $\\\\beta=3$.
71+
6172
\`
6273
6374
ReactDOM.render(<Markdown>{markdown}</Markdown>, mountNode);

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@
4646
"react-dates": "^20.1.0",
4747
"react-docgen": "^3.0.0",
4848
"react-dropzone": "^4.1.2",
49+
"react-katex": "^2.0.2",
4950
"react-markdown": "^4.0.6",
5051
"react-resize-detector": "^4.2.1",
5152
"react-select-fast-filter-options": "^0.2.3",
5253
"react-virtualized-select": "^3.1.3",
54+
"remark-math": "^1.0.6",
5355
"uniqid": "^5.0.3"
5456
},
5557
"devDependencies": {
@@ -87,6 +89,7 @@
8789
"style-loader": "^0.23.1",
8890
"styled-jsx": "^3.1.1",
8991
"terser-webpack-plugin": "^2.3.0",
92+
"url-loader": "^2.1.0",
9093
"webpack": "^4.37.0",
9194
"webpack-cli": "^3.3.6",
9295
"webpack-serve": "^2.0.3"

src/fragments/Markdown.react.js

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import {mergeDeepRight, pick, type} from 'ramda';
33
import JsxParser from 'react-jsx-parser';
44
import Markdown from 'react-markdown';
55

6+
import RemarkMathPlugin from 'remark-math';
7+
import { InlineMath, BlockMath } from 'react-katex';
8+
import 'katex/dist/katex.min.css';
9+
610
import MarkdownHighlighter from '../utils/MarkdownHighlighter';
711
import {propTypes, defaultProps} from '../components/Markdown.react';
812

@@ -131,7 +135,10 @@ export default class DashMarkdown extends Component {
131135
<Markdown
132136
source={displayText}
133137
escapeHtml={!dangerously_allow_html}
138+
plugins={[RemarkMathPlugin]}
134139
renderers={{
140+
math: ({value}) => <BlockMath>{value}</BlockMath>,
141+
inlineMath: ({value}) => <InlineMath>{value}</InlineMath>,
135142
html: props =>
136143
props.escapeHtml ? (
137144
props.value

webpack.config.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ module.exports = (env, argv) => {
9292
},
9393
],
9494
},
95+
{
96+
test: /\.(png|woff|woff2|eot|ttf|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
97+
use:[
98+
{
99+
loader: 'url-loader'
100+
}
101+
]
102+
}
95103
],
96104
},
97105
resolve: {
@@ -138,4 +146,4 @@ module.exports = (env, argv) => {
138146
})
139147
]
140148
}
141-
};
149+
};

0 commit comments

Comments
 (0)