oak_markdown/kind/
mod.rs

1use oak_core::SyntaxKind;
2use serde::{Deserialize, Serialize};
3
4#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
5pub enum MarkdownSyntaxKind {
6    // 基础文本
7    Text,
8    Whitespace,
9    Newline,
10
11    // 标题
12    Heading1,
13    Heading2,
14    Heading3,
15    Heading4,
16    Heading5,
17    Heading6,
18    HeadingText,
19
20    // 强调和加
21    Emphasis,      // *text* or _text_
22    Strong,        // **text** or __text__
23    Strikethrough, // ~~text~~
24
25    // 代码
26    InlineCode,   // `code`
27    CodeBlock,    // ```code```
28    CodeFence,    // ``` or ~~~
29    CodeLanguage, // language identifier in code block
30
31    // 链接和图
32    Link,
33    LinkText,
34    LinkUrl,
35    LinkTitle,
36    Image,
37    ImageAlt,
38    ImageUrl,
39    ImageTitle,
40
41    // 列表
42    UnorderedList,
43    OrderedList,
44    ListItem,
45    ListMarker, // -, *, +, 1., 2., etc.
46    TaskList,
47    TaskMarker, // [x] or [ ]
48
49    // 引用
50    Blockquote,
51    BlockquoteMarker, // >
52
53    // 分隔
54    HorizontalRule, // --- or *** or ___
55
56    // 表格
57    Table,
58    TableRow,
59    TableCell,
60    TableHeader,
61    TableSeparator, // |
62    TableAlignment, // :---, :---:, ---:
63
64    // HTML
65    HtmlTag,
66    HtmlComment,
67
68    // 转义字符
69    Escape, // \
70
71    // 特殊字符
72    LeftBracket,  // [
73    RightBracket, // ]
74    LeftParen,    // (
75    RightParen,   // )
76    LeftAngle,    // <
77    RightAngle,   // >
78    Asterisk,     // *
79    Underscore,   // _
80    Backtick,     // `
81    Tilde,        // ~
82    Hash,         // #
83    Pipe,         // |
84    Dash,         // -
85    Plus,         // +
86    Dot,          // .
87    Colon,        // :
88    Exclamation,  // !
89
90    // 错误处理
91    Error,
92
93    // 文档结构
94    Document,
95    Paragraph,
96
97    // EOF
98    Eof,
99}
100
101impl SyntaxKind for MarkdownSyntaxKind {
102    fn is_trivia(&self) -> bool {
103        matches!(self, Self::Whitespace | Self::Newline)
104    }
105
106    fn is_comment(&self) -> bool {
107        matches!(self, Self::HtmlComment)
108    }
109
110    fn is_whitespace(&self) -> bool {
111        matches!(self, Self::Whitespace | Self::Newline)
112    }
113
114    fn is_token_type(&self) -> bool {
115        !matches!(self, Self::Document | Self::Paragraph)
116    }
117
118    fn is_element_type(&self) -> bool {
119        matches!(self, Self::Document | Self::Paragraph)
120    }
121}