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