Node is empty when using remarkGfm and react-remark #1469
Answered
by
remcohaszing
bouteillerAlan
asked this question in
Q&A
-
|
It's seem I'm missing something, when I want to use I have followed the example here: https://github.com/remarkjs/react-remark?tab=readme-ov-file#pass-options-to-component
The resulting is: <div class="markdown-reader"><div class="reader-content"></div></div>My component: import { useEffect } from "react";
import { Remark } from "react-remark";
import remarkGfm from "remark-gfm";
import rehypeHighlight from "rehype-highlight";
import rehypeStringify from "rehype-stringify";
import "highlight.js/styles/github.min.css";
import "highlight.js/styles/github-dark.css";
interface MarkdownReaderProps {
content: string;
filePath: string | null;
}
const MarkdownReader: React.FC<MarkdownReaderProps> = ({ content, filePath }) => {
useEffect(() => {
console.log(content);
}, [content])
if (!filePath) {
return (
<div className="reader-empty">
<p>Select a markdown file to view its content</p>
</div>
);
}
if (!content.trim()) {
return (
<div className="reader-empty">
<p>This file is empty</p>
<p>Switch to editor mode to add content</p>
</div>
);
}
return (
<div className="markdown-reader">
<div className="reader-content">
<Remark
remarkPlugins={[remarkGfm]}
remarkToRehypeOptions={{ allowDangerousHtml: true }}
rehypePlugins={[rehypeHighlight, rehypeStringify]}
>
{content}
</Remark>
</div>
</div>
);
};
export default MarkdownReader; |
Beta Was this translation helpful? Give feedback.
Answered by
remcohaszing
Dec 9, 2025
Replies: 1 comment 1 reply
-
|
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
bouteillerAlan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
react-rehypehasn’t been updated for a while. Tryreact-markdowninstead.