Markdown writer: avoid unnecessary escapes before intraword `_`
when `intraword_underscores` extension is enabled.
Closes #6296.
commit9a809d4d01f1a9cba4401e98d95cccf8a0ec7e75
authorJohn MacFarlane <jgm@berkeley.edu>
dateFri 17 Apr 2020, 22:42 (7 years ago)
parent0d2b8e3
src/Text/Pandoc/Writers/Markdown.hs+6−1
@@ -313,7 +313,12 @@ escapeText opts =
313313 case cs of
314314 '.':'.':rest -> '\\':'.':'.':'.':go rest
315315 _ -> '.':go cs
316− _ -> c : go cs
316+ _ -> case cs of
317+ '_':x:xs
318+ | isEnabled Ext_intraword_underscores opts
319+ , isAlphaNum c
320+ , isAlphaNum x -> c : '_' : x : go xs
321+ _ -> c : go cs
317322
318323attrsToMarkdown :: Attr -> Doc Text
319324attrsToMarkdown attribs = braces $ hsep [attribId, attribClasses, attribKeys]
test/command/6296.mdnew file+14
@@ -0,0 +1,14 @@
1+```
2+% pandoc -f native -t markdown
3+[Str "_hi_there"]
4+^D
5+\_hi_there
6+```
7+
8+```
9+% pandoc -f native -t markdown-intraword_underscores
10+[Str "_hi_there"]
11+^D
12+\_hi\_there
13+```
14+
test/writer.markdown+1−1
@@ -683,7 +683,7 @@ Just a [URL](/url/).
683683
684684[URL and title](/url/ "title with single quotes")
685685
686−[with\_underscore](/url/with_underscore)
686+[with_underscore](/url/with_underscore)
687687
688688[Email link](mailto:nobody@nowhere.net)
689689