GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - stacksjs/ts-md: Extremely performant markdown parser & compiler.

BranchesTags
Open more actions menu

Latest commit

 

History

91 Commits
91 Commits

Folders and files

NameName
Last commit message
Last commit date
.config
.config
 
 
.github
.github
 
 
.vscode
.vscode
 
 
benchmarks
benchmarks
 
 
bin
bin
 
 
docs
docs
 
 
fixtures
fixtures
 
 
src
src
 
 
test
test
 
 
.editorconfig
.editorconfig
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CLAUDE.md
CLAUDE.md
 
 
LICENSE.md
LICENSE.md
 
 
README.md
README.md
 
 
build.ts
build.ts
 
 
bun.lock
bun.lock
 
 
bunfig.toml
bunfig.toml
 
 
deps.yaml
deps.yaml
 
 
markdown.config.ts
markdown.config.ts
 
 
md
md
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

ts-md

High-performance markdown parser and sanitizer built for Bun.

Features

  • GitHub Flavored Markdown (GFM) support
  • Tables, task lists, strikethrough
  • Header ID generation
  • Syntax highlighting support
  • HTML sanitization
  • Frontmatter parsing (YAML, TOML, JSON)

Installation

bun add @stacksjs/ts-md

Usage

Basic Markdown Parsing

import { parseMarkdown } from '@stacksjs/ts-md'

const html = parseMarkdown('# Hello **world**')
// <h1 id="hello-world">Hello <strong>world</strong></h1>

With Options

const html = parseMarkdown(markdown, {
  gfm: true,              // GitHub Flavored Markdown (default: true)
  breaks: false,          // Convert \n to <br> (default: false)
  headerIds: true,        // Generate header IDs (default: true)
  headerPrefix: '',       // Prefix for header IDs (default: '')
  sanitize: false,        // Sanitize HTML output (default: false)
  highlight: (code, lang) => {
    // Custom syntax highlighting
    return highlightedCode
  }
})

HTML Sanitization

import { sanitizeHtml } from '@stacksjs/ts-md'

const clean = sanitizeHtml(userInput, {
  allowedTags: ['p', 'strong', 'em', 'a', 'code'],
  allowedAttributes: {
    a: ['href', 'title']
  },
  allowedSchemes: ['http', 'https', 'mailto']
})

Frontmatter Parsing

import { parseFrontmatter } from '@stacksjs/ts-md'

const content = `---
title: My Post
date: 2024-01-01
---

# Content here`

const { data, content: markdown } = parseFrontmatter(content)
console.log(data.title) // 'My Post'

Performance

Benchmark results against popular markdown parsers:

Document Size @stacksjs/ts-md markdown-it marked showdown
Small (< 1KB) 324B ops/sec 112B ops/sec 26B ops/sec 14B ops/sec
Medium (~3KB) 34.7B ops/sec 17.7B ops/sec 2.8B ops/sec 2.8B ops/sec
Large (~50KB) 1.81B ops/sec 1.25B ops/sec 16M ops/sec 135M ops/sec

Performance vs markdown-it:

  • Small documents: 2.89x faster
  • Medium documents: 1.96x faster
  • Large documents: 1.45x faster

The parser uses a flat token stream architecture with position-based parsing for optimal performance.

Architecture

The markdown parser is built with several key optimizations:

  • Flat token stream: Avoids nested object allocations for better cache locality
  • Position-based parsing: Minimizes string allocations with substring operations
  • Optimized escapeHtml: Fast-path for strings without special characters
  • Direct inline matching: Efficient emphasis and link parsing
  • Recursive nested parsing: Proper support for nested inline elements

API

parseMarkdown(markdown: string, options?: MarkdownOptions): string

Parse markdown to HTML.

sanitizeHtml(html: string, options?: SanitizeOptions): string

Sanitize HTML to prevent XSS attacks.

parseFrontmatter(content: string): { data: any, content: string }

Extract and parse frontmatter from markdown content. Supports YAML, TOML, and JSON formats.

License

MIT

About

Extremely performant markdown parser & compiler.

Topics

compilermarkdownmarkdown-itmarkedparser

Resources

Readme
MIT license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy
Activity
Custom properties

Stars

3 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Sponsor this project

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.