A lightweight markdown parser for React and Next.js projects.
I like to write in Markdown, and i use Obsidian extensively in my day to day. This is part of the reason why I wrote this simple utility tool.
I created this to mainly be used in my web portfolio, but feel free to try it out.
- Lightweight with no dependencies
- Supports headings, bold, italic, links, images, code blocks
- Frontmatter parsing for blog metadata
- React component friendly
Since this package isn't yet published to npm, you can install it locally using npm pack:
# from the demark directory, create a package
npm pack
# then from your project directory, install the generated .tgz file
npm install ../path/to/demark-1.0.0.tgzimport { parse } from "demark";
const markdown = "# Hello\n\nThis is **bold** text.";
const html = parse(markdown);import { parseDocument } from "demark";
const markdownWithFrontmatter = `---
title: "My Blog Post"
date: "2025-01-01"
tags: ["react", "markdown"]
---
# Hello World
Your content here...`;
const { frontmatter, content } = parseDocument(markdownWithFrontmatter);
// frontmatter.title = "My Blog Post"
// content = "<h1>Hello World</h1><p>Your content here...</p>"import { parseDocument } from "demark";
function BlogPost({ markdownContent }) {
const { frontmatter, content } = parseDocument(markdownContent);
return (
<article>
<h1>{frontmatter.title}</h1>
<div dangerouslySetInnerHTML={{ __html: content }} />
</article>
);
}parse(markdown)- Converts markdown to htmlparseDocument(markdown)- Parses frontmatter and content separatelycreateSlug(text)- Creates URL-friendly slugs from text
- Headings (
# ## ###) - Bold (
**text**) and Italic (_text_) - Links (
[text](url)) - Images (
) - Inline code (
`code`) and code blocks - Horizontal rules (
---)
---
title: "Post title"
date: "2025-01-01"
author: "Mr. Author"
tags: ["tag1", "tag2"]
featured: true
---