From 1d92666865b35341e076efbefddf6e73b5e1542e Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 7 Sep 2022 15:53:06 +0200 Subject: Add support for recoverable syntax errors --- src/parser.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/parser.rs') diff --git a/src/parser.rs b/src/parser.rs index 62b3e03..3a7713a 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -26,7 +26,7 @@ pub struct ParseState<'a> { /// Turn a string of markdown into events. /// /// Passes the bytes back so the compiler can access the source. -pub fn parse<'a>(value: &'a str, options: &'a Options) -> (Vec, &'a [u8]) { +pub fn parse<'a>(value: &'a str, options: &'a Options) -> Result<(Vec, &'a [u8]), String> { let mut parse_state = ParseState { options, bytes: value.as_bytes(), @@ -49,7 +49,7 @@ pub fn parse<'a>(value: &'a str, options: &'a Options) -> (Vec, &'a [u8]) (parse_state.bytes.len(), 0), State::Next(StateName::DocumentStart), ); - tokenizer.flush(state, true); + tokenizer.flush(state, true)?; let mut events = tokenizer.events; @@ -58,7 +58,7 @@ pub fn parse<'a>(value: &'a str, options: &'a Options) -> (Vec, &'a [u8]) parse_state.gfm_footnote_definitions = footnote; parse_state.definitions = normal; - while !subtokenize(&mut events, &parse_state) {} + while !(subtokenize(&mut events, &parse_state)?) {} - (events, parse_state.bytes) + Ok((events, parse_state.bytes)) } -- cgit