From f4b7ab125e0eb034b4f90448f093d4c4a2284589 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 10 Oct 2016 11:23:04 +0200 Subject: More checks for Ext_raw_html when rendering HTML in Markdown. Previously we'd emit raw HTML tables even if the `raw_html` extension was disabled. Now we just emit `[TABLE]` if no table formats are enabled and raw HTML is not enabled. We also check for the `raw_html` extension before emiting a raw HTML block. Closes #3154. --- src/Text/Pandoc/Writers/Markdown.hs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/Text/Pandoc/Writers') diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index b04e33085..addcdf6a1 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -346,19 +346,20 @@ blockToMarkdown opts (Para [Image attr alt (src,'f':'i':'g':':':tit)]) = blockToMarkdown opts (Para inlines) = (<> blankline) `fmap` blockToMarkdown opts (Plain inlines) blockToMarkdown opts (RawBlock f str) - | f == "html" = do + | f == "markdown" = return $ text str <> text "\n" + | f == "html" && isEnabled Ext_raw_html opts = do plain <- gets stPlain return $ if plain then empty else if isEnabled Ext_markdown_attribute opts then text (addMarkdownAttribute str) <> text "\n" else text str <> text "\n" - | f `elem` ["latex", "tex", "markdown"] = do + | f `elem` ["latex", "tex"] && isEnabled Ext_raw_tex opts = do plain <- gets stPlain return $ if plain then empty else text str <> text "\n" -blockToMarkdown _ (RawBlock _ _) = return empty + | otherwise = return empty blockToMarkdown opts HorizontalRule = do return $ blankline <> text (replicate (writerColumns opts) '-') <> blankline blockToMarkdown opts (Header level attr inlines) = do @@ -460,9 +461,10 @@ blockToMarkdown opts t@(Table caption aligns widths headers rows) = do | isEnabled Ext_grid_tables opts -> fmap (id,) $ gridTable opts (all null headers) aligns widths rawHeaders rawRows - | otherwise -> fmap (id,) $ + | isEnabled Ext_raw_html opts -> fmap (id,) $ return $ text $ writeHtmlString def $ Pandoc nullMeta [t] + | otherwise -> return $ (id, text "[TABLE]") return $ nst $ tbl $$ blankline $$ caption'' $$ blankline blockToMarkdown opts (BulletList items) = do contents <- inList $ mapM (bulletListItemToMarkdown opts) items @@ -680,7 +682,9 @@ blockListToMarkdown opts blocks = isListBlock (OrderedList _ _) = True isListBlock (DefinitionList _) = True isListBlock _ = False - commentSep = RawBlock "html" "\n" + commentSep = if isEnabled Ext_raw_html opts + then RawBlock "html" "\n" + else RawBlock "markdown" " " -- | Get reference for target; if none exists, create unique one and return. -- Prefer label if possible; otherwise, generate a unique key. -- cgit v1.2.3