From 37fdec8fc264b9886e91cb0ae1947d2da7901488 Mon Sep 17 00:00:00 2001 From: DerDrodt Date: Tue, 5 Dec 2023 20:54:57 +0100 Subject: [PATCH 1/2] Implement localized quotation marks --- src/csl/mod.rs | 5 +++++ src/types/strings.rs | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/csl/mod.rs b/src/csl/mod.rs index a366f75..db56a97 100644 --- a/src/csl/mod.rs +++ b/src/csl/mod.rs @@ -2390,6 +2390,11 @@ impl<'a, T: EntryLike> Context<'a, T> { self.writing.buf.push_verbatim(&chunk.value); self.writing.pull_punctuation = false; } + ChunkKind::Quote => { + self.push_quotes(); + self.push_str(&chunk.value); + self.pop_quotes(); + } ChunkKind::Math => { self.writing.buf.prevent_trimming(); self.writing.save_to_block(); diff --git a/src/types/strings.rs b/src/types/strings.rs index c374fe9..a3fd7e7 100644 --- a/src/types/strings.rs +++ b/src/types/strings.rs @@ -357,7 +357,7 @@ impl ChunkedString { let config = c.case(); for chunk in &self.0 { match chunk.kind { - ChunkKind::Normal => c.reconfigure(config), + ChunkKind::Normal | ChunkKind::Quote => c.reconfigure(config), ChunkKind::Verbatim | ChunkKind::Math => c.reconfigure(Case::NoTransform), }; @@ -416,6 +416,13 @@ impl FromStr for ChunkedString { '$' => { kind = ChunkKind::Math; } + '"' if kind == ChunkKind::Quote => { + kind = + if depth > 0 { ChunkKind::Verbatim } else { ChunkKind::Normal }; + } + '"' => { + kind = ChunkKind::Quote; + } _ => chunks.push_char(c, kind), } } @@ -573,6 +580,11 @@ impl StringChunk { write_escaped(self, buf)?; buf.write_char('$')?; } + ChunkKind::Quote => { + buf.write_char('"')?; + write_escaped(self, buf)?; + buf.write_char('"')?; + } } Ok(()) @@ -590,6 +602,8 @@ pub enum ChunkKind { /// The contained markup is expected to be evaluated using /// [Typst](https://typst.app/). Math, + /// Quotation marks to be formatted according to the locale. + Quote, } /// The kind of a string chunk for use with the case folder. @@ -609,7 +623,7 @@ impl TryFrom for FoldableKind { match value { ChunkKind::Normal => Ok(Self::Normal), ChunkKind::Verbatim => Ok(Self::Verbatim), - ChunkKind::Math => Err(()), + ChunkKind::Math | ChunkKind::Quote => Err(()), } } } From 2e0bfcbef9b4097fbc2878f1f1be527de9ce9d09 Mon Sep 17 00:00:00 2001 From: DerDrodt Date: Tue, 5 Dec 2023 21:08:23 +0100 Subject: [PATCH 2/2] Document changes --- docs/file-format.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/file-format.md b/docs/file-format.md index 2ec887a..4fbb9af 100644 --- a/docs/file-format.md +++ b/docs/file-format.md @@ -421,6 +421,20 @@ publisher: Title and sentence case folding will always be deactivated if your item has set the `language` key to something other than English. +Double quotation marks in a formattable string will be we transformed to +fitting opening and closing quotation marks according to the chosen locale. +Quotes will always be appropriately nested: + +```yaml +title: Reflections on "Harlem" and Other Poems +``` + +If you use quotation marks as YAML delimiters, simply escape the quotation marks in the title: + +```yaml +title: "Reflections on \"Harlem\" and Other Poems" +``` + You can also include mathematical markup evaluated by [Typst](https://typst.app) by wrapping it in dollars.