From 9a809d4d01f1a9cba4401e98d95cccf8a0ec7e75 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 17 Apr 2020 22:42:21 -0700 Subject: Markdown writer: avoid unnecessary escapes before intraword `_` when `intraword_underscores` extension is enabled. Closes #6296. --- src/Text/Pandoc/Writers/Markdown.hs | 7 ++++++- test/command/6296.md | 14 ++++++++++++++ test/writer.markdown | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 test/command/6296.md diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index 7a11e3c16..fb9888b24 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -313,7 +313,12 @@ escapeText opts = case cs of '.':'.':rest -> '\\':'.':'.':'.':go rest _ -> '.':go cs - _ -> c : go cs + _ -> case cs of + '_':x:xs + | isEnabled Ext_intraword_underscores opts + , isAlphaNum c + , isAlphaNum x -> c : '_' : x : go xs + _ -> c : go cs attrsToMarkdown :: Attr -> Doc Text attrsToMarkdown attribs = braces $ hsep [attribId, attribClasses, attribKeys] diff --git a/test/command/6296.md b/test/command/6296.md new file mode 100644 index 000000000..f4ce6b6d5 --- /dev/null +++ b/test/command/6296.md @@ -0,0 +1,14 @@ +``` +% pandoc -f native -t markdown +[Str "_hi_there"] +^D +\_hi_there +``` + +``` +% pandoc -f native -t markdown-intraword_underscores +[Str "_hi_there"] +^D +\_hi\_there +``` + diff --git a/test/writer.markdown b/test/writer.markdown index 7393ee18e..ec867fa47 100644 --- a/test/writer.markdown +++ b/test/writer.markdown @@ -683,7 +683,7 @@ Just a [URL](/url/). [URL and title](/url/ "title with single quotes") -[with\_underscore](/url/with_underscore) +[with_underscore](/url/with_underscore) [Email link](mailto:nobody@nowhere.net) -- cgit v1.2.3