${styledCode}`;
},
langPrefix: "language-",
}),
);
// Configure marked with custom renderer
const renderer = new marked.Renderer();
// Custom inline code renderer
renderer.codespan = function (token: Tokens.Codespan) {
return `${token.text}`;
};
// Custom header renderer with IDs and styling
renderer.heading = function (token: Tokens.Heading) {
const text = this.parser.parseInline(token.tokens);
const level = token.depth;
const id = text
.toLowerCase()
.replace(/<[^>]+>/g, "") // Strip HTML tags
.replace(/[^\w\s-]/g, "") // Remove special characters
.replace(/\s+/g, "-") // Replace spaces with hyphens
.trim();
const styles = {
1: "text-xl font-semibold text-white mt-8 mb-4",
2: "text-lg font-semibold text-white mt-8 mb-3",
3: "text-base font-medium text-zinc-100 mt-6 mb-3",
4: "text-sm font-medium text-zinc-200 mt-4 mb-2",
5: "text-xs font-medium text-zinc-200 mt-4 mb-2",
6: "text-xs font-medium text-zinc-300 mt-3 mb-2",
};
return `${text} `;
};
// Custom link renderer to handle .md links
renderer.link = function (token: Tokens.Link) {
let href = token.href;
const title = token.title;
const text = this.parser.parseInline(token.tokens);
// Convert relative .md links to docs routes
if (href.endsWith(".md") && !href.startsWith("http")) {
const slug = href.replace(/^\.\//, "").replace(/\.md$/, "");
href = `/docs/${slug}`;
}
const titleAttr = title ? ` title="${title}"` : "";
return `${text}`;
};
// Custom paragraph renderer
renderer.paragraph = function (token: Tokens.Paragraph) {
const text = this.parser.parseInline(token.tokens);
return `${text}
`;
};
// Custom list renderer - just add styling classes
renderer.list = function (token: Tokens.List) {
const ordered = token.ordered;
const tag = ordered ? "ol" : "ul";
const listStyle = ordered ? "list-decimal" : "list-disc";
// Use default marked behavior for rendering items
let body = "";
for (let i = 0; i < token.items.length; i++) {
body += this.listitem(token.items[i]);
}
return `<${tag} class="${listStyle} list-inside my-3 text-zinc-400">${body}${tag}>`;
};
renderer.listitem = function (token: Tokens.ListItem) {
let text = "";
if (token.task) {
const checkbox = ``;
if (token.loose) {
if (token.tokens.length > 0 && token.tokens[0].type === "paragraph") {
token.tokens[0].text = checkbox + " " + token.tokens[0].text;
if (
token.tokens[0].tokens && token.tokens[0].tokens.length > 0 &&
token.tokens[0].tokens[0].type === "text"
) {
token.tokens[0].tokens[0].text = checkbox + " " +
token.tokens[0].tokens[0].text;
}
} else {
token.tokens.unshift(
{ type: "text", raw: checkbox + " ", text: checkbox + " " } as Tokens.Text,
);
}
} else {
text += checkbox + " ";
}
}
text += this.parser.parse(token.tokens, !!token.loose);
return `