diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-02-04 22:09:06 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-02-04 22:09:06 +0100 |
commit | 7404c83fb3338e791b8ff0dc7a21346d67f3e322 (patch) | |
tree | 1a44752e163d7ed956a41680c2f797906042ab08 | |
parent | a435422d0fb08832ecd8951bb42684aed27a7cb7 (diff) |
Improved escaping in RST writer with smart option.
-rw-r--r-- | src/Text/Pandoc/Writers/RST.hs | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs index 4e0fe1011..6093c668b 100644 --- a/src/Text/Pandoc/Writers/RST.hs +++ b/src/Text/Pandoc/Writers/RST.hs @@ -161,8 +161,22 @@ pictToRST (label, (attr, src, _, mbtarget)) = do Just t -> " :target: " <> text t -- | Escape special characters for RST. -escapeString :: String -> String -escapeString = escapeStringUsing (backslashEscapes "`\\|*_") +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 titleToRST :: [Inline] -> [Inline] -> State WriterState Doc titleToRST [] _ = return empty @@ -447,10 +461,10 @@ inlineToRST (Cite _ lst) = inlineToRST (Code _ str) = return $ "``" <> text str <> "``" inlineToRST (Str str) = do opts <- gets stOptions - let str' = if isEnabled Ext_smart opts - then unsmartify opts str - else str - return $ text $ escapeString str' + return $ text $ + (if isEnabled Ext_smart opts + then unsmartify opts + else id) $ escapeString opts str inlineToRST (Math t str) = do modify $ \st -> st{ stHasMath = True } return $ if t == InlineMath |