File tree 2 files changed +20
-3
lines changed
2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import type { AProps } from '@/types';
23
23
import { CodeFullFeatured , CodeLite } from './CodeBlock' ;
24
24
import type { TypographyProps } from './Typography' ;
25
25
import { useStyles as useMarkdownStyles } from './markdown.style' ;
26
+ import { rehypeKatexDir } from './rehypePlugin' ;
26
27
import { useStyles } from './style' ;
27
28
import { escapeBrackets , escapeMhchem , fixMarkdownBold } from './utils' ;
28
29
@@ -139,9 +140,12 @@ const Markdown = memo<MarkdownProps>(
139
140
140
141
const memoRehypePlugins = useMemo (
141
142
( ) =>
142
- [ allowHtml && rehypeRaw , enableLatex && rehypeKatex , ...innerRehypePlugins ] . filter (
143
- Boolean ,
144
- ) as any ,
143
+ [
144
+ allowHtml && rehypeRaw ,
145
+ enableLatex && rehypeKatex ,
146
+ enableLatex && rehypeKatexDir ,
147
+ ...innerRehypePlugins ,
148
+ ] . filter ( Boolean ) as any ,
145
149
[ allowHtml , enableLatex , ...innerRehypePlugins ] ,
146
150
) ;
147
151
Original file line number Diff line number Diff line change
1
+ // katex-directive
2
+ // 给 class="katex" 的节点加上 dir="ltr" 属性
3
+ import type { Node } from 'unist' ;
4
+ import { visit } from 'unist-util-visit' ;
5
+
6
+ // eslint-disable-next-line unicorn/consistent-function-scoping
7
+ export const rehypeKatexDir = ( ) => ( tree : Node ) => {
8
+ visit ( tree , 'element' , ( node : any ) => {
9
+ if ( node . properties ?. className ?. includes ( 'katex' ) ) {
10
+ node . properties . dir = 'ltr' ;
11
+ }
12
+ } ) ;
13
+ } ;
You can’t perform that action at this time.
0 commit comments