Use unified, add header ids

This commit is contained in:
Endeavorance 2025-05-27 17:00:12 -04:00
parent 5c6ef03082
commit 6f4b2d20da
7 changed files with 271 additions and 6 deletions

View file

@ -49,7 +49,6 @@ h1 {
h2 {
font-size: 2.5rem;
text-align: center;
}
h3 {

View file

@ -10,6 +10,7 @@ import defaultTemplate from "./defaults/default-template.html" with {
};
import { CLIError } from "./error";
import type { BunFile } from "bun";
import { parseMarkdown } from "./markdown";
const DEFAULT_TEMPLATE_FILE = "_template.html";
const DEFAULT_STYLESHEET_FILE = "_style.css";
@ -155,9 +156,7 @@ async function buildFile(
content: string;
};
const html = await marked.parse(content, {
gfm: true,
});
const html = await parseMarkdown(content);
const title = [options.title, props.title].find((t) => t) || "Untitled";

20
src/markdown.ts Normal file
View file

@ -0,0 +1,20 @@
import rehypeRaw from "rehype-raw";
import remarkGfm from "remark-gfm";
import rehypeStringify from "rehype-stringify";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import rehypeSlug from "rehype-slug";
import { unified } from "unified";
export async function parseMarkdown(markdown: string): Promise<string> {
const file = await unified()
.use(remarkParse)
.use(remarkGfm)
.use(remarkRehype, { allowDangerousHtml: true })
.use(rehypeRaw)
.use(rehypeSlug)
.use(rehypeStringify)
.process(markdown);
return String(file);
}