aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-03-30 15:48:40 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2014-03-30 15:50:01 -0700
commit361167deff57e0e2d3508c598785a7de7b887fb7 (patch)
tree6dd66ea970370ad64e0ec1a74af3e4e3829dcfdc /src/Text/Pandoc
parent69a7c9f634b1e9133f7c6e4e135404bdf8caa3ab (diff)
downloadpandoc-361167deff57e0e2d3508c598785a7de7b887fb7.tar.gz
Markdown writer: Use longer backtick fences if needed.
If the content contains a backtick fence and there are attributes, make sure longer fences are used to delimit the code. Note: This works well in pandoc, but github markdown is more limited, and will interpret the first string of three or more backticks as ending the code block. Closes #1206.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index 278e5cc9d..e8f976da1 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -392,7 +392,11 @@ blockToMarkdown opts (CodeBlock attribs str) = return $
xs -> case maximum $ map length xs of
n | n < 3 -> "~~~~"
| otherwise -> replicate (n+1) '~'
- backticks = text "```"
+ backticks = text $ case [ln | ln <- lines str, all (=='`') ln] of
+ [] -> "```"
+ xs -> case maximum $ map length xs of
+ n | n < 3 -> "```"
+ | otherwise -> replicate (n+1) '`'
attrs = if isEnabled Ext_fenced_code_attributes opts
then nowrap $ " " <> attrsToMarkdown attribs
else case attribs of