use super::node::Node;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, PartialEq, Clone, Default)]
pub struct Document<T>(pub Vec<Block<T>>);
impl<T> std::ops::Deref for Document<T> {
type Target = [Block<T>];
fn deref(&self) -> &[Block<T>] {
&self.0
}
}
impl<T> std::ops::DerefMut for Document<T> {
fn deref_mut(&mut self) -> &mut [Block<T>] {
&mut self.0
}
}
impl<T> IntoIterator for Document<T> {
type Item = Block<T>;
type IntoIter = std::vec::IntoIter<Block<T>>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
impl<'a, T> IntoIterator for &'a Document<T> {
type Item = &'a Block<T>;
type IntoIter = std::slice::Iter<'a, Block<T>>;
fn into_iter(self) -> Self::IntoIter {
self.0.iter()
}
}
impl<'a, T> IntoIterator for &'a mut Document<T> {
type Item = &'a mut Block<T>;
type IntoIter = std::slice::IterMut<'a, Block<T>>;
fn into_iter(self) -> Self::IntoIter {
self.0.iter_mut()
}
}
impl<T> From<Vec<Block<T>>> for Document<T> {
fn from(v: Vec<Block<T>>) -> Self {
Document(v)
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, PartialEq, Clone)]
pub struct Block<T> {
pub indent: usize,
pub content: BlockContent<T>,
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
#[derive(Debug, PartialEq, Clone)]
pub enum BlockContent<T> {
Line(Vec<Node<T>>),
CodeBlock {
meta: CodeBlockMeta,
content: String,
},
Table {
name: String,
rows: Vec<Vec<Vec<Node<T>>>>,
},
Quote(Vec<Node<T>>),
Helpfeel(String),
CommandLine {
prompt: ShellPrompt,
command: String,
},
Custom(T),
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum ShellPrompt {
Dollar,
Percent,
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
#[derive(Debug, PartialEq, Clone)]
pub enum CodeBlockMeta {
None,
NameOrLang(String),
Both {
filename: String,
language: String,
},
}