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.
This commit is contained in:
John MacFarlane 2014-03-30 15:48:40 -07:00
parent 69a7c9f634
commit 361167deff

View file

@ -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