@@ -444,30 +444,35 @@ blockToMarkdown' opts (LineBlock lns) =
444444 mdLines <- mapM (inlineListToMarkdown opts) lns
445445 return $ (vcat $ map (hang 2 (text "| ")) mdLines) <> blankline
446446 else blockToMarkdown opts $ linesToPara lns
447−blockToMarkdown' opts b@(RawBlock f str)
448− | f `elem` ["markdown", "markdown_github", "markdown_phpextra",
449− "markdown_mmd", "markdown_strict"]
450− = return $ text str <> text "\n"
451− | f `elem` ["html", "html5", "html4"] && isEnabled Ext_raw_html opts = do
452− plain <- asks envPlain
453− return $ if plain
454− then empty
455− else if isEnabled Ext_markdown_attribute opts
456− then text (addMarkdownAttribute str) <> text "\n"
457− else text str <> text "\n"
458− | f `elem` ["latex", "tex"] && isEnabled Ext_raw_tex opts = do
459− plain <- asks envPlain
460− return $ if plain
461− then empty
462− else text str <> text "\n"
463− | f == "plain" = do
464− plain <- asks envPlain
465− return $ if plain
466− then text str <> text "\n"
467− else empty
468− | otherwise = do
469− report $ BlockNotRendered b
470− return empty
447+blockToMarkdown' opts b@(RawBlock f str) = do
448+ plain <- asks envPlain
449+ let Format fmt = f
450+ let rawAttribBlock = return $
451+ (text "```{=" <> text fmt <> "}") $$
452+ text str $$
453+ (text "```" <> text "\n")
454+ let renderEmpty = mempty <$ report (BlockNotRendered b)
455+ case () of
456+ _ | plain -> renderEmpty
457+ | f `elem` ["markdown", "markdown_github", "markdown_phpextra",
458+ "markdown_mmd", "markdown_strict"] ->
459+ return $ text str <> text "\n"
460+ | f `elem` ["html", "html5", "html4"] ->
461+ case () of
462+ _ | isEnabled Ext_markdown_attribute opts -> return $
463+ text (addMarkdownAttribute str) <> text "\n"
464+ | isEnabled Ext_raw_html opts -> return $
465+ text str <> text "\n"
466+ | isEnabled Ext_raw_attribute opts -> rawAttribBlock
467+ | otherwise -> renderEmpty
468+ | f `elem` ["latex", "tex"] ->
469+ case () of
470+ _ | isEnabled Ext_raw_tex opts -> return $
471+ text str <> text "\n"
472+ | isEnabled Ext_raw_attribute opts -> rawAttribBlock
473+ | otherwise -> renderEmpty
474+ | isEnabled Ext_raw_attribute opts -> rawAttribBlock
475+ | otherwise -> renderEmpty
471476blockToMarkdown' opts HorizontalRule = do
472477 return $ blankline <> text (replicate (writerColumns opts) '-') <> blankline
473478blockToMarkdown' opts (Header level attr inlines) = do
@@ -1115,17 +1120,33 @@ inlineToMarkdown opts (Math DisplayMath str) =
11151120 | otherwise -> (\x -> cr <> x <> cr) `fmap`
11161121 (texMathToInlines DisplayMath str >>= inlineListToMarkdown opts)
11171122inlineToMarkdown opts il@(RawInline f str) = do
1123+ let tickGroups = filter (\s -> '`' `elem` s) $ group str
1124+ let numticks = if null tickGroups
1125+ then 1
1126+ else 1 + maximum (map length tickGroups)
11181127 plain <- asks envPlain
1119− if (plain && f == "plain") || (not plain &&
1120− ( f `elem` ["markdown", "markdown_github", "markdown_phpextra",
1121− "markdown_mmd", "markdown_strict"] ||
1122− (isEnabled Ext_raw_tex opts && (f == "latex" || f == "tex")) ||
1123− (isEnabled Ext_raw_html opts && f `elem` ["html", "html4", "html5"])
1124− ))
1125− then return $ text str
1126− else do
1127− report $ InlineNotRendered il
1128− return empty
1128+ let Format fmt = f
1129+ let rawAttribInline = return $
1130+ text (replicate numticks '`') <> text str <>
1131+ text (replicate numticks '`') <> text "{=" <> text fmt <> text "}"
1132+ let renderEmpty = mempty <$ report (InlineNotRendered il)
1133+ case () of
1134+ _ | plain -> renderEmpty
1135+ | f `elem` ["markdown", "markdown_github", "markdown_phpextra",
1136+ "markdown_mmd", "markdown_strict"] ->
1137+ return $ text str
1138+ | f `elem` ["html", "html5", "html4"] ->
1139+ case () of
1140+ _ | isEnabled Ext_raw_html opts -> return $ text str
1141+ | isEnabled Ext_raw_attribute opts -> rawAttribInline
1142+ | otherwise -> renderEmpty
1143+ | f `elem` ["latex", "tex"] ->
1144+ case () of
1145+ _ | isEnabled Ext_raw_tex opts -> return $ text str
1146+ | isEnabled Ext_raw_attribute opts -> rawAttribInline
1147+ | otherwise -> renderEmpty
1148+ | isEnabled Ext_raw_attribute opts -> rawAttribInline
1149+ | otherwise -> renderEmpty
11291150inlineToMarkdown opts (LineBreak) = do
11301151 plain <- asks envPlain
11311152 if plain || isEnabled Ext_hard_line_breaks opts