diff options
-rw-r--r-- | src/Text/Pandoc/Writers/RST.hs | 33 | ||||
-rw-r--r-- | test/command/3978.md | 6 | ||||
-rw-r--r-- | test/writer.rst | 2 |
3 files changed, 25 insertions, 16 deletions
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 diff --git a/test/command/3978.md b/test/command/3978.md new file mode 100644 index 000000000..2399ae6e6 --- /dev/null +++ b/test/command/3978.md @@ -0,0 +1,6 @@ +``` +% pandoc -t rst +foo_bar*baz +^D +foo_bar*baz +``` diff --git a/test/writer.rst b/test/writer.rst index e81e79f3f..def149feb 100644 --- a/test/writer.rst +++ b/test/writer.rst @@ -772,7 +772,7 @@ Just a `URL </url/>`__. `URL and title </url/>`__ -`with\_underscore </url/with_underscore>`__ +`with_underscore </url/with_underscore>`__ `Email link <mailto:nobody@nowhere.net>`__ |