This commit is contained in:
Noah Hellman 2022-11-28 21:52:09 +01:00
parent 217676d516
commit 2a2851178a

View file

@ -12,37 +12,132 @@ pub struct Block;
const EOF: char = '\0'; const EOF: char = '\0';
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub enum ListType { pub enum Event2<'s> {
Unordered, /// Start of a tag.
Ordered, Start(TagKind<'s>, Attributes<'s>),
/// End of a tag.
End(TagKind<'s>),
/// A string object, text only.
Str(&'s str),
/// A verbatim string.
Verbatim(&'s str),
/// An inline or display math element.
Math { content: &'s str, display: bool },
/// An ellipsis, i.e. a set of three periods.
Ellipsis,
/// An en dash.
EnDash,
/// An em dash.
EmDash,
/// A thematic break, typically a horizontal rule.
ThematicBreak,
/// A blank line.
Blankline,
/// A space that may not break a line.
NonBreakingSpace,
/// A newline that may or may not break a line in the output format.
Softbreak,
/// A newline that must break a line.
HardBreak,
} }
// Attributes are rare, better to pay 8 bytes always and sometimes an extra allocation instead of
// always 24 bytes.
#[derive(Debug, PartialEq, Eq)]
pub struct Attributes<'s>(Option<Box<Vec<(&'s str, &'s str)>>>);
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub enum TagKind<'s> { pub enum TagKind<'s> {
/// A paragraph.
Paragraph, Paragraph,
/// A heading.
Heading { level: u8 }, Heading { level: u8 },
Table, /// A link with a destination URL.
TableRow, Link(&'s str, LinkType),
TableCell, /// An image.
RawBlock { format: &'s str }, Image(&'s str),
CodeBlock { language: &'s str }, /// A divider element.
Blockquote,
Div, Div,
UnorderedList, /// An inline divider element.
OrderedList { start: usize }, Span,
/// A table element.
Table,
/// A row element of a table.
TableRow,
/// A cell element of row within a table.
TableCell,
/// A block with raw markup for a specific output format.
RawBlock { format: &'s str },
/// A block with code in a specific language.
CodeBlock { language: Option<&'s str> },
/// A blockquote element.
Blockquote,
/// A list.
List(List),
/// An item of a list
ListItem, ListItem,
/// A description list element.
DescriptionList, DescriptionList,
/// A item of a description list.
DescriptionItem, DescriptionItem,
/// A footnote definition.
Footnote { tag: &'s str }, Footnote { tag: &'s str },
} }
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub enum Event2<'s> { pub enum LinkType {
Start(TagKind<'s>), Inline,
End(TagKind<'s>), Reference,
Blankline, Autolink,
Email,
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum List {
Unordered,
Ordered {
kind: OrderedListKind,
start: u32,
format: OrderedListFormat,
},
Description,
Task(bool),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OrderedListKind {
/// Decimal numbering, e.g. `1)`.
Decimal,
/// Lowercase alphabetic numbering, e.g. `a)`.
AlphaLower,
/// Uppercase alphabetic numbering, e.g. `A)`.
AlphaUpper,
/// Lowercase roman numbering, e.g. `iv)`.
RomanLower,
/// Uppercase roman numbering, e.g. `IV)`.
RomanUpper,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OrderedListFormat {
/// Number is followed by a period, e.g. `1.`.
Period,
/// Number is followed by a closing parenthesis, e.g. `1)`.
Paren,
/// Number is enclosed by parentheses, e.g. `(1)`.
ParenParen,
}
/*
impl<'s> Event<'s> {
fn from_inline(src: &'s str, inline: inline::Event) -> Self {
match inline {
Enter
}
}
}
*/
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub enum Event { pub enum Event {
Start(block::Block), Start(block::Block),