@origints/markdown
Markdown parsing with GitHub Flavored Markdown support, YAML frontmatter extraction, and HTML conversion.
Installation
Section titled “Installation”npm install @origints/markdown @origints/coreFeatures
Section titled “Features”- GFM (GitHub Flavored Markdown) support
- YAML frontmatter extraction
- Source position tracking for all nodes
- Type-safe navigation and extraction
- Convert to HTML
- Tables, task lists, and footnotes
Usage with Planner
Section titled “Usage with Planner”Extract content
Section titled “Extract content”import { Planner, loadFile, run } from '@origints/core'import { parseMarkdown } from '@origints/markdown'
const plan = new Planner() .in(loadFile('README.md')) .mapIn(parseMarkdown()) .emit((out, $) => out .add('title', $.select('heading').text()) ) .compile()
const result = await run(plan, { readFile, registry })Extract collections
Section titled “Extract collections”.emit((out, $) => out .add('headings', $.selectAll('heading', node => node.text())))Children extraction
Section titled “Children extraction”.emit((out, $) => out .add('blocks', $.children(node => node.text())))Frontmatter
Section titled “Frontmatter”.emit((out, $) => out .add('frontmatter', $.select('yaml').text()))Standalone usage
Section titled “Standalone usage”import { parseMarkdownImpl, MarkdownNode } from '@origints/markdown'
const node = parseMarkdownImpl.execute(markdownString) as MarkdownNode
const heading = node.select('heading')if (heading.ok) console.log(heading.value.text())
// Attribute selectorsnode.select('heading[depth=1]')node.select('code[lang="typescript"]')HTML conversion
Section titled “HTML conversion”import { parseMarkdownImpl, toHtml } from '@origints/markdown'
const node = parseMarkdownImpl.execute('# Hello\n\nWorld') as MarkdownNodeconst html = toHtml(node)Frontmatter extraction
Section titled “Frontmatter extraction”import { parseMarkdownImpl, extractFrontmatter } from '@origints/markdown'
const node = parseMarkdownImpl.execute(markdownWithFrontmatter) as MarkdownNodeconst frontmatter = extractFrontmatter(node)if (frontmatter) console.log(frontmatter.title)| Export | Description |
|---|---|
parseMarkdown(options?) | Transform AST for Planner.mapIn() |
parseMarkdownImpl | Sync transform implementation |
parseMarkdownAsyncImpl | Async transform implementation |
registerMarkdownTransforms(registry) | Register Markdown transforms |
MarkdownNode | Navigable wrapper with selector support |
toHtml(node) | Convert to HTML |
extractFrontmatter(node) | Extract YAML frontmatter |
License
Section titled “License”MIT