From 7525fe0834e47bef425135e8cda1d576c44060a5 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 23 Apr 2026 16:57:33 +0800 Subject: Initialize Rust project with Markdown AST structure --- src/ast.rs | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/ast.rs (limited to 'src/ast.rs') 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, +} + +pub struct Line { + pub row: u32, + pub tokens: Vec, +} + +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, EmphasisStyle), + + // Lists + UnorderedList(Line, UnorderedListPrefix), + OrderedList(Line, u32), + + // Links + Link(Vec, Url, Option, 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>>, +} -- cgit