Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 39 additions & 23 deletions src/csl/rendering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ impl RenderCsl for citationberg::Text {
ctx.may_strip_periods(self.strip_periods);
let cidx = ctx.push_case(self.text_case);

let mut should_render = true;

match target {
ResolvedTextTarget::StandardVariable(var, val) => match var {
StandardVariable::URL => {
Expand Down Expand Up @@ -99,12 +101,18 @@ impl RenderCsl for citationberg::Text {
MaybeTyped::String(s) => ctx.push_str(&s.replace('-', "–")),
},
ResolvedTextTarget::Macro(mac) => {
// Delimiters from ancestor delimiting elements are NOT applied within.
let idx = ctx.writing.push_delimiter(None);
for child in &mac.children {
child.render(ctx);
// Treat macros as groups: don't render if all variables are empty.
let info = self.will_have_info(ctx).1;
should_render = info.should_render_group();
if should_render {
// Delimiters from ancestor delimiting elements are NOT
// applied within.
let idx = ctx.writing.push_delimiter(None);
for child in &mac.children {
child.render(ctx);
}
ctx.writing.pop_delimiter(idx);
}
ctx.writing.pop_delimiter(idx);
}
ResolvedTextTarget::Term(s) => ctx.push_str(s),
ResolvedTextTarget::Value(val) => ctx.push_str(val),
Expand All @@ -121,24 +129,28 @@ impl RenderCsl for citationberg::Text {
if let Some(affix_loc) = affix_loc {
ctx.apply_suffix(&self.affixes, affix_loc);
}
ctx.commit_elem(
depth,
self.display,
match self.target {
TextTarget::Variable { var, .. }
if var == NumberVariable::CitationNumber.into() =>
{
Some(ElemMeta::CitationNumber)
}
TextTarget::Variable { var, .. }
if var == StandardVariable::CitationLabel.into() =>
{
Some(ElemMeta::CitationLabel)
}
TextTarget::Variable { .. } => Some(ElemMeta::Text),
_ => None,
},
);
if should_render {
ctx.commit_elem(
depth,
self.display,
match self.target {
TextTarget::Variable { var, .. }
if var == NumberVariable::CitationNumber.into() =>
{
Some(ElemMeta::CitationNumber)
}
TextTarget::Variable { var, .. }
if var == StandardVariable::CitationLabel.into() =>
{
Some(ElemMeta::CitationLabel)
}
TextTarget::Variable { .. } => Some(ElemMeta::Text),
_ => None,
},
);
} else {
ctx.discard_elem(depth);
}
}

fn will_render<T: EntryLike>(&self, ctx: &mut Context<T>, var: Variable) -> bool {
Expand Down Expand Up @@ -209,6 +221,10 @@ impl RenderCsl for citationberg::Text {
info = info.merge_child(child_info)
}

// Treat macro as group: don't render if all variables are
// empty.
will_print &= info.should_render_group();

(will_print, UsageInfo { has_used_macros: will_print, ..info })
}
ResolvedTextTarget::Term(_) => (true, UsageInfo::default()),
Expand Down
1 change: 1 addition & 0 deletions tests/citeproc-pass.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ fullstyles_APA
fullstyles_ChicagoNoteWithBibliographyWithPublisher
group_ComplexNesting
group_ShortOutputOnly
group_SuppressTermInMacro
group_SuppressValueWithEmptySubgroup
group_SuppressWithEmptyNestedDateNode
integration_CitationSort
Expand Down