Skip to content

API Reference

Converts a Markdown string into HTML and a Table of Contents (TOC) structure.

function parse(md: string): {
html: string;
toc: TOCItem[];
};
  • md (string): Markdown input to be parsed.

An object containing:

  • html (string): The rendered HTML string.
  • toc (TOCItem[]): A list of TOC entries generated from headings.
interface TOCItem {
id: string; // The slugified heading ID
title: string; // The original heading text
level: number; // Heading level (e.g., 1 for h1, 2 for h2)
}
import { markdom } from '@tenedev/markdom';
const markdown = `
# Title
## Subtitle
`;
const { html, toc } = markdom.parse(markdown);
console.log(html);
/*
<h1 id="title"><a href="#title">🔗</a> Title</h1>
<h2 id="subtitle"><a href="#subtitle">🔗</a> Subtitle</h2>
*/
console.log(toc);
/*
[
{ id: "title", title: "Title", level: 1 },
{ id: "subtitle", title: "Subtitle", level: 2 }
]
*/

This API is synchronous and does not require any file I/O.