Skip to content

Commit e8f9269

Browse files
committed
[Docs Site] Use dedent in Markdown component
1 parent b50d8d2 commit e8f9269

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/components/Markdown.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
---
22
import { z } from "astro:schema";
33
import { marked } from "marked";
4+
import dedent from "dedent";
45
56
type Props = z.infer<typeof props>;
67
78
const props = z.object({
8-
text: z.string(),
9+
text: z.string().transform((val) => dedent(val)),
910
inline: z.boolean().default(true),
1011
});
1112

src/content/docs/style-guide/components/markdown.mdx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,27 @@ If you have a variable that needs to be formatted in any special way (for exampl
1818
<Markdown text={props.foo} />
1919
```
2020

21-
Note that you need to wrap your variable in curly braces, as well as use `text=` or this will not work.
21+
Note that you need to wrap your variable in curly braces, as well as use `text=` or this will not work.
22+
23+
## Multi-line strings
24+
25+
The Markdown component uses the [`dedent`](https://www.npmjs.com/package/dedent) library to remove indentation from multi-line strings.
26+
27+
This is because the [Commonmark spec](https://spec.commonmark.org/0.22/#indented-code-blocks) treats indented text as code blocks, unlike [MDX](https://mdxjs.com/docs/what-is-mdx/#:~:text=Indented%20code%20does%20not%20work%20in%20MDX%3A).
28+
29+
```mdx live
30+
import { Markdown } from "~/components";
31+
32+
<>
33+
<Markdown
34+
text={`
35+
You need to purchase [Magic WAN](https://www.cloudflare.com/magic-wan/) before you can purchase and use the Magic WAN Connector. The Magic WAN Connector can function as your primary edge device for your network, or be deployed in-line with existing network gear.
36+
37+
You also need to purchase a Magic WAN Connector before you can start configuring your settings in the Cloudflare dashboard. After buying a Magic WAN Connector, the device will be registered with your Cloudflare account and show up in your Cloudflare dashboard.
38+
39+
Contact your account representative to learn more about purchasing options for the Magic WAN Connector device.
40+
`}
41+
inline={false}
42+
/>
43+
</>
44+
```

0 commit comments

Comments
 (0)