Markdown writer: Better escaping when +smart.
This commit is contained in:
parent
cb1b0bcba7
commit
e0abe18bb9
1 changed files with 21 additions and 17 deletions
|
@ -267,23 +267,27 @@ noteToMarkdown opts num blocks = do
|
||||||
|
|
||||||
-- | Escape special characters for Markdown.
|
-- | Escape special characters for Markdown.
|
||||||
escapeString :: WriterOptions -> String -> String
|
escapeString :: WriterOptions -> String -> String
|
||||||
escapeString opts = escapeStringUsing markdownEscapes
|
escapeString _ [] = []
|
||||||
where markdownEscapes = ('<', "<") : ('>', ">") :
|
escapeString opts (c:cs) =
|
||||||
backslashEscapes specialChars
|
case c of
|
||||||
specialChars =
|
'<' -> "<" ++ escapeString opts cs
|
||||||
(if isEnabled Ext_superscript opts
|
'>' -> ">" ++ escapeString opts cs
|
||||||
then ('^':)
|
_ | c `elem` ['\\','`','*','_','[',']','#'] ->
|
||||||
else id) .
|
'\\':c:escapeString opts cs
|
||||||
(if isEnabled Ext_subscript opts
|
'^' | isEnabled Ext_superscript opts -> '\\':'^':escapeString opts cs
|
||||||
then ('~':)
|
'~' | isEnabled Ext_subscript opts -> '\\':'~':escapeString opts cs
|
||||||
else id) .
|
'$' | isEnabled Ext_tex_math_dollars opts -> '\\':'$':escapeString opts cs
|
||||||
(if isEnabled Ext_tex_math_dollars opts
|
'\'' | isEnabled Ext_smart opts -> '\\':'\'':escapeString opts cs
|
||||||
then ('$':)
|
'"' | isEnabled Ext_smart opts -> '\\':'"':escapeString opts cs
|
||||||
else id) $
|
'-' | isEnabled Ext_smart opts ->
|
||||||
"\\`*_[]#" ++
|
case cs of
|
||||||
if isEnabled Ext_smart opts
|
'-':_ -> '\\':'-':escapeString opts cs
|
||||||
then "\"'"
|
_ -> '-':escapeString opts cs
|
||||||
else ""
|
'.' | isEnabled Ext_smart opts ->
|
||||||
|
case cs of
|
||||||
|
'.':'.':rest -> '\\':'.':'.':'.':escapeString opts rest
|
||||||
|
_ -> '.':escapeString opts cs
|
||||||
|
_ -> c : escapeString opts cs
|
||||||
|
|
||||||
-- | Construct table of contents from list of header blocks.
|
-- | Construct table of contents from list of header blocks.
|
||||||
tableOfContents :: PandocMonad m => WriterOptions -> [Block] -> m Doc
|
tableOfContents :: PandocMonad m => WriterOptions -> [Block] -> m Doc
|
||||||
|
|
Loading…
Add table
Reference in a new issue