Change placeholder behaviour to be global and not document-scoped

pull/1/head
trivernis 4 years ago
parent 8daa6bb70c
commit a7deb82966

@ -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(&QUOTES);
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(&QUOTES) {
self.skip_char();
}

@ -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<Mutex<BibEntry>>;
@ -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| {

Loading…
Cancel
Save