From fce43ddaac2eab7491e8fe7145baaf8e7bf26a72 Mon Sep 17 00:00:00 2001 From: Omikhleia Date: Sat, 12 Nov 2022 01:53:47 +0100 Subject: [PATCH] feat: Smart typography takes language into account for quotation marks --- examples/sile-and-markdown.md | 8 ++++++++ inputters/markdown.lua | 2 ++ inputters/pandocast.lua | 5 +++-- markdown.sile-dev-1.rockspec | 3 ++- packages/markdown/commands.lua | 1 + 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/examples/sile-and-markdown.md b/examples/sile-and-markdown.md index 9d2d9c2..cdacad1 100644 --- a/examples/sile-and-markdown.md +++ b/examples/sile-and-markdown.md @@ -181,6 +181,14 @@ This was obtained with: Or inline in text: [«Encore du français!»]{lang=fr} ``` +Smart typography takes the current language into account when converting straight double and single +quotation marks to the appropriate typographic variant: +["English"]{lang=en} / ["Deutsch"]{lang=de} / ["français"]{lang=fr} / ["dansk"]{lang=da} / ["русский"]{lang=ru}; +['English']{lang=en} / ['Deutsch']{lang=de} / ['français']{lang=fr} / ['dansk']{lang=da} / ['русский']{lang=ru}.^[For +most languages, `"` and `'` correspond to the primary and secondary quotations marks, respectively. +In some languages, they are used the other way round, but obviously the user's input is respected in those cases +(e.g. respectively ["Ghàidhlig"]{lang=cy} and ['Ghàidhlig']{lang=cy}).] + ### Custom styles On the "div" and "span" extended elements, the converter also supports the `{custom-style="..."}` diff --git a/inputters/markdown.lua b/inputters/markdown.lua index 45c647f..980e97e 100644 --- a/inputters/markdown.lua +++ b/inputters/markdown.lua @@ -80,6 +80,8 @@ local function SileAstWriter (options) writer.verbatim = simpleCommandWrapper("verbatim") writer.listitem = simpleCommandWrapper("item") writer.linebreak = simpleCommandWrapper("cr") + writer.singlequoted = simpleCommandWrapper("singlequoted") + writer.doublequoted = simpleCommandWrapper("doublequoted") -- Special case for hrule (simple too, but arguments from lunamark has to be ignored) writer.hrule = function () return utils.createCommand("fullrule") end diff --git a/inputters/pandocast.lua b/inputters/pandocast.lua index d2e8b6d..0b324a0 100644 --- a/inputters/pandocast.lua +++ b/inputters/pandocast.lua @@ -426,10 +426,11 @@ end -- Quoted QuoteType [Inline] -- Where QuoteType is a tag DoubleQuote or SingleQuote Pandoc.Quoted = function (quotetype, inlines) + local content = pandocAstParse(inlines) if quotetype.t == "DoubleQuote" then - return pandocAstParse({ "“", inlines, "”" }) + return utils.createCommand("doublequoted", {}, content) end - return pandocAstParse({ "‘", inlines, "’" }) + return utils.createCommand("singlequoted", content) end -- Cite [Citation] [Inline] diff --git a/markdown.sile-dev-1.rockspec b/markdown.sile-dev-1.rockspec index 2b9c178..f5f2998 100644 --- a/markdown.sile-dev-1.rockspec +++ b/markdown.sile-dev-1.rockspec @@ -16,7 +16,8 @@ description = { dependencies = { "lua >= 5.1", "ptable.sile", - "textsubsuper.sile" + "textsubsuper.sile", + "smartquotes.sile" } build = { diff --git a/packages/markdown/commands.lua b/packages/markdown/commands.lua index 0ea338a..ea8fc53 100644 --- a/packages/markdown/commands.lua +++ b/packages/markdown/commands.lua @@ -92,6 +92,7 @@ function package:_init (_) self.class:loadPackage("lists") self.class:loadPackage("ptable") self.class:loadPackage("rules") + self.class:loadPackage("smartquotes") self.class:loadPackage("svg") self.class:loadPackage("textsubsuper") self.class:loadPackage("url")