Skip to main content

oak_typst/ast/
mod.rs

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