Capture corresponding authors and class metadata cleanly
This commit is contained in:
1 parent
5fd5f92bb4
commit
06cc88809e
5 files changed
+40
-8
No files matched your search
@@ -75,6 +75,8 @@ pub struct AuthorBlock {
|
||||
/// One-based affiliation indices attached to this author.
|
||||
pub affiliations: Vec<usize>,
|
||||
pub email: Option<String>,
|
||||
/// Author marked with `*` (corresponding author).
|
||||
pub corresponding: bool,
|
||||
}
|
||||
|
||||
/// One numbered affiliation in a structured front matter.
|
||||
|
||||
@@ -480,6 +480,7 @@ struct Parser {
|
||||
metadata_capture: Option<(expanded::MetadataField, Vec<Run>)>,
|
||||
author_affiliations: Vec<usize>,
|
||||
pending_author_email: Option<String>,
|
||||
pending_author_corresponding: bool,
|
||||
email_capture: Option<Vec<Run>>,
|
||||
affiliation_capture: Option<(usize, Vec<Run>)>,
|
||||
abstract_capture: Option<Vec<Run>>,
|
||||
@@ -598,6 +599,7 @@ impl Parser {
|
||||
metadata_capture: None,
|
||||
author_affiliations: Vec::new(),
|
||||
pending_author_email: None,
|
||||
pending_author_corresponding: false,
|
||||
email_capture: None,
|
||||
affiliation_capture: None,
|
||||
abstract_capture: None,
|
||||
@@ -803,10 +805,12 @@ impl Parser {
|
||||
self.document.author = value;
|
||||
let affiliations = std::mem::take(&mut self.author_affiliations);
|
||||
let email = self.pending_author_email.take();
|
||||
let corresponding = std::mem::take(&mut self.pending_author_corresponding);
|
||||
self.document.authors.push(crate::document::AuthorBlock {
|
||||
runs,
|
||||
affiliations,
|
||||
email,
|
||||
corresponding,
|
||||
});
|
||||
}
|
||||
expanded::MetadataField::Date => self.document.date = value,
|
||||
@@ -1063,11 +1067,18 @@ impl Parser {
|
||||
expanded::FrontendEventKind::MetadataEmailStart => {
|
||||
self.email_capture = Some(Vec::new());
|
||||
}
|
||||
expanded::FrontendEventKind::MetadataAuthorCorresponding => {
|
||||
self.pending_author_corresponding = true;
|
||||
}
|
||||
expanded::FrontendEventKind::MetadataEmailEnd => {
|
||||
if let Some(mut runs) = self.email_capture.take() {
|
||||
trim_run_end(&mut runs);
|
||||
let email = runs.iter().map(|run| run.text.as_str()).collect::<String>();
|
||||
self.pending_author_email = Some(email);
|
||||
if let Some(author) = self.document.authors.last_mut() {
|
||||
author.email = Some(email);
|
||||
} else {
|
||||
self.pending_author_email = Some(email);
|
||||
}
|
||||
}
|
||||
}
|
||||
expanded::FrontendEventKind::AffiliationStart(index) => {
|
||||
|
||||
@@ -292,6 +292,7 @@ pub enum FrontendEventKind {
|
||||
KeywordsEnd,
|
||||
/// Start/end of the e-mail address inside an author block.
|
||||
MetadataEmailStart,
|
||||
MetadataAuthorCorresponding,
|
||||
MetadataEmailEnd,
|
||||
ParagraphAlignment(crate::document::ParagraphAlignment),
|
||||
TableOfContents,
|
||||
|
||||
Reference in new issue
Block a user