git.iko.soy/typeable/pandoc
on master help sign in
Markdown writer: better escaping of `<` and `>`.

If `all_symbols_escapable` is set, we backslash escape these. Otherwise we use entities as before.

commitb8afec05e0ce85ab811bf55d4948be768ad363e2 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 30 Jul 2017, 13:45 (9 years ago) parent8cbc284
2 files changed+10−6
src/Text/Pandoc/Writers/Markdown.hs+6−2 test/writer.markdown+4−4
src/Text/Pandoc/Writers/Markdown.hs+6−2
@@ -280,8 +280,12 @@ escapeString :: WriterOptions -> String -> String
280280escapeString _ [] = []
281281escapeString opts (c:cs) =
282282 case c of
283− '<' -> "&lt;" ++ escapeString opts cs
284− '>' -> "&gt;" ++ escapeString opts cs
283+ '<' | isEnabled Ext_all_symbols_escapable opts ->
284+ '\\' : '<' : escapeString opts cs
285+ | otherwise -> "&lt;" ++ escapeString opts cs
286+ '>' | isEnabled Ext_all_symbols_escapable opts ->
287+ '\\' : '>' : escapeString opts cs
288+ | otherwise -> "&gt;" ++ escapeString opts cs
285289 _ | c `elem` ['\\','`','*','_','[',']','#'] ->
286290 '\\':c:escapeString opts cs
287291 '^' | isEnabled Ext_superscript opts -> '\\':'^':escapeString opts cs
test/writer.markdown+4−4
@@ -80,7 +80,7 @@ E-mail style:
8080>
8181> > nested
8282
83−This should not be a block quote: 2 &gt; 1.
83+This should not be a block quote: 2 \> 1.
8484
8585And a following paragraph.
8686
@@ -580,9 +580,9 @@ AT&T is another way to write it.
580580
581581This & that.
582582
583−4 &lt; 5.
583+4 \< 5.
584584
585−6 &gt; 5.
585+6 \> 5.
586586
587587Backslash: \\
588588
@@ -604,7 +604,7 @@ Left paren: (
604604
605605Right paren: )
606606
607−Greater-than: &gt;
607+Greater-than: \>
608608
609609Hash: \#
610610