From cba18c19a69d05ecd3e617bcbd74780482bffd7e Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 16 Oct 2017 20:36:37 -0700 Subject: RST writer: don't backslash-escape word-internal punctuation. Closes #3978. --- src/Text/Pandoc/Writers/RST.hs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs index 94c135715..cd277b51b 100644 --- a/src/Text/Pandoc/Writers/RST.hs +++ b/src/Text/Pandoc/Writers/RST.hs @@ -169,21 +169,24 @@ pictToRST (label, (attr, src, _, mbtarget)) = do -- | Escape special characters for RST. escapeString :: WriterOptions -> String -> String -escapeString _ [] = [] -escapeString opts (c:cs) = - case c of - _ | c `elem` ['\\','`','*','_','|'] -> '\\':c:escapeString opts cs - '\'' | isEnabled Ext_smart opts -> '\\':'\'':escapeString opts cs - '"' | isEnabled Ext_smart opts -> '\\':'"':escapeString opts cs - '-' | isEnabled Ext_smart opts -> - case cs of - '-':_ -> '\\':'-':escapeString opts cs - _ -> '-':escapeString opts cs - '.' | isEnabled Ext_smart opts -> - case cs of - '.':'.':rest -> '\\':'.':'.':'.':escapeString opts rest - _ -> '.':escapeString opts cs - _ -> c : escapeString opts cs +escapeString = escapeString' True + where + escapeString' _ _ [] = [] + escapeString' firstChar opts (c:cs) = + case c of + _ | c `elem` ['\\','`','*','_','|'] && + (firstChar || null cs) -> '\\':c:escapeString' False opts cs + '\'' | isEnabled Ext_smart opts -> '\\':'\'':escapeString' False opts cs + '"' | isEnabled Ext_smart opts -> '\\':'"':escapeString' False opts cs + '-' | isEnabled Ext_smart opts -> + case cs of + '-':_ -> '\\':'-':escapeString' False opts cs + _ -> '-':escapeString' False opts cs + '.' | isEnabled Ext_smart opts -> + case cs of + '.':'.':rest -> '\\':'.':'.':'.':escapeString' False opts rest + _ -> '.':escapeString' False opts cs + _ -> c : escapeString' False opts cs titleToRST :: PandocMonad m => [Inline] -> [Inline] -> RST m Doc titleToRST [] _ = return empty -- cgit v1.2.3