Update Hayagriva (#5088)

This commit is contained in:
Martin Haug 2024-10-02 17:53:23 +02:00 committed by GitHub
parent fcdccc9cba
commit f6406ed901
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 56 additions and 30 deletions

34
Cargo.lock generated
View file

@ -149,9 +149,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
[[package]] [[package]]
name = "biblatex" name = "biblatex"
version = "0.9.3" version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27fe7285040d0227cd8b5395e1c4783f44f0b673eca5a657f4432ae401f2b7b8" checksum = "a35a7317fcbdbef94b60d0dd0a658711a936accfce4a631fea4bf8e527eff3c2"
dependencies = [ dependencies = [
"numerals", "numerals",
"paste", "paste",
@ -317,11 +317,11 @@ dependencies = [
[[package]] [[package]]
name = "citationberg" name = "citationberg"
version = "0.3.1" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d259fe9fd78ffa05a119581d20fddb50bfba428311057b12741ffb9015123d0b" checksum = "92fea693c83bd967604be367dc1e1b4895625eabafec2eec66c51092e18e700e"
dependencies = [ dependencies = [
"quick-xml 0.31.0", "quick-xml 0.36.2",
"serde", "serde",
] ]
@ -866,9 +866,9 @@ dependencies = [
[[package]] [[package]]
name = "hayagriva" name = "hayagriva"
version = "0.5.3" version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d0d20c98b77b86ce737876b2a1653e2e6abbeee84afbb39d72111091191c97a" checksum = "c9e1ae4b9c0537119755702dfb6f838bf6ff5976ddc84501630783f0d7b5ce5e"
dependencies = [ dependencies = [
"biblatex", "biblatex",
"ciborium", "ciborium",
@ -1861,16 +1861,6 @@ version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
[[package]]
name = "quick-xml"
version = "0.31.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33"
dependencies = [
"memchr",
"serde",
]
[[package]] [[package]]
name = "quick-xml" name = "quick-xml"
version = "0.32.0" version = "0.32.0"
@ -1880,6 +1870,16 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "quick-xml"
version = "0.36.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7649a7b4df05aed9ea7ec6f628c67c9953a43869b8bc50929569b2999d443fe"
dependencies = [
"memchr",
"serde",
]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.37" version = "1.0.37"

View file

@ -51,7 +51,7 @@ env_proxy = "0.4"
flate2 = "1" flate2 = "1"
fontdb = { version = "0.21", default-features = false } fontdb = { version = "0.21", default-features = false }
fs_extra = "1.3" fs_extra = "1.3"
hayagriva = "0.5.3" hayagriva = "0.6.0"
heck = "0.5" heck = "0.5"
hypher = "0.1.4" hypher = "0.1.4"
icu_properties = { version = "1.4", features = ["serde"] } icu_properties = { version = "1.4", features = ["serde"] }

View file

@ -779,8 +779,11 @@ impl<'a> Generator<'a> {
let content = if info.subinfos.iter().all(|sub| sub.hidden) { let content = if info.subinfos.iter().all(|sub| sub.hidden) {
Content::empty() Content::empty()
} else { } else {
let mut content = let mut content = renderer.display_elem_children(
renderer.display_elem_children(&citation.citation, &mut None)?; &citation.citation,
&mut None,
true,
)?;
if info.footnote { if info.footnote {
content = FootnoteElem::with_content(content).pack(); content = FootnoteElem::with_content(content).pack();
@ -835,7 +838,8 @@ impl<'a> Generator<'a> {
.first_field .first_field
.as_ref() .as_ref()
.map(|elem| { .map(|elem| {
let mut content = renderer.display_elem_child(elem, &mut None)?; let mut content =
renderer.display_elem_child(elem, &mut None, false)?;
if let Some(location) = first_occurrences.get(item.key.as_str()) { if let Some(location) = first_occurrences.get(item.key.as_str()) {
let dest = Destination::Location(*location); let dest = Destination::Location(*location);
content = content.linked(dest); content = content.linked(dest);
@ -846,7 +850,7 @@ impl<'a> Generator<'a> {
// Render the main reference content. // Render the main reference content.
let mut reference = let mut reference =
renderer.display_elem_children(&item.content, &mut prefix)?; renderer.display_elem_children(&item.content, &mut prefix, false)?;
// Attach a backlink to either the prefix or the reference so that // Attach a backlink to either the prefix or the reference so that
// we can link to the bibliography entry. // we can link to the bibliography entry.
@ -876,16 +880,24 @@ impl ElemRenderer<'_> {
/// ///
/// The `prefix` can be a separate content storage where `left-margin` /// The `prefix` can be a separate content storage where `left-margin`
/// elements will be accumulated into. /// elements will be accumulated into.
///
/// `is_citation` dictates whether whitespace at the start of the citation
/// will be eliminated. Some CSL styles yield whitespace at the start of
/// their citations, which should instead be handled by Typst.
fn display_elem_children( fn display_elem_children(
&self, &self,
elems: &hayagriva::ElemChildren, elems: &hayagriva::ElemChildren,
prefix: &mut Option<Content>, prefix: &mut Option<Content>,
is_citation: bool,
) -> StrResult<Content> { ) -> StrResult<Content> {
Ok(Content::sequence( Ok(Content::sequence(
elems elems
.0 .0
.iter() .iter()
.map(|elem| self.display_elem_child(elem, prefix)) .enumerate()
.map(|(i, elem)| {
self.display_elem_child(elem, prefix, is_citation && i == 0)
})
.collect::<StrResult<Vec<_>>>()?, .collect::<StrResult<Vec<_>>>()?,
)) ))
} }
@ -895,9 +907,12 @@ impl ElemRenderer<'_> {
&self, &self,
elem: &hayagriva::ElemChild, elem: &hayagriva::ElemChild,
prefix: &mut Option<Content>, prefix: &mut Option<Content>,
trim_start: bool,
) -> StrResult<Content> { ) -> StrResult<Content> {
Ok(match elem { Ok(match elem {
hayagriva::ElemChild::Text(formatted) => self.display_formatted(formatted), hayagriva::ElemChild::Text(formatted) => {
self.display_formatted(formatted, trim_start)
}
hayagriva::ElemChild::Elem(elem) => self.display_elem(elem, prefix)?, hayagriva::ElemChild::Elem(elem) => self.display_elem(elem, prefix)?,
hayagriva::ElemChild::Markup(markup) => self.display_math(markup), hayagriva::ElemChild::Markup(markup) => self.display_math(markup),
hayagriva::ElemChild::Link { text, url } => self.display_link(text, url)?, hayagriva::ElemChild::Link { text, url } => self.display_link(text, url)?,
@ -921,6 +936,7 @@ impl ElemRenderer<'_> {
let mut content = self.display_elem_children( let mut content = self.display_elem_children(
&elem.children, &elem.children,
if block_level { &mut suf_prefix } else { prefix }, if block_level { &mut suf_prefix } else { prefix },
false,
)?; )?;
if let Some(prefix) = suf_prefix { if let Some(prefix) = suf_prefix {
@ -976,7 +992,7 @@ impl ElemRenderer<'_> {
/// Display a link. /// Display a link.
fn display_link(&self, text: &hayagriva::Formatted, url: &str) -> StrResult<Content> { fn display_link(&self, text: &hayagriva::Formatted, url: &str) -> StrResult<Content> {
let dest = Destination::Url(Url::new(url)?); let dest = Destination::Url(Url::new(url)?);
Ok(LinkElem::new(dest.into(), self.display_formatted(text)) Ok(LinkElem::new(dest.into(), self.display_formatted(text, false))
.pack() .pack()
.spanned(self.span)) .spanned(self.span))
} }
@ -988,8 +1004,18 @@ impl ElemRenderer<'_> {
} }
/// Display formatted hayagriva text as content. /// Display formatted hayagriva text as content.
fn display_formatted(&self, formatted: &hayagriva::Formatted) -> Content { fn display_formatted(
let content = TextElem::packed(formatted.text.as_str()).spanned(self.span); &self,
formatted: &hayagriva::Formatted,
trim_start: bool,
) -> Content {
let formatted_text = if trim_start {
formatted.text.trim_start()
} else {
formatted.text.as_str()
};
let content = TextElem::packed(formatted_text).spanned(self.span);
apply_formatting(content, &formatted.formatting) apply_formatting(content, &formatted.formatting)
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 841 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 489 B

After

Width:  |  Height:  |  Size: 403 B

View file

@ -30,7 +30,7 @@ A @netwok @arrgh @quark B. \
A @netwok @arrgh @quark, B. A @netwok @arrgh @quark, B.
#set text(0pt) #set text(0pt)
#bibliography("/assets/bib/works.bib") #bibliography("/assets/bib/works.bib", style: "american-physics-society")
--- cite-grouping-and-ordering --- --- cite-grouping-and-ordering ---
@mcintosh_anxiety @mcintosh_anxiety
@ -47,7 +47,7 @@ A @netwok @arrgh @quark, B.
@restful @restful
#show bibliography: none #show bibliography: none
#bibliography("/assets/bib/works.bib") #bibliography("/assets/bib/works.bib", style: "american-physics-society")
--- issue-785-cite-locate --- --- issue-785-cite-locate ---
// Test citation in other introspection. // Test citation in other introspection.

View file

@ -160,7 +160,7 @@ hi
@netwok hey " dis @netwok hey " dis
#show bibliography: none #show bibliography: none
#bibliography("/assets/bib/works.bib") #bibliography("/assets/bib/works.bib", style: "american-physics-society")
--- show-text-in-citation --- --- show-text-in-citation ---
#show "A": "B" #show "A": "B"