Skip to content

Commit a6e12f4

Browse files
fix: display changelog images (#552)
Signed-off-by: David Dal Busco <david.dalbusco@outlook.com>
1 parent be90c44 commit a6e12f4

6 files changed

Lines changed: 93 additions & 6 deletions

File tree

package-lock.json

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
"jsdom": "^27.0.0",
5757
"prettier": "^3.6.2",
5858
"prettier-plugin-organize-imports": "^4.3.0",
59+
"rehype-raw": "^7.0.0",
60+
"rehype-sanitize": "^6.0.0",
5961
"sass": "^1.93.2",
6062
"turndown": "^7.2.1",
6163
"typescript": "^5.9.3"

src/components/Markdown/index.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import ReactMarkdown from "react-markdown";
2+
import rehypeRaw from "rehype-raw";
3+
import rehypeSanitize, { defaultSchema } from "rehype-sanitize";
4+
import remarkGfm from "remark-gfm";
5+
import styles from "./styles.module.scss";
6+
7+
export const Markdown = ({ body }) => {
8+
const sanitizeSchema = {
9+
...defaultSchema,
10+
attributes: {
11+
...defaultSchema.attributes,
12+
img: [...(defaultSchema.attributes?.img || []), ["alt"], ["src"]]
13+
}
14+
};
15+
16+
return (
17+
<div className={styles.markdown}>
18+
<ReactMarkdown
19+
remarkPlugins={[remarkGfm]}
20+
rehypePlugins={[rehypeRaw, [rehypeSanitize, sanitizeSchema]]}
21+
>
22+
{body}
23+
</ReactMarkdown>
24+
</div>
25+
);
26+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.markdown {
2+
img {
3+
width: 100%;
4+
height: auto;
5+
}
6+
}

src/pages/changelog/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { GitHubRelease } from "@site/src/types/github";
44
import type { Props } from "@theme/BlogLayout";
55
import ReadMoreLink from "@theme/BlogPostItem/Footer/ReadMoreLink";
66
import clsx from "clsx";
7-
import Markdown from "react-markdown";
7+
import ReactMarkdown from "react-markdown";
88
import remarkGfm from "remark-gfm";
99

1010
export default function ChangelogPage(
@@ -18,9 +18,9 @@ export default function ChangelogPage(
1818
<div key={tag_name} id={tag_name}>
1919
<Release tag_name={tag_name} published_at={published_at} />
2020

21-
<Markdown remarkPlugins={[remarkGfm]}>
21+
<ReactMarkdown remarkPlugins={[remarkGfm]}>
2222
{body.length > 400 ? `${body.substring(0, 400)}...` : body}
23-
</Markdown>
23+
</ReactMarkdown>
2424

2525
{body.length > 400 && (
2626
<footer className="row docusaurus-mt-lg">

src/pages/release/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import Changelog from "@site/src/components/Changelog";
2+
import { Markdown } from "@site/src/components/Markdown";
23
import Release from "@site/src/components/Release";
34
import { GitHubRelease } from "@site/src/types/github";
45
import type { Props } from "@theme/BlogLayout";
5-
import Markdown from "react-markdown";
6-
import remarkGfm from "remark-gfm";
76
import styles from "./index.module.scss";
87

98
export default function ReleasePage(
@@ -25,7 +24,7 @@ export default function ReleasePage(
2524
<div key={tag_name} id={tag_name}>
2625
<Release tag_name={tag_name} published_at={published_at} />
2726

28-
<Markdown remarkPlugins={[remarkGfm]}>{body}</Markdown>
27+
<Markdown body={body} />
2928

3029
<footer className="row docusaurus-mt-lg">
3130
<div className="col text--left">

0 commit comments

Comments
 (0)