#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct Span {
pub start: usize,
pub end: usize,
pub line: u32,
pub column: u32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BlockKind {
Document,
Paragraph,
Heading,
BlockQuote,
List,
ListItem,
FencedCode,
IndentedCode,
ThematicBreak,
HtmlBlock,
Table,
TableRow,
TableCell,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Alignment {
None,
Left,
Center,
Right,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ListData {
pub ordered: bool,
pub start: u64,
pub tight: bool,
pub marker: char,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Link {
pub href: String,
pub title: String,
pub image: bool,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct LinkDef {
pub dest: String,
pub title: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Inline {
Emphasis,
Strong,
Strikethrough,
Code,
Link(Link),
Image(Link),
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct InlineStyle {
pub emphasis: bool, pub strong: bool, pub code: bool, pub strikethrough: bool,
pub link: Option<Link>,
pub raw_html: bool,
}
impl InlineStyle {
pub fn is_plain(&self) -> bool {
!self.emphasis
&& !self.strong
&& !self.code
&& !self.strikethrough
&& self.link.is_none()
&& !self.raw_html
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct BlockData {
pub level: u8,
pub info: String,
pub list: Option<ListData>,
pub alignment: Vec<Alignment>,
pub html_raw_text: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Event {
EnterBlock {
block: BlockKind,
data: BlockData,
span: Span,
},
ExitBlock {
block: BlockKind,
span: Span,
},
Text {
text: String,
style: InlineStyle,
span: Span,
},
EnterInline {
inline: Inline,
span: Span,
},
ExitInline {
inline: Inline,
},
SoftBreak,
LineBreak,
}
impl Event {
pub fn text(s: impl Into<String>) -> Event {
Event::Text {
text: s.into(),
style: InlineStyle::default(),
span: Span::default(),
}
}
pub fn enter(block: BlockKind) -> Event {
Event::EnterBlock {
block,
data: BlockData::default(),
span: Span::default(),
}
}
pub fn exit(block: BlockKind) -> Event {
Event::ExitBlock {
block,
span: Span::default(),
}
}
}