Skip to content

Commit

Permalink
Fix citation suppresses title when no author provided (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
AstrickHarren authored Apr 8, 2024
1 parent 5aec683 commit 4c97279
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/csl/rendering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,16 +774,17 @@ fn choose_children<F, R, T: EntryLike>(
where
F: FnMut(&[LayoutRenderingElement], &mut Context<T>) -> R,
{
for branch in choose.branches() {
if branch.match_.test(BranchConditionIter::from_branch(branch, ctx)) {
return Some(f(&branch.children, ctx));
}
}

choose
.otherwise
.as_ref()
.map(|fallthrough| f(&fallthrough.children, ctx))
let supressed = ctx.writing.suppress_queried_variables;
ctx.writing.stop_suppressing_queried_variables();
let branch = choose
.branches()
.find(|branch| branch.match_.test(BranchConditionIter::from_branch(branch, ctx)));
ctx.writing.suppress_queried_variables = supressed;

branch
.map(|b| b.children.as_slice())
.or_else(|| choose.otherwise.as_ref().map(|f| f.children.as_slice()))
.map(|children| f(children, ctx))
}

impl RenderCsl for citationberg::Choose {
Expand Down
49 changes: 49 additions & 0 deletions tests/citeproc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,3 +746,52 @@ fn access_date() {
.unwrap();
assert_eq!(buf, "Retrieved 2021, from https://example.com/");
}

#[test]
fn no_author() {
let style = ArchivedStyle::by_name("apa").unwrap().get();
let locales = locales();
let Style::Independent(style) = style else {
panic!("test has dependent style");
};

let lib = from_biblatex_str(
r#"
@misc{test,
title = {Definition and objectives of systems development},
url = {https://www.opentextbooks.org.hk/ditatopic/25323},
language = {en},
urldate = {2023-11-24},
journal = {Open Textbooks for Hong Kong},
date = {2016-01-19},
}
}"#,
)
.unwrap();
let entry = lib.get("test").unwrap();

let mut driver: BibliographyDriver<'_, Entry> = BibliographyDriver::new();
driver.citation(CitationRequest::new(
vec![CitationItem::new(entry, None, None, false, None)],
&style,
None,
&locales,
Some(1),
));

let rendered = driver.finish(BibliographyRequest::new(&style, None, &locales));
let mut buf = String::new();
rendered.bibliography.unwrap().items[0]
.content
.write_buf(&mut buf, hayagriva::BufWriteFormat::Plain)
.unwrap();

assert_eq!(buf, "Definition and objectives of systems development. (2016, January 19). https://www.opentextbooks.org.hk/ditatopic/25323");

let mut buf = String::new();
rendered.citations[0]
.citation
.write_buf(&mut buf, hayagriva::BufWriteFormat::Plain)
.unwrap();
assert_eq!(buf, "(Definition and Objectives of Systems Development, 2016)");
}

0 comments on commit 4c97279

Please sign in to comment.