A markdown parser and compiler written in TypeScript
- Complete Markdown Parser: Supports headers, bold, italic, strikethrough, lists, blockquotes, links, and more
- Math Expressions: Parse mathematical notation with superscript (
^) and subscript (~) support - Checklists: Support for GitHub-style task lists with
- [ ]and- [x] - TypeScript: Fully typed codebase with comprehensive test coverage
- Modular Architecture: Separate lexer, parser, AST, and renderer components
- Headers:
# H1through###### H6 - Text Formatting:
**bold**,*italic*,~~strikethrough~~ - Lists:
- Unordered:
* itemor- item - Checklists:
- [ ] todoand- [x] done
- Unordered:
- Blockquotes:
> quoted text - Links:
[text](url) - Code:
`inline code` - Math:
$x^2 + y~1$with superscript and subscript - Horizontal Rules:
---
- Run tests with
npm test - Run with
ts-node src/index.ts
The project includes comprehensive test coverage with 103 tests across all components:
- Token Tests: 56 tests covering lexical analysis
- AST Tests: 35 tests for abstract syntax tree nodes
- Lexer Tests: 10 tests for tokenization
- Renderer Tests: 15 tests for HTML output generation
- Interpreter Tests: 9 tests for end-to-end processing
- Parser Tests: 13 tests for syntax parsing
All tests are written in TypeScript and use Jest as the testing framework.
The parser follows a traditional compiler architecture:
- Lexer (
src/Lexer.ts): Tokenizes markdown input - Parser (
src/Parser.ts): Builds an Abstract Syntax Tree (AST) - AST (
src/Ast.ts): Node types representing markdown elements - Renderer (
src/Renderer.ts): Converts AST to HTML output
# Install dependencies
npm install
# Run tests
npm test
# Run the parser
ts-node src/index.ts
# Compile TypeScript
npx tsc