|
|
@ -39,7 +39,7 @@ const B_NOTES: &str = "notes";
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct BibEntry {
|
|
|
|
pub struct BibEntry {
|
|
|
|
key: String,
|
|
|
|
pub(crate) key: String,
|
|
|
|
author: Option<String>,
|
|
|
|
author: Option<String>,
|
|
|
|
date: Option<String>,
|
|
|
|
date: Option<String>,
|
|
|
|
url: Option<String>,
|
|
|
|
url: Option<String>,
|
|
|
@ -50,11 +50,9 @@ pub struct BibEntry {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl BibEntry {
|
|
|
|
impl BibEntry {
|
|
|
|
pub fn get_formatted(&self) -> String {
|
|
|
|
pub fn get_template(&self) -> Template {
|
|
|
|
if let Some(display) = &self.display {
|
|
|
|
let mut template = Template::empty();
|
|
|
|
let value = display.lock().unwrap();
|
|
|
|
template.add_replacement("key", &self.key);
|
|
|
|
if let MetadataValue::String(format) = &value.value {
|
|
|
|
|
|
|
|
let mut template = Template::new(format.clone());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(author) = &self.author {
|
|
|
|
if let Some(author) = &self.author {
|
|
|
|
template.add_replacement(B_AUTHOR, author.as_str());
|
|
|
|
template.add_replacement(B_AUTHOR, author.as_str());
|
|
|
@ -75,6 +73,16 @@ impl BibEntry {
|
|
|
|
template.add_replacement(B_NOTES, notes.as_str());
|
|
|
|
template.add_replacement(B_NOTES, notes.as_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn get_formatted(&self) -> String {
|
|
|
|
|
|
|
|
if let Some(display) = &self.display {
|
|
|
|
|
|
|
|
let value = display.lock().unwrap();
|
|
|
|
|
|
|
|
if let MetadataValue::String(format) = &value.value {
|
|
|
|
|
|
|
|
let mut template = self.get_template();
|
|
|
|
|
|
|
|
template.set_value(format.clone());
|
|
|
|
|
|
|
|
|
|
|
|
template.render()
|
|
|
|
template.render()
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
format!("'Invalid formatter!' {:?}", self)
|
|
|
|
format!("'Invalid formatter!' {:?}", self)
|
|
|
@ -104,12 +112,14 @@ impl ProcessPlaceholders for Document {
|
|
|
|
if let Some(entry) = self.bib_entries.get(key.as_str()) {
|
|
|
|
if let Some(entry) = self.bib_entries.get(key.as_str()) {
|
|
|
|
pholder.value = Some(inline!(Inline::Reference(Reference {
|
|
|
|
pholder.value = Some(inline!(Inline::Reference(Reference {
|
|
|
|
value: Some(RefValue::BibEntry(entry.clone())),
|
|
|
|
value: Some(RefValue::BibEntry(entry.clone())),
|
|
|
|
metadata: pholder.metadata.clone()
|
|
|
|
metadata: pholder.metadata.clone(),
|
|
|
|
|
|
|
|
display: self.get_config_param("ref-display")
|
|
|
|
})))
|
|
|
|
})))
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
pholder.value = Some(inline!(Inline::Reference(Reference {
|
|
|
|
pholder.value = Some(inline!(Inline::Reference(Reference {
|
|
|
|
value: None,
|
|
|
|
value: None,
|
|
|
|
metadata: pholder.metadata.clone()
|
|
|
|
metadata: pholder.metadata.clone(),
|
|
|
|
|
|
|
|
display: self.get_config_param("ref-display")
|
|
|
|
})))
|
|
|
|
})))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|