Add formatting implementation for article

Signed-off-by: trivernis <trivernis@protonmail.com>
feature/epub-rendering
trivernis 4 years ago
parent 801268b804
commit 1ef9f1183c
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

6
Cargo.lock generated

@ -54,7 +54,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "bibliographix" name = "bibliographix"
version = "0.2.0" version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"chrono 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1145,7 +1145,7 @@ version = "0.23.0"
dependencies = [ dependencies = [
"asciimath-rs 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", "asciimath-rs 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)",
"base64 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", "base64 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
"bibliographix 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "bibliographix 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"charred 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "charred 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)",
"colored 1.9.3 (registry+https://github.com/rust-lang/crates.io-index)", "colored 1.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1588,7 +1588,7 @@ dependencies = [
"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" "checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" "checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
"checksum base64 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" "checksum base64 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
"checksum bibliographix 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba3bc8793948a3de7d106d5f855afb085b998585c5f407ae59cd5489d3ed97c8" "checksum bibliographix 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4d80a9410af7ce9fa988e4ea1944a84ab9b00ffadb9f380120b0bc18996fad4b"
"checksum bincode 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d" "checksum bincode 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d"
"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
"checksum bumpalo 3.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" "checksum bumpalo 3.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820"

@ -19,7 +19,7 @@ path = "src/main.rs"
[dependencies] [dependencies]
charred = "0.3.3" charred = "0.3.3"
asciimath-rs = "0.5.7" asciimath-rs = "0.5.7"
bibliographix = "0.2.0" bibliographix = "0.3.0"
crossbeam-utils = "0.7.2" crossbeam-utils = "0.7.2"
structopt = "0.3.14" structopt = "0.3.14"
minify = "1.1.1" minify = "1.1.1"

@ -1 +1,82 @@
use crate::elements::Inline;
use crate::elements::{BoldText, ItalicText, Line, List, ListItem, PlainText, TextLine};
use bibliographix::bibliography::bib_types::article::Article;
use bibliographix::bibliography::bib_types::BibliographyType;
use bibliographix::bibliography::bibliography_entry::{
BibliographyEntry, BibliographyEntryReference,
};
use std::sync::MutexGuard;
macro_rules! plain_text {
($e:expr) => {
Inline::Plain(PlainText { value: $e })
};
}
macro_rules! bold_text {
($e:expr) => {
Inline::Bold(BoldText {
value: vec![Inline::Plain(PlainText { value: $e })],
})
};
}
macro_rules! italic_text {
($e:expr) => {
Inline::Italic(ItalicText {
value: vec![Inline::Plain(PlainText { value: $e })],
})
};
}
fn create_bib_list(entries: Vec<BibliographyEntryReference>) -> List {
let mut list = List::new();
for entry in entries {
list.add_item(get_item_for_entry(entry));
}
list
}
fn get_item_for_entry(entry: BibliographyEntryReference) -> ListItem {
let entry = entry.lock().unwrap();
match &entry.bib_type {
BibliographyType::Article(a) => get_item_for_article(&*entry, a),
_ => unimplemented!(),
}
}
/// Returns the formatted article bib entry
fn get_item_for_article(entry: &BibliographyEntry, a: &Article) -> ListItem {
let mut text = TextLine::new();
text.subtext.push(bold_text!(entry.key().clone()));
text.subtext
.push(plain_text!(format!(": {}.", a.author.clone())));
text.subtext
.push(plain_text!(format!("\"{}\"", a.title.clone()).to_string()));
text.subtext.push(plain_text!("In: ".to_string()));
text.subtext.push(italic_text!(a.journal.clone()));
if let Some(volume) = a.volume.clone() {
text.subtext
.push(italic_text!(format!(", {}", volume).to_string()))
}
if let Some(number) = a.number.clone() {
text.subtext
.push(plain_text!(format!(", Number: {}", number)));
}
text.subtext
.push(plain_text!(format!(", {}", a.date.format("%d.%m.%y"))));
if let Some(pages) = a.pages.clone() {
text.subtext
.push(plain_text!(format!(", Pages: {}", pages).to_string()));
}
if let Some(url) = a.url.clone() {
text.subtext
.push(plain_text!(format!("URL: {}", url).to_string()));
}
ListItem::new(Line::Text(text), 0, true)
}

Loading…
Cancel
Save