diff options
| author | Ana Gelez <ana+github@gelez.xyz> | 2024-03-25 14:32:02 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2024-05-17 14:27:58 +0200 |
| commit | c5dcd220c1d99e07b5736b6bbae4687aa82d3f55 (patch) | |
| tree | ea2b8db5ac5f24f1d3c466aca3fdf6af54c10de8 | |
| parent | 784488c5225534ee7e3848df186d059cb6cbeed5 (diff) | |
Fix smart quotes in PDF outline (#3790)
| -rw-r--r-- | crates/typst/src/text/smartquote.rs | 16 | ||||
| -rw-r--r-- | tests/ref/bugs/3662-pdf-smartquotes.png | bin | 0 -> 11950 bytes | |||
| -rw-r--r-- | tests/typ/bugs/3662-pdf-smartquotes.typ | 12 |
3 files changed, 26 insertions, 2 deletions
diff --git a/crates/typst/src/text/smartquote.rs b/crates/typst/src/text/smartquote.rs index dbcca6dc..4bb5ca01 100644 --- a/crates/typst/src/text/smartquote.rs +++ b/crates/typst/src/text/smartquote.rs @@ -2,7 +2,9 @@ use ecow::EcoString; use unicode_segmentation::UnicodeSegmentation; use crate::diag::{bail, StrResult}; -use crate::foundations::{array, cast, dict, elem, Array, Dict, FromValue, Smart, Str}; +use crate::foundations::{ + array, cast, dict, elem, Array, Dict, FromValue, Packed, PlainText, Smart, Str, +}; use crate::layout::Dir; use crate::syntax::is_newline; use crate::text::{Lang, Region}; @@ -26,7 +28,7 @@ use crate::text::{Lang, Region}; /// # Syntax /// This function also has dedicated syntax: The normal quote characters /// (`'` and `"`). Typst automatically makes your quotes smart. -#[elem(name = "smartquote")] +#[elem(name = "smartquote", PlainText)] pub struct SmartQuoteElem { /// Whether this should be a double quote. #[default(true)] @@ -85,6 +87,16 @@ pub struct SmartQuoteElem { pub quotes: Smart<SmartQuoteDict>, } +impl PlainText for Packed<SmartQuoteElem> { + fn plain_text(&self, text: &mut EcoString) { + if self.double.unwrap_or(true) { + text.push_str("\""); + } else { + text.push_str("'"); + } + } +} + /// State machine for smart quote substitution. #[derive(Debug, Clone)] pub struct SmartQuoter { diff --git a/tests/ref/bugs/3662-pdf-smartquotes.png b/tests/ref/bugs/3662-pdf-smartquotes.png Binary files differnew file mode 100644 index 00000000..c272a8ff --- /dev/null +++ b/tests/ref/bugs/3662-pdf-smartquotes.png diff --git a/tests/typ/bugs/3662-pdf-smartquotes.typ b/tests/typ/bugs/3662-pdf-smartquotes.typ new file mode 100644 index 00000000..36dc8a15 --- /dev/null +++ b/tests/typ/bugs/3662-pdf-smartquotes.typ @@ -0,0 +1,12 @@ +// Smart quotes were not appearing in the PDF outline, because they didn't +// implement `PlainText` +// https://github.com/typst/typst/issues/3662 + +--- += It's "Unnormal Heading" += It’s “Normal Heading” + +#set smartquote(enabled: false) += It's "Unnormal Heading" += It's 'single quotes' += It’s “Normal Heading”
\ No newline at end of file |
