From 5affa30e8ad8b5c6ce31240ecd271fd4cccab219 Mon Sep 17 00:00:00 2001 From: John MacFarlane <jgm@berkeley.edu> Date: Sun, 5 May 2019 21:47:15 -0700 Subject: [PATCH] Asciidoc writer: use proper smart quotes with asciidoctor. Asciidoctor has a different format for smart quotes. Closes #5487. --- src/Text/Pandoc/Writers/AsciiDoc.hs | 14 ++++++++++---- test/writer.asciidoctor | 16 ++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/Text/Pandoc/Writers/AsciiDoc.hs b/src/Text/Pandoc/Writers/AsciiDoc.hs index 472fb6a91..47738e69d 100644 --- a/src/Text/Pandoc/Writers/AsciiDoc.hs +++ b/src/Text/Pandoc/Writers/AsciiDoc.hs @@ -425,10 +425,16 @@ inlineToAsciiDoc opts (Subscript lst) = do contents <- inlineListToAsciiDoc opts lst return $ "~" <> contents <> "~" inlineToAsciiDoc opts (SmallCaps lst) = inlineListToAsciiDoc opts lst -inlineToAsciiDoc opts (Quoted SingleQuote lst) = - inlineListToAsciiDoc opts (Str "`" : lst ++ [Str "'"]) -inlineToAsciiDoc opts (Quoted DoubleQuote lst) = - inlineListToAsciiDoc opts (Str "``" : lst ++ [Str "''"]) +inlineToAsciiDoc opts (Quoted qt lst) = do + isAsciidoctor <- gets asciidoctorVariant + inlineListToAsciiDoc opts $ + case qt of + SingleQuote + | isAsciidoctor -> [Str "'`"] ++ lst ++ [Str "`'"] + | otherwise -> [Str "`"] ++ lst ++ [Str "'"] + DoubleQuote + | isAsciidoctor -> [Str "\"`"] ++ lst ++ [Str "`\""] + | otherwise -> [Str "``"] ++ lst ++ [Str "''"] inlineToAsciiDoc _ (Code _ str) = return $ text "`" <> text (escapeStringUsing (backslashEscapes "`") str) <> "`" inlineToAsciiDoc _ (Str str) = return $ text $ escapeString str diff --git a/test/writer.asciidoctor b/test/writer.asciidoctor index 8b388e55f..d72b1876f 100644 --- a/test/writer.asciidoctor +++ b/test/writer.asciidoctor @@ -439,16 +439,16 @@ spaces: a^b c^d, a~b c~d. == Smart quotes, ellipses, dashes -``Hello,'' said the spider. ```Shelob' is my name.'' +"`Hello,`" said the spider. "`'`Shelob`' is my name.`" -`A', `B', and `C' are letters. +'`A`', '`B`', and '`C`' are letters. -`Oak,' `elm,' and `beech' are names of trees. So is `pine.' +'`Oak,`' '`elm,`' and '`beech`' are names of trees. So is '`pine.`' -`He said, ``I want to go.''' Were you alive in the 70’s? +'`He said, "`I want to go.`"`' Were you alive in the 70’s? -Here is some quoted ``code`' and a ``http://example.com/?foo=1&bar=2[quoted -link]''. +Here is some quoted '``code``' and a "`http://example.com/?foo=1&bar=2[quoted +link]`". Some dashes: one—two — three—four — five. @@ -478,7 +478,7 @@ latexmath:[\alpha + \omega \times x^2]. These shouldn’t be math: * To get the famous equation, write `$e = mc^2$`. -* $22,000 is a _lot_ of money. So is $34,000. (It worked if ``lot'' is +* $22,000 is a _lot_ of money. So is $34,000. (It worked if "`lot`" is emphasized.) * Shoes ($20) and socks ($5). * Escaped `$`: $73 _this should be emphasized_ 23$. @@ -621,7 +621,7 @@ or here: <http://example.com/> == Images -From ``Voyage dans la Lune'' by Georges Melies (1902): +From "`Voyage dans la Lune`" by Georges Melies (1902): image:lalune.jpg[lalune,title="Voyage dans la Lune"]