Capture corresponding authors and class metadata cleanly

This commit is contained in:
gloamxun committed 2026-10-20 01:15:02 +08:00
1 parent 5fd5f92bb4
commit 06cc88809e
5 files changed
+40 -8

No files matched your search

+12 -1
View File
@@ -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) => {