Having issues formatting markdown #34954
-
This is what my getPost data looks like
import fs from "fs";
import path from "path";
import matter from "gray-matter";
import { remark } from "remark";
import html from "remark-html";
// ------------------------------------------
export async function getPostData(id) {
const fullPath = path.join(postsDirectory, `${id}.md`);
const fileContents = fs.readFileSync(fullPath, "utf8");
// Use gray-matter to parse the post metadata section
const matterResult = matter(fileContents);
// Use remark to convert markdown into HTML string
const processedContent = await remark()
.use(html)
.process(matterResult.content);
const contentHtml = processedContent.toString();
// Combine the data with the id and contentHtml
return {
id,
contentHtml,
...matterResult.data,
};
} Here is the component<div className={main}>
<div className={ArticleContainer}>
<div dangerouslySetInnerHTML={{ __html: postData.contentHtml }} />
</div>
</div> here is a link to my project |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hi, You need to provide CSS that selects the elements inside the markdown, because markdown naturally breaks down into components like this: https://mdxjs.com/table-of-components/ Alternatively you could use a markdown renderer, for more into that please refer to this document: https://nextjs.org/blog/markdown#styling |
Beta Was this translation helpful? Give feedback.
-
I have the same problem and non of the solutions worked for me. There are no styles, even for I'm wondering why this happen because there are at least the default styles. For example, the paragraph spacing and |
Beta Was this translation helpful? Give feedback.
Hi,
You need to provide CSS that selects the elements inside the markdown, because markdown naturally breaks down into components like this: https://mdxjs.com/table-of-components/
Alternatively you could use a markdown renderer, for more into that please refer to this document: https://nextjs.org/blog/markdown#styling