diff options
| author | Martin Haug <mhaug@live.de> | 2024-10-02 17:53:23 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-02 15:53:23 +0000 |
| commit | f6406ed901352ee0bd93359fb1ed6d32bcc927b5 (patch) | |
| tree | d5dda0ed9227feb79ffccb7745804bf04632d1c2 | |
| parent | fcdccc9cbae02be0ac61f5f50f7f1a256fdd2b11 (diff) | |
Update Hayagriva (#5088)
| -rw-r--r-- | Cargo.lock | 24 | ||||
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | crates/typst/src/model/bibliography.rs | 44 | ||||
| -rw-r--r-- | tests/ref/bibliography-before-content.png | bin | 17138 -> 17109 bytes | |||
| -rw-r--r-- | tests/ref/cite-group.png | bin | 5464 -> 4745 bytes | |||
| -rw-r--r-- | tests/ref/cite-grouping-and-ordering.png | bin | 1278 -> 841 bytes | |||
| -rw-r--r-- | tests/ref/show-text-citation-smartquote.png | bin | 489 -> 403 bytes | |||
| -rw-r--r-- | tests/suite/model/cite.typ | 4 | ||||
| -rw-r--r-- | tests/suite/styling/show-text.typ | 2 |
9 files changed, 51 insertions, 25 deletions
@@ -149,9 +149,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "biblatex" -version = "0.9.3" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27fe7285040d0227cd8b5395e1c4783f44f0b673eca5a657f4432ae401f2b7b8" +checksum = "a35a7317fcbdbef94b60d0dd0a658711a936accfce4a631fea4bf8e527eff3c2" dependencies = [ "numerals", "paste", @@ -317,11 +317,11 @@ dependencies = [ [[package]] name = "citationberg" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d259fe9fd78ffa05a119581d20fddb50bfba428311057b12741ffb9015123d0b" +checksum = "92fea693c83bd967604be367dc1e1b4895625eabafec2eec66c51092e18e700e" dependencies = [ - "quick-xml 0.31.0", + "quick-xml 0.36.2", "serde", ] @@ -866,9 +866,9 @@ dependencies = [ [[package]] name = "hayagriva" -version = "0.5.3" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d0d20c98b77b86ce737876b2a1653e2e6abbeee84afbb39d72111091191c97a" +checksum = "c9e1ae4b9c0537119755702dfb6f838bf6ff5976ddc84501630783f0d7b5ce5e" dependencies = [ "biblatex", "ciborium", @@ -1863,21 +1863,21 @@ checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" [[package]] name = "quick-xml" -version = "0.31.0" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33" +checksum = "1d3a6e5838b60e0e8fa7a43f22ade549a37d61f8bdbe636d0d7816191de969c2" dependencies = [ "memchr", - "serde", ] [[package]] name = "quick-xml" -version = "0.32.0" +version = "0.36.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d3a6e5838b60e0e8fa7a43f22ade549a37d61f8bdbe636d0d7816191de969c2" +checksum = "f7649a7b4df05aed9ea7ec6f628c67c9953a43869b8bc50929569b2999d443fe" dependencies = [ "memchr", + "serde", ] [[package]] @@ -51,7 +51,7 @@ env_proxy = "0.4" flate2 = "1" fontdb = { version = "0.21", default-features = false } fs_extra = "1.3" -hayagriva = "0.5.3" +hayagriva = "0.6.0" heck = "0.5" hypher = "0.1.4" icu_properties = { version = "1.4", features = ["serde"] } diff --git a/crates/typst/src/model/bibliography.rs b/crates/typst/src/model/bibliography.rs index d6b81a20..ebc2c003 100644 --- a/crates/typst/src/model/bibliography.rs +++ b/crates/typst/src/model/bibliography.rs @@ -779,8 +779,11 @@ impl<'a> Generator<'a> { let content = if info.subinfos.iter().all(|sub| sub.hidden) { Content::empty() } else { - let mut content = - renderer.display_elem_children(&citation.citation, &mut None)?; + let mut content = renderer.display_elem_children( + &citation.citation, + &mut None, + true, + )?; if info.footnote { content = FootnoteElem::with_content(content).pack(); @@ -835,7 +838,8 @@ impl<'a> Generator<'a> { .first_field .as_ref() .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()) { let dest = Destination::Location(*location); content = content.linked(dest); @@ -846,7 +850,7 @@ impl<'a> Generator<'a> { // Render the main reference content. 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 // we can link to the bibliography entry. @@ -876,16 +880,24 @@ impl ElemRenderer<'_> { /// /// The `prefix` can be a separate content storage where `left-margin` /// 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( &self, elems: &hayagriva::ElemChildren, prefix: &mut Option<Content>, + is_citation: bool, ) -> StrResult<Content> { Ok(Content::sequence( elems .0 .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<_>>>()?, )) } @@ -895,9 +907,12 @@ impl ElemRenderer<'_> { &self, elem: &hayagriva::ElemChild, prefix: &mut Option<Content>, + trim_start: bool, ) -> StrResult<Content> { 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::Markup(markup) => self.display_math(markup), hayagriva::ElemChild::Link { text, url } => self.display_link(text, url)?, @@ -921,6 +936,7 @@ impl ElemRenderer<'_> { let mut content = self.display_elem_children( &elem.children, if block_level { &mut suf_prefix } else { prefix }, + false, )?; if let Some(prefix) = suf_prefix { @@ -976,7 +992,7 @@ impl ElemRenderer<'_> { /// Display a link. fn display_link(&self, text: &hayagriva::Formatted, url: &str) -> StrResult<Content> { 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() .spanned(self.span)) } @@ -988,8 +1004,18 @@ impl ElemRenderer<'_> { } /// Display formatted hayagriva text as content. - fn display_formatted(&self, formatted: &hayagriva::Formatted) -> Content { - let content = TextElem::packed(formatted.text.as_str()).spanned(self.span); + fn display_formatted( + &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) } } diff --git a/tests/ref/bibliography-before-content.png b/tests/ref/bibliography-before-content.png Binary files differindex 9a473e54..ea5ece26 100644 --- a/tests/ref/bibliography-before-content.png +++ b/tests/ref/bibliography-before-content.png diff --git a/tests/ref/cite-group.png b/tests/ref/cite-group.png Binary files differindex 0549d2c8..02772f49 100644 --- a/tests/ref/cite-group.png +++ b/tests/ref/cite-group.png diff --git a/tests/ref/cite-grouping-and-ordering.png b/tests/ref/cite-grouping-and-ordering.png Binary files differindex b292ab4a..8dea1b53 100644 --- a/tests/ref/cite-grouping-and-ordering.png +++ b/tests/ref/cite-grouping-and-ordering.png diff --git a/tests/ref/show-text-citation-smartquote.png b/tests/ref/show-text-citation-smartquote.png Binary files differindex 941b4b05..604ecc24 100644 --- a/tests/ref/show-text-citation-smartquote.png +++ b/tests/ref/show-text-citation-smartquote.png diff --git a/tests/suite/model/cite.typ b/tests/suite/model/cite.typ index f69fe9f4..90280081 100644 --- a/tests/suite/model/cite.typ +++ b/tests/suite/model/cite.typ @@ -30,7 +30,7 @@ A @netwok @arrgh @quark B. \ A @netwok @arrgh @quark, B. #set text(0pt) -#bibliography("/assets/bib/works.bib") +#bibliography("/assets/bib/works.bib", style: "american-physics-society") --- cite-grouping-and-ordering --- @mcintosh_anxiety @@ -47,7 +47,7 @@ A @netwok @arrgh @quark, B. @restful #show bibliography: none -#bibliography("/assets/bib/works.bib") +#bibliography("/assets/bib/works.bib", style: "american-physics-society") --- issue-785-cite-locate --- // Test citation in other introspection. diff --git a/tests/suite/styling/show-text.typ b/tests/suite/styling/show-text.typ index af45127c..3544b4fc 100644 --- a/tests/suite/styling/show-text.typ +++ b/tests/suite/styling/show-text.typ @@ -160,7 +160,7 @@ hi @netwok hey " dis #show bibliography: none -#bibliography("/assets/bib/works.bib") +#bibliography("/assets/bib/works.bib", style: "american-physics-society") --- show-text-in-citation --- #show "A": "B" |
