Skip to content

Commit ce25069

Browse files
committed
website: Fix rehype-rewrite type errors. #264
1 parent d46116e commit ce25069

File tree

2 files changed

+694
-1060
lines changed

2 files changed

+694
-1060
lines changed

website/src/component/Markdown/index.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import MarkdownPreview from '@uiw/react-markdown-preview';
33
import CodePreview from '@uiw/react-code-preview';
44
import rehypeRewrite from 'rehype-rewrite';
55
import rehypeAttr from 'rehype-attr';
6+
import { Element } from 'hast';
67
import Contributors from '../Contributors';
78
import Footer from '../Footer';
89
import styles from './index.module.less';
@@ -91,10 +92,18 @@ export default class Markdown extends Component<MarkdownProps, MarkdownState> {
9192
[rehypeAttr, { properties: 'attr' }],
9293
[
9394
rehypeRewrite,
94-
(node: any) => {
95-
if (node.type === 'element' && node.tagName === 'pre' && node.properties['data-type'] === 'rehyp') {
96-
node.properties['className'].push(styles.rehyp);
97-
}
95+
{
96+
rewrite: (node: Element) => {
97+
if (
98+
node.type === 'element' &&
99+
node.tagName === 'pre' &&
100+
node.properties &&
101+
node.properties['data-type'] === 'rehyp' &&
102+
Array.isArray(node.properties.className)
103+
) {
104+
node.properties['className'].push(styles.rehyp);
105+
}
106+
},
98107
},
99108
],
100109
]}

0 commit comments

Comments
 (0)