summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-07-30 13:45:22 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2017-07-30 13:45:22 -0700
commitb8afec05e0ce85ab811bf55d4948be768ad363e2 (patch)
tree987e8334e08d2415bf4707bed7e1ec618f531812
parent8cbc28415ef7246e9eb5b74d8958f1ab0dc01d4d (diff)
Markdown writer: better escaping of `<` and `>`.
If `all_symbols_escapable` is set, we backslash escape these. Otherwise we use entities as before.
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs8
-rw-r--r--test/writer.markdown8
2 files changed, 10 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index 1e0d8bde2..837c177f1 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -280,8 +280,12 @@ escapeString :: WriterOptions -> String -> String
escapeString _ [] = []
escapeString opts (c:cs) =
case c of
- '<' -> "&lt;" ++ escapeString opts cs
- '>' -> "&gt;" ++ escapeString opts cs
+ '<' | isEnabled Ext_all_symbols_escapable opts ->
+ '\\' : '<' : escapeString opts cs
+ | otherwise -> "&lt;" ++ escapeString opts cs
+ '>' | isEnabled Ext_all_symbols_escapable opts ->
+ '\\' : '>' : escapeString opts cs
+ | otherwise -> "&gt;" ++ escapeString opts cs
_ | c `elem` ['\\','`','*','_','[',']','#'] ->
'\\':c:escapeString opts cs
'^' | isEnabled Ext_superscript opts -> '\\':'^':escapeString opts cs
diff --git a/test/writer.markdown b/test/writer.markdown
index d41030785..0cc465f1e 100644
--- a/test/writer.markdown
+++ b/test/writer.markdown
@@ -80,7 +80,7 @@ E-mail style:
>
> > nested
-This should not be a block quote: 2 &gt; 1.
+This should not be a block quote: 2 \> 1.
And a following paragraph.
@@ -580,9 +580,9 @@ AT&T is another way to write it.
This & that.
-4 &lt; 5.
+4 \< 5.
-6 &gt; 5.
+6 \> 5.
Backslash: \\
@@ -604,7 +604,7 @@ Left paren: (
Right paren: )
-Greater-than: &gt;
+Greater-than: \>
Hash: \#