gomark 这是一个快速、可扩展且结构清晰的 Markdown 解析器,针对简单性和性能进行了优化。特点 - 快速、轻量级、高性能 - 可扩展 - 可配置 - 可定制 - 可测试 - 可移植 - 可部署 - 可持续 - 可维护 - 可重用 - 可复用 - 可扩展 - 可定制 - 可测试 - 可移植 - 可部署 - 可持续 - 可维护 - 可重用 - 可复用 - 可扩展 - 可定制 - 可测试 - 可移植 - 可部署 - 可持续 - 可维护 - 可重用 - 可复用 - 可扩展 - 可定制 - 可测试 - 可移植 - 可部署 - 可持续 - 可维护 - 可重用 - 可复
gomark 这是一个快速、可扩展且结构清晰的 Markdown 解析器,针对简单性和性能进行了优化。特点 - 快速、轻量级、高性能 - 可扩展 - 可配置 - 可定制 - 可测试 - 可移植 - 可部署 - 可持续 - 可维护 - 可重用 - 可复用 - 可扩展 - 可定制 - 可测试 - 可移植 - 可部署 - 可持续 - 可维护 - 可重用 - 可复用 - 可扩展 - 可定制 - 可测试 - 可移植 - 可部署 - 可持续 - 可维护 - 可重用 - 可复用 - 可扩展 - 可定制 - 可测试 - 可移植 - 可部署 - 可持续 - 可维护 - 可重用 - 可复
A fast, extensible, and well-structured markdown parser for Go, optimized for simplicity and performance.
$math$) and block ($$math$$) expressions==highlighted text==~sub~ and ^super^||spoiler text||#hashtag syntax[[wiki-style]] links![[embeds]], ` `, , , , and moregomark is designed for zero-configuration usage - all features are enabled by default:
…While gomark works great with zero configuration, you can customize it if needed:
import (
"github.com/usememos/gomark"
"github.com/usememos/gomark/config"
)
// Customize limits if needed
engine := gomark.NewEngine(gomark.WithConfig(
config.DefaultConfig().WithMaxDepth(100).WithMaxFileSize(1024 * 1024), // 1MB limit
))
doc, err := engine.Parse(markdown)import (
"github.com/usememos/gomark/renderer"
"github.com/usememos/gomark/renderer/html"
"github.com/usememos/gomark/renderer/string"
)
// Parse once, render to multiple formats
doc, _ := gomark.Parse(markdown)
// Render to HTML
htmlRenderer := html.NewHTMLRenderer()
htmlOutput := htmlRenderer.RenderDocument(doc)
// Extract plain text
stringRenderer := string.NewStringRenderer()
textOutput := stringRenderer.RenderDocument(doc)
// Render back to markdown (roundtrip)
markdownOutput := gomark.Restore(doc)import "github.com/usememos/gomark/config"
// Default configuration: all features enabled with generous limits
cfg := config.DefaultConfig()
// Custom limits if needed
cfg := config.DefaultConfig().
WithMaxDepth(50). // Limit nesting depth
WithMaxFileSize(1024 * 1024) // 1MB file size limitgomark follows a clean, modular architecture:
gomark/
├── ast/ # Abstract Syntax Tree definitions
├── config/ # Configuration management
├── parser/ # Parsing logic and tokenization
│ ├── internal/ # Parser implementations
│ ├── tokenizer/ # Tokenization engine
│ └── tests/ # Comprehensive parser tests
├── renderer/ # Output rendering
│ ├── html/ # HTML renderer
│ ├── markdown/ # Markdown renderer (roundtrip)
│ └── string/ # Plain text renderer
└── gomark.go # Main engine and public APIgomark is designed for performance:
All extensions can be configured via the config package:
cfg := config.DefaultConfig()
// Disable specific extensions
cfg = cfg.WithExtension("tables", false)
cfg = cfg.WithExtension("math", false)
// Enable strict parsing
cfg = cfg.WithStrictMode(true)
// Enable safe mode (sanitizes content)
cfg = cfg.WithSafeMode(true)| Extension | Default | Description |
|---|---|---|
tables |
✅ | GitHub-flavored table syntax |
strikethrough |
✅ | ~~strikethrough~~ text |
autolinks |
✅ | Automatic URL detection |
tasklists |
✅ | - [ ] and - [x] checkboxes |
math |
✅ | $inline$ and $$block$$ math |
highlighting |
✅ | ==highlighted== text |
subscript |
✅ | ~subscript~ text |
superscript |
✅ | ^superscript^ text |
spoilers |
✅ | ||spoiler|| text |
embedded |
✅ | ![[embedded]] content |
references |
✅ | [[referenced]] content |
tags |
✅ | #hashtag syntax |
, ` `, , , go test ./...This project is part of the Memos ecosystem.
Designed for simplicity, performance, and ease of use. gomark focuses on practical markdown parsing with clean, maintainable code.
暂无开放 Issues,或尚未同步最近议题。