git.iko.soy/typeable/pandoc
on master help sign in
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.

commit361167deff57e0e2d3508c598785a7de7b887fb7 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 30 Mar 2014, 15:48 (13 years ago) parent69a7c9f
1 file changed+5−1
src/Text/Pandoc/Writers/Markdown.hs+5−1
src/Text/Pandoc/Writers/Markdown.hs+5−1
@@ -392,7 +392,11 @@ blockToMarkdown opts (CodeBlock attribs str) = return $
392392 xs -> case maximum $ map length xs of
393393 n | n < 3 -> "~~~~"
394394 | otherwise -> replicate (n+1) '~'
395− backticks = text "```"
395+ backticks = text $ case [ln | ln <- lines str, all (=='`') ln] of
396+ [] -> "```"
397+ xs -> case maximum $ map length xs of
398+ n | n < 3 -> "```"
399+ | otherwise -> replicate (n+1) '`'
396400 attrs = if isEnabled Ext_fenced_code_attributes opts
397401 then nowrap $ " " <> attrsToMarkdown attribs
398402 else case attribs of