diff --git a/src/syntax/content/parser/context.rs b/src/syntax/content/parser/context.rs index aeda3cd..3e8d30e 100644 --- a/src/syntax/content/parser/context.rs +++ b/src/syntax/content/parser/context.rs @@ -1,6 +1,8 @@ use crate::syntax::content::parser::{ state::State, - token::{Token, paragraph::Paragraph, preformat::PreFormat}, + token::{ + Token, header::Header, paragraph::Paragraph, preformat::PreFormat, + }, }; pub mod block; @@ -31,7 +33,7 @@ pub enum Inline { } /// # Panics -/// Panics if there is an open header at end of input. +/// Panics if there is an open header or list at end of input. pub fn close(state: &State, tokens: &mut Vec) { match state.context.block { Block::PreFormat => { @@ -43,7 +45,9 @@ pub fn close(state: &State, tokens: &mut Vec) { Block::List => { panic!("End of input with open list") }, - Block::Header(_) => panic!("End of input with open header"), + Block::Header(level) => { + tokens.push(Token::Header(Header::from_u8(level, false, None))); + }, Block::None => (), } } diff --git a/src/syntax/content/parser/context/block.rs b/src/syntax/content/parser/context/block.rs index 4dfede6..03a6c97 100644 --- a/src/syntax/content/parser/context/block.rs +++ b/src/syntax/content/parser/context/block.rs @@ -90,16 +90,15 @@ pub fn parse( mod tests { use crate::{ - types::Graph, - syntax::content::{ - parser, - parser::{ - token::{preformat::PreFormat}, - state::State, - token::header::Level, - Block, context, Token, + syntax::content::parser::{ + self, Block, Token, context, + state::State, + token::{ + header::{Header, Level}, + preformat::PreFormat, }, }, + types::Graph, }; fn read(input: &str) -> String { @@ -125,12 +124,13 @@ mod tests { } #[test] - #[should_panic(expected = "End of input with open header")] fn end_with_open_header() { let mut state = State::default(); state.context.block = Block::Header(1); - context::close(&state, &mut vec![]); + let mut vec: Vec = vec![]; + context::close(&state, &mut vec); + assert_eq!(vec, vec![Token::Header(Header::from_u8(1, false, None))]); } #[test]