diff --git a/Cargo.lock b/Cargo.lock index ecf4146..bd0aae4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -571,7 +571,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "snekdown" -version = "0.18.2" +version = "0.18.3" dependencies = [ "charred 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 64d98cd..0ae2052 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snekdown" -version = "0.18.2" +version = "0.18.3" authors = ["trivernis "] edition = "2018" license-file = "LICENSE" diff --git a/src/parser/inline.rs b/src/parser/inline.rs index e714bdb..25e5eaa 100644 --- a/src/parser/inline.rs +++ b/src/parser/inline.rs @@ -119,17 +119,20 @@ impl ParseInline for Parser { self.ctm.seek_one()?; self.inline_break_at.push(DESC_CLOSE); - while let Ok(inline) = self.parse_inline() { - description.push(inline); - if self.ctm.check_char(&DESC_CLOSE) { - break; + // only parse the description as inline if there is a description + if !self.ctm.check_char(&DESC_CLOSE) { + while let Ok(inline) = self.parse_inline() { + description.push(inline); + if self.ctm.check_char(&DESC_CLOSE) { + break; + } } } self.inline_break_at.pop(); + self.ctm.seek_one()?; } else if !short_syntax { return Err(self.ctm.rewind_with_error(start_index)); } - self.ctm.seek_one()?; self.ctm.assert_char(&URL_OPEN, Some(start_index))?; self.ctm.seek_one()?; self.ctm.seek_any(&INLINE_WHITESPACE)?; diff --git a/src/parser/line.rs b/src/parser/line.rs index 2faafab..d9bc785 100644 --- a/src/parser/line.rs +++ b/src/parser/line.rs @@ -121,35 +121,6 @@ impl ParseLine for Parser { } } - fn parse_bib_entry(&mut self) -> ParseResult>> { - let start_index = self.ctm.get_index(); - self.ctm.seek_any(&INLINE_WHITESPACE)?; - self.ctm.assert_char(&BIB_KEY_OPEN, Some(start_index))?; - self.ctm.seek_one()?; - let key = - self.ctm - .get_string_until_any_or_rewind(&[BIB_KEY_CLOSE], &[LB, SPACE], start_index)?; - self.ctm.seek_one()?; - self.ctm.assert_char(&BIB_DATA_START, Some(start_index))?; - self.ctm.seek_one()?; - self.ctm.seek_any(&INLINE_WHITESPACE)?; - - let entry = if let Ok(meta) = self.parse_inline_metadata() { - BibEntry::from_metadata(key, Box::new(meta), &self.document.config) - } else { - let url = self - .ctm - .get_string_until_any_or_rewind(&[LB], &[], start_index)?; - BibEntry::from_url(key, url, &self.document.config) - }; - let entry_ref = Arc::new(RwLock::new(entry)); - self.document - .bibliography - .add_bib_entry(Arc::clone(&entry_ref)); - - Ok(entry_ref) - } - /// parses centered text fn parse_centered(&mut self) -> ParseResult { let start_index = self.ctm.get_index(); @@ -192,4 +163,33 @@ impl ParseLine for Parser { Err(self.ctm.err()) } } + + fn parse_bib_entry(&mut self) -> ParseResult>> { + let start_index = self.ctm.get_index(); + self.ctm.seek_any(&INLINE_WHITESPACE)?; + self.ctm.assert_char(&BIB_KEY_OPEN, Some(start_index))?; + self.ctm.seek_one()?; + let key = + self.ctm + .get_string_until_any_or_rewind(&[BIB_KEY_CLOSE], &[LB, SPACE], start_index)?; + self.ctm.seek_one()?; + self.ctm.assert_char(&BIB_DATA_START, Some(start_index))?; + self.ctm.seek_one()?; + self.ctm.seek_any(&INLINE_WHITESPACE)?; + + let entry = if let Ok(meta) = self.parse_inline_metadata() { + BibEntry::from_metadata(key, Box::new(meta), &self.document.config) + } else { + let url = self + .ctm + .get_string_until_any_or_rewind(&[LB], &[], start_index)?; + BibEntry::from_url(key, url, &self.document.config) + }; + let entry_ref = Arc::new(RwLock::new(entry)); + self.document + .bibliography + .add_bib_entry(Arc::clone(&entry_ref)); + + Ok(entry_ref) + } }