diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-04-23 16:57:33 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-04-23 16:57:33 +0800 |
| commit | 7525fe0834e47bef425135e8cda1d576c44060a5 (patch) | |
| tree | 0d9367b7f0aa0b3542f165095c10ab698b3b2c05 /src/ast.rs | |
| parent | 277bc93f84b298c7cb24e136f67eb237fb3a68a2 (diff) | |
Initialize Rust project with Markdown AST structure
Diffstat (limited to 'src/ast.rs')
| -rw-r--r-- | src/ast.rs | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/ast.rs b/src/ast.rs new file mode 100644 index 0000000..49cfd6f --- /dev/null +++ b/src/ast.rs @@ -0,0 +1,95 @@ +use std::collections::HashMap; + +pub mod parser; +pub mod renderer; + +pub struct MarkdownAST { + pub root: Layer, +} + +pub type Level = u8; +pub type Lang = String; +pub type Title = String; +pub type Url = String; + +pub struct Layer { + pub range_row_begin: u32, + pub range_row_end: u32, + pub lines: Vec<Line>, +} + +pub struct Line { + pub row: u32, + pub tokens: Vec<Token>, +} + +pub struct Token { + pub begin_row: u32, + pub begin_col: u16, + pub end_row: u32, + pub end_col: u16, + pub token: TokenData, +} + +pub enum TokenData { + Normal(Fragment), + Newline, + Newlayer(Layer), + + // Headings + Heading(Level, Line, Layer), + + // Emphasis + Emphasis(Vec<TokenData>, EmphasisStyle), + + // Lists + UnorderedList(Line, UnorderedListPrefix), + OrderedList(Line, u32), + + // Links + Link(Vec<Fragment>, Url, Option<Title>, LinkType), + + // Code + InlineCode(Vec<Fragment>), + CodeBlock(Vec<Line>, Option<Lang>), + + // Blockquotes + Blockquotes(Layer), + + // HorizontalRule + HorizontalRule(HorizontalRuleType), + + // Table + Table(Table), +} + +pub struct Fragment { + pub str: String, +} + +pub struct EmphasisStyle { + pub bold: bool, + pub italic: bool, + pub strikethrough: bool, +} + +pub enum UnorderedListPrefix { + Star, + Dash, + Plus, +} + +pub enum LinkType { + Image, + Url, +} + +pub enum HorizontalRuleType { + Stars, + Dashes, + Underscores, +} + +pub struct Table { + pub contents: HashMap<(u32, u32), Vec<Fragment>>, +} |
