mirror of https://github.com/stelzo/typst.git
Fix smart quotes in PDF outline (#3790)
This commit is contained in:
parent
a33d8bf322
commit
2efa86cbdf
|
|
@ -2,7 +2,9 @@ use ecow::EcoString;
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
||||||
use crate::diag::{bail, StrResult};
|
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::layout::Dir;
|
||||||
use crate::syntax::is_newline;
|
use crate::syntax::is_newline;
|
||||||
use crate::text::{Lang, Region};
|
use crate::text::{Lang, Region};
|
||||||
|
|
@ -26,7 +28,7 @@ use crate::text::{Lang, Region};
|
||||||
/// # Syntax
|
/// # Syntax
|
||||||
/// This function also has dedicated syntax: The normal quote characters
|
/// This function also has dedicated syntax: The normal quote characters
|
||||||
/// (`'` and `"`). Typst automatically makes your quotes smart.
|
/// (`'` and `"`). Typst automatically makes your quotes smart.
|
||||||
#[elem(name = "smartquote")]
|
#[elem(name = "smartquote", PlainText)]
|
||||||
pub struct SmartQuoteElem {
|
pub struct SmartQuoteElem {
|
||||||
/// Whether this should be a double quote.
|
/// Whether this should be a double quote.
|
||||||
#[default(true)]
|
#[default(true)]
|
||||||
|
|
@ -85,6 +87,16 @@ pub struct SmartQuoteElem {
|
||||||
pub quotes: Smart<SmartQuoteDict>,
|
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.
|
/// State machine for smart quote substitution.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct SmartQuoter {
|
pub struct SmartQuoter {
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
|
|
@ -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”
|
||||||
Loading…
Reference in New Issue