Fix image short syntax

feature/epub-rendering
trivernis 4 years ago
parent 47e6490203
commit 5f7d9f8de1

2
Cargo.lock generated

@ -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)",

@ -1,6 +1,6 @@
[package]
name = "snekdown"
version = "0.18.2"
version = "0.18.3"
authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018"
license-file = "LICENSE"

@ -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)?;

@ -121,35 +121,6 @@ impl ParseLine for Parser {
}
}
fn parse_bib_entry(&mut self) -> ParseResult<Arc<RwLock<BibEntry>>> {
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<Centered> {
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<Arc<RwLock<BibEntry>>> {
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)
}
}

Loading…
Cancel
Save