aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-03-08 12:06:08 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-03-08 12:06:08 +0100
commit2645ce7acacc9050643cad1dbdf0d9759270765c (patch)
tree9f46561cb13f1910c50f4801f1031aa96e7fd871
parent5418f202dffbcfe05ad794eb07f730631cb3ede1 (diff)
downloadpandoc-2645ce7acacc9050643cad1dbdf0d9759270765c.tar.gz
Markdown writer: escape unordered list markers at beginning of paragraph
to avoid false interpretation as a list. Also handle `|`, and refactor code for escaping `%`. Closes #3497.
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index 96d46ae5b..844df3345 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -398,18 +398,26 @@ blockToMarkdown' opts (Plain inlines) = do
then Just $ writerColumns opts
else Nothing
let rendered = render colwidth contents
- let escapeDelimiter (x:xs) | x `elem` (".()" :: String) = '\\':x:xs
- | otherwise = x : escapeDelimiter xs
- escapeDelimiter [] = []
- let contents' = if isEnabled Ext_all_symbols_escapable opts &&
- not isPlain && beginsWithOrderedListMarker rendered
- then text $ escapeDelimiter rendered
- else contents
- -- escape if para starts with %
- return $
- if isEnabled Ext_pandoc_title_block opts && take 1 rendered == "%"
- then "\\" <> contents' <> cr
- else contents' <> cr
+ let escapeMarker (x:xs) | x `elem` (".()" :: String) = '\\':x:xs
+ | otherwise = x : escapeMarker xs
+ escapeMarker [] = []
+ let contents' =
+ case rendered of
+ '%':_ | isEnabled Ext_pandoc_title_block opts &&
+ isEnabled Ext_all_symbols_escapable opts ->
+ "\\" <> contents
+ '+':s:_ | not isPlain && isSpace s -> "\\" <> contents
+ '*':s:_ | not isPlain && isSpace s -> "\\" <> contents
+ '-':s:_ | not isPlain && isSpace s -> "\\" <> contents
+ '|':_ | (isEnabled Ext_line_blocks opts ||
+ isEnabled Ext_pipe_tables opts)
+ && isEnabled Ext_all_symbols_escapable opts
+ -> "\\" <> contents
+ _ | not isPlain && beginsWithOrderedListMarker rendered
+ && isEnabled Ext_all_symbols_escapable opts
+ -> text $ escapeMarker rendered
+ | otherwise -> contents
+ return $ contents' <> cr
-- title beginning with fig: indicates figure
blockToMarkdown' opts (Para [Image attr alt (src,'f':'i':'g':':':tit)]) =
blockToMarkdown opts (Para [Image attr alt (src,tit)])