Skip to content

Commit baad9b7

Browse files
committed
Add PreProxy component that calls CodeBlockWrapper if pre is not for mermaid
1 parent bafdcd4 commit baad9b7

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
)}

src/layouts/TutorialLayout.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Head from "@components/Head/index.astro";
44
import { getCurrentLocale, getUiTranslator } from "../i18n/utils";
55
import { setJumpToState } from "../globals/state";
66
import FreeRatioImage from "@components/Image/FreeRatioImage.astro";
7+
import PreProxy from "@components/PreProxy/index.astro";
78
import CodeBlockWrapper from "@components/CodeBlockWrapper/index.astro";
89
import LinkWrapper from "@components/LinkWrapper/index.astro";
910
import 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
/>

0 commit comments

Comments
 (0)