From a7deb829665228d285f8dbc4ec82908f0afb2b00 Mon Sep 17 00:00:00 2001 From: trivernis Date: Mon, 1 Jun 2020 21:37:04 +0200 Subject: [PATCH] Change placeholder behaviour to be global and not document-scoped --- src/parsing/parser.rs | 13 ++++++++----- src/parsing/placeholders.rs | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/parsing/parser.rs b/src/parsing/parser.rs index 110206e..abe6814 100644 --- a/src/parsing/parser.rs +++ b/src/parsing/parser.rs @@ -255,7 +255,9 @@ impl Parser { let wg = self.wg.clone(); self.wg = WaitGroup::new(); wg.wait(); - self.document.process_placeholders(); + if !self.is_child { + self.document.process_placeholders(); + } let document = self.document.clone(); self.document = Document::new(!self.is_child); @@ -453,13 +455,14 @@ impl Parser { value = MetadataValue::Placeholder(ph); } else { let quoted_string = self.check_special_group("ES); - let parse_until: &[char] = if quoted_string { + let parse_until = if quoted_string { + let quote_start = self.current_char; self.skip_char(); - &[SINGLE_QUOTE, DOUBLE_QUOTE, META_CLOSE, LB] + vec![quote_start, META_CLOSE, LB] } else { - &[META_CLOSE, LB, SPACE] + vec![META_CLOSE, LB, SPACE] }; - let raw_value = self.get_string_until(parse_until, &[])?; + let raw_value = self.get_string_until(&parse_until, &[])?; if self.check_special_group("ES) { self.skip_char(); } diff --git a/src/parsing/placeholders.rs b/src/parsing/placeholders.rs index cc408a1..ae5f39b 100644 --- a/src/parsing/placeholders.rs +++ b/src/parsing/placeholders.rs @@ -24,6 +24,7 @@ macro_rules! inline { } pub(crate) trait ProcessPlaceholders { + fn combine_placeholders(&mut self); fn process_placeholders(&mut self); fn process_definitions(&mut self); fn add_bib_entry(&mut self, key: String, value: BibEntry) -> Arc>; @@ -101,8 +102,22 @@ const P_TIME: &str = "time"; const P_DATETIME: &str = "datetime"; impl ProcessPlaceholders for Document { + fn combine_placeholders(&mut self) { + let mut placeholders = Vec::new(); + self.elements.iter().for_each(|e| { + if let Block::Import(import) = e { + let anchor = import.anchor.lock().unwrap(); + if let Some(doc) = &anchor.document { + placeholders.append(&mut doc.placeholders.clone()) + } + } + }); + self.placeholders.append(&mut placeholders); + } + /// parses all placeholders and assigns values to them fn process_placeholders(&mut self) { + self.combine_placeholders(); self.process_definitions(); lazy_static::lazy_static! {static ref RE_REF: Regex = Regex::new(r"^ref:(.*)$").unwrap();} self.placeholders.iter().for_each(|p| {