File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ // Conditionally process pre blocks with CodeBlockWrapper or leave untouched.
3+ // Not all pre blocks should be rendered by the CodeBlockWrapper.
4+ // For example, mermaid diagram declarations should be left alone so that mermaid can process them.
5+ // In those cases, the diagram source isn't intended for the user.
6+
7+ import CodeBlockWrapper from ' ../CodeBlockWrapper/index.astro' ;
8+
9+ const props = Astro .props ;
10+
11+ // Check if this is a mermaid block
12+ // The 'data-language' or 'class' usually contains the language name
13+ const isMermaid = props .class ?.includes (' mermaid' ) || props [' data-language' ] === ' mermaid' ;
14+ ---
15+
16+ { isMermaid ? (
17+ <pre { ... props } ><slot /></pre >
18+ ) : (
19+ <CodeBlockWrapper { ... props } ><slot /></CodeBlockWrapper >
20+ )}
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import Head from "@components/Head/index.astro";
44import { getCurrentLocale , getUiTranslator } from " ../i18n/utils" ;
55import { setJumpToState } from " ../globals/state" ;
66import FreeRatioImage from " @components/Image/FreeRatioImage.astro" ;
7+ import PreProxy from " @components/PreProxy/index.astro" ;
78import CodeBlockWrapper from " @components/CodeBlockWrapper/index.astro" ;
89import LinkWrapper from " @components/LinkWrapper/index.astro" ;
910import RelatedItems from " @components/RelatedItems/index.astro" ;
@@ -68,7 +69,7 @@ const relatedExamples =
6869 components ={ {
6970 ... components ,
7071 img: FreeRatioImage ,
71- pre: CodeBlockWrapper ,
72+ pre: PreProxy ,
7273 a: LinkWrapper ,
7374 }}
7475 />
You can’t perform that action at this time.
0 commit comments