diff --git a/src/Text/Pandoc/Writers/Markdown/Inline.hs b/src/Text/Pandoc/Writers/Markdown/Inline.hs index 1ae7e1847..4e98530b1 100644 --- a/src/Text/Pandoc/Writers/Markdown/Inline.hs +++ b/src/Text/Pandoc/Writers/Markdown/Inline.hs @@ -68,8 +68,16 @@ escapeText opts = T.pack . go' . T.unpack go [] = [] go (c:cs) = case c of - _ | c `elem` ['\\','`','*','_','[',']'] -> - '\\':c:go cs + '[' -> '\\':c:go cs + ']' -> '\\':c:go cs + '`' -> '\\':c:go cs + '*' -> '\\':c:go cs + '_' -> '\\':c:go cs + '\\' | isEnabled Ext_raw_tex opts -> '\\':c:go cs + | otherwise -> + case cs of -- don't escape \ if we don't have to: + d:_ | isAlphaNum d -> c:go cs + _ -> '\\':c:go cs '>' | isEnabled Ext_all_symbols_escapable opts -> '\\':'>':go cs | otherwise -> ">" ++ go cs '<' | isEnabled Ext_all_symbols_escapable opts -> '\\':'<':go cs diff --git a/test/command/4527.md b/test/command/4527.md index 2f54fca60..c1e0f6ad6 100644 --- a/test/command/4527.md +++ b/test/command/4527.md @@ -1,24 +1,11 @@ -# Raw TeX blocks in CommonMark with and without raw_tex - +This command comes through as regular text: ``` -% pandoc -f latex+raw_tex -t commonmark-raw_tex -\someunknowncommand - -Hello. +% pandoc -f latex+raw_tex -t native +\maketitle ^D -Hello. +[ RawBlock (Format "latex") "\\maketitle" ] ``` -``` -% pandoc -f latex+raw_tex -t commonmark+raw_tex -\someunknowncommand - -Hello. -^D -\someunknowncommand - -Hello. -``` ``` % pandoc -f latex -t native diff --git a/test/writer.opml b/test/writer.opml index 6bdcb882e..4d2a412f2 100644 --- a/test/writer.opml +++ b/test/writer.opml @@ -50,7 +50,7 @@ - +