mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-25 09:47:06 +00:00
RST writer: don't backslash-escape word-internal punctuation.
Closes #3978.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
```
|
||||
% pandoc -t rst
|
||||
foo_bar*baz
|
||||
^D
|
||||
foo_bar*baz
|
||||
```
|
||||
+1
-1
@@ -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>`__
|
||||
|
||||
|
||||
Reference in New Issue
Block a user