Skip to main content

oak_typst/ast/
mod.rs

1use core::range::Range;
2use serde::{Deserialize, Serialize};
3
4/// Typst AST 根节点
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct TypstRoot {
7    #[serde(with = "oak_core::serde_range")]
8    pub span: Range<usize>,
9    pub items: Vec<TypstItem>,
10}
11
12impl TypstRoot {
13    pub fn new(span: Range<usize>) -> Self {
14        Self { span, items: Vec::new() }
15    }
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
19pub enum TypstItem {
20    Text(String),
21    Space,
22    Parbreak,
23    Heading(TypstHeading),
24    Strong(TypstRoot),
25    Emphasis(TypstRoot),
26    Math(TypstRoot),
27    Quote(TypstRoot),
28    ListItem(TypstRoot),
29    EnumItem(TypstRoot),
30    Link(TypstLink),
31    Raw(String),
32    Block(TypstRoot),
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
36pub struct TypstHeading {
37    pub level: usize,
38    pub content: TypstRoot,
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize)]
42pub struct TypstLink {
43    pub url: String,
44    pub content: Option<TypstRoot>,
45}