mod command;
mod highlighter;
mod link;
mod list;
mod table;
use std::fmt::{self, Debug, Display, Formatter};
pub use crate::Value;
pub use command::{Command, CommandKind};
pub use highlighter::Highlighter;
pub use link::SmartLink;
pub use list::ListView;
use std::collections::HashMap;
pub use table::TableView;
pub use url::Url;
#[derive(Clone)]
pub struct TextRange {
pub start: (u64, u64),
pub end: (u64, u64),
}
impl Default for TextRange {
fn default() -> Self {
Self {
start: (0, 0),
end: (0, 0),
}
}
}
#[derive(Debug, Clone)]
pub enum AST {
None,
Statements(Vec<AST>),
Header {
level: usize,
children: Vec<AST>,
r: TextRange,
},
Paragraph {
children: Vec<AST>,
r: TextRange,
},
Highlight {
inner: Highlighter,
r: TextRange,
},
MathBlock {
inner: String,
r: TextRange,
},
TableView {
head: Vec<AST>,
align: Vec<Option<bool>>,
terms: Vec<Vec<AST>>,
column: usize,
r: TextRange,
},
List {
inner: ListView,
r: TextRange,
},
Normal {
inner: String,
r: TextRange,
},
Raw {
inner: String,
r: TextRange,
},
Code {
inner: String,
r: TextRange,
},
Italic {
children: Vec<AST>,
r: TextRange,
},
Bold {
children: Vec<AST>,
r: TextRange,
},
Emphasis {
children: Vec<AST>,
r: TextRange,
},
Underline {
children: Vec<AST>,
r: TextRange,
},
Strikethrough {
children: Vec<AST>,
r: TextRange,
},
Undercover {
children: Vec<AST>,
r: TextRange,
},
MathInline {
inner: String,
r: TextRange,
},
MathDisplay {
inner: String,
r: TextRange,
},
Link {
inner: SmartLink,
r: TextRange,
},
Escaped {
inner: char,
r: TextRange,
},
Command {
cmd: String,
args: Vec<Value>,
kvs: HashMap<String, Value>,
kind: CommandKind,
r: TextRange,
},
String {
inner: String,
r: TextRange,
},
Integer {
inner: String,
r: TextRange,
},
Decimal {
inner: String,
r: TextRange,
},
Boolean {
inner: bool,
r: TextRange,
},
Array {
inner: Vec<AST>,
r: TextRange,
},
}
impl Default for AST {
fn default() -> Self {
Self::None
}
}
impl Debug for TextRange {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "({}, {}) → ({}, {})", self.start.0, self.start.1, self.end.0, self.end.1)
}
}