Workaround for show set propagation on citations

Fixes #2531
This commit is contained in:
Laurenz 2023-11-19 18:55:36 +01:00
parent b23914fca9
commit c641044380
3 changed files with 18 additions and 6 deletions

View File

@ -750,8 +750,10 @@ impl Default for ListBuilder<'_> {
/// Accepts citations.
#[derive(Default)]
struct CiteGroupBuilder<'a> {
/// The styles.
styles: StyleChain<'a>,
/// The citations.
items: StyleVecBuilder<'a, CiteElem>,
items: Vec<CiteElem>,
/// Trailing content for which it is unclear whether it is part of the list.
staged: Vec<(&'a Content, StyleChain<'a>)>,
}
@ -766,8 +768,11 @@ impl<'a> CiteGroupBuilder<'a> {
}
if let Some(citation) = content.to::<CiteElem>() {
if self.items.is_empty() {
self.styles = styles;
}
self.staged.retain(|(elem, _)| !elem.is::<SpaceElem>());
self.items.push(citation.clone(), styles);
self.items.push(citation.clone());
return true;
}
@ -775,9 +780,7 @@ impl<'a> CiteGroupBuilder<'a> {
}
fn finish(self) -> (Content, StyleChain<'a>) {
let (items, styles) = self.items.finish();
let items = items.into_items();
let span = items.first().map(|cite| cite.span()).unwrap_or(Span::detached());
(CiteGroup::new(items).pack().spanned(span), styles)
let span = self.items.first().map(|cite| cite.span()).unwrap_or(Span::detached());
(CiteGroup::new(self.items).pack().spanned(span), self.styles)
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -0,0 +1,9 @@
// Test show set rules on citations.
---
#show cite: set text(red)
A @netwok @arrgh.
B #cite(<netwok>) #cite(<arrgh>).
#show bibliography: none
#bibliography("/files/works.bib")