git.iko.soy/typeable/pandoc
on master help sign in
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.

commit2645ce7acacc9050643cad1dbdf0d9759270765c authorJohn MacFarlane <jgm@berkeley.edu> dateWed 8 Mar 2017, 12:06 (10 years ago) parent5418f20
1 file changed+20−12
src/Text/Pandoc/Writers/Markdown.hs+20−12
src/Text/Pandoc/Writers/Markdown.hs+20−12
@@ -398,18 +398,26 @@ blockToMarkdown' opts (Plain inlines) = do
398398 then Just $ writerColumns opts
399399 else Nothing
400400 let rendered = render colwidth contents
401− let escapeDelimiter (x:xs) | x `elem` (".()" :: String) = '\\':x:xs
402− | otherwise = x : escapeDelimiter xs
403− escapeDelimiter [] = []
404− let contents' = if isEnabled Ext_all_symbols_escapable opts &&
405− not isPlain && beginsWithOrderedListMarker rendered
406− then text $ escapeDelimiter rendered
407− else contents
408− -- escape if para starts with %
409− return $
410− if isEnabled Ext_pandoc_title_block opts && take 1 rendered == "%"
411− then "\\" <> contents' <> cr
412− else contents' <> cr
401+ let escapeMarker (x:xs) | x `elem` (".()" :: String) = '\\':x:xs
402+ | otherwise = x : escapeMarker xs
403+ escapeMarker [] = []
404+ let contents' =
405+ case rendered of
406+ '%':_ | isEnabled Ext_pandoc_title_block opts &&
407+ isEnabled Ext_all_symbols_escapable opts ->
408+ "\\" <> contents
409+ '+':s:_ | not isPlain && isSpace s -> "\\" <> contents
410+ '*':s:_ | not isPlain && isSpace s -> "\\" <> contents
411+ '-':s:_ | not isPlain && isSpace s -> "\\" <> contents
412+ '|':_ | (isEnabled Ext_line_blocks opts ||
413+ isEnabled Ext_pipe_tables opts)
414+ && isEnabled Ext_all_symbols_escapable opts
415+ -> "\\" <> contents
416+ _ | not isPlain && beginsWithOrderedListMarker rendered
417+ && isEnabled Ext_all_symbols_escapable opts
418+ -> text $ escapeMarker rendered
419+ | otherwise -> contents
420+ return $ contents' <> cr
413421-- title beginning with fig: indicates figure
414422blockToMarkdown' opts (Para [Image attr alt (src,'f':'i':'g':':':tit)]) =
415423 blockToMarkdown opts (Para [Image attr alt (src,tit)])