Files
YunShu/pkg/mdprint/mdprint.go
titor d2b9b2c4bb refactor: 项目结构重组,src/ 扁平化为根目录,提取 pkg/ 子包
- 模块名重命名 yunshu -> hub.gaomia.site/titor/YunShu
- Go 版本升级 1.21 -> 1.25
- src/ 目录删除,所有文件移至根目录
- 新增 pkg/mdprint/: Markdown AST 解析+ANSI 渲染
- 新增 pkg/style/: 终端颜色样式(8色 ANSI + 24位真彩色)
- 新增 pkg/termui/: 终端输入组件(交互式输入/密码/确认)
- 更新文档:AGENTS.md、architecture.md、changelog.md、taolun.md
- gitignore 通配符修复 yunshu.exe -> yunshu.exe*
2026-05-09 03:55:56 +08:00

53 lines
1.3 KiB
Go

package mdprint
import "fmt"
// Node is the interface for all AST nodes.
type Node interface{ isNode() }
// ---- block-level ----
type Heading struct{ Level int; Content []Node }
type Paragraph struct{ Content []Node }
type CodeBlock struct{ Lang, Body string }
type Blockquote struct{ Children []Node }
type List struct{ Ordered bool; Items []ListItem }
type ListItem struct{ Checked *bool; Content []Node }
type Table struct{ Headers []string; Rows [][]string }
type ThematicBreak struct{}
// ---- inline-level ----
type Text struct{ Text string }
type Bold struct{ Content []Node }
type Italic struct{ Content []Node }
type Code struct{ Text string }
type Link struct{ Content []Node; URL string }
func (Heading) isNode() {}
func (Paragraph) isNode() {}
func (CodeBlock) isNode() {}
func (Blockquote) isNode() {}
func (List) isNode() {}
func (ListItem) isNode() {}
func (Table) isNode() {}
func (ThematicBreak) isNode() {}
func (Text) isNode() {}
func (Bold) isNode() {}
func (Italic) isNode() {}
func (Code) isNode() {}
func (Link) isNode() {}
// Print parses Markdown content and renders it to the terminal.
func Print(content string) {
blocks := parseBlocks(content)
for i, b := range blocks {
if i > 0 {
fmt.Println()
}
fmt.Print(renderNode(b))
}
fmt.Println()
}