Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub enum Leaf<'s> {

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Container<'s> {
Document,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of a document start and end as events.

Blockquote,
Div { class: &'s str },
List { ty: ListType, tight: bool },
Expand Down Expand Up @@ -223,6 +224,8 @@ impl<'s> TreeParser<'s> {

#[must_use]
fn parse(mut self) -> Vec<Event<'s>> {
self.enter(Node::Container(Document), 0..0);

let mut lines = lines(self.src).collect::<Vec<_>>();
let mut line_pos = 0;
while line_pos < lines.len() {
Expand All @@ -239,7 +242,10 @@ impl<'s> TreeParser<'s> {
for _ in std::mem::take(&mut self.open_sections).drain(..) {
self.exit(self.src.len()..self.src.len());
}

self.exit(self.src.len()..self.src.len()); // Document
debug_assert_eq!(self.open, &[]);

self.events
}

Expand Down Expand Up @@ -1317,7 +1323,11 @@ mod test {
($src:expr $(,$($event:expr),* $(,)?)?) => {
let t = super::TreeParser::new($src).parse();
let actual = t.into_iter().map(|ev| (ev.kind, &$src[ev.span])).collect::<Vec<_>>();
let expected = &[$($($event),*,)?];
let expected = &[
(Enter(Container(Document)), ""),
$($($event),*,)?
(Exit(Container(Document)), ""),
];
assert_eq!(
actual,
expected,
Expand Down
Loading