git.iko.soy/typeable/pandoc
on master help sign in
Markdown writer: Respect -raw_html.

pandoc -t markdown-raw_html should not emit any raw HTML, even span and div tags that go with pandoc Span and Div elements. Cleaned up a bit of the logic with extensions and plain.

commitf723a0575d242191638a564554230b8197f127fd authorJohn MacFarlane <jgm@berkeley.edu> dateFri 8 Aug 2014, 13:34 (12 years ago) parent7b47042
2 files changed+15−13
src/Text/Pandoc/Writers/Markdown.hs+14−12 tests/writer.plain+1−1
src/Text/Pandoc/Writers/Markdown.hs+14−12
@@ -80,6 +80,8 @@ writePlain opts document =
8080 writerExtensions = Set.delete Ext_escaped_line_breaks $
8181 Set.delete Ext_pipe_tables $
8282 Set.delete Ext_raw_html $
83+ Set.delete Ext_markdown_in_html_blocks $
84+ Set.delete Ext_raw_tex $
8385 Set.delete Ext_footnotes $
8486 Set.delete Ext_tex_math_dollars $
8587 Set.delete Ext_citations $
@@ -296,12 +298,12 @@ blockToMarkdown :: WriterOptions -- ^ Options
296298 -> State WriterState Doc
297299blockToMarkdown _ Null = return empty
298300blockToMarkdown opts (Div attrs ils) = do
299− plain <- gets stPlain
300301 contents <- blockListToMarkdown opts ils
301− return $ if plain || not (isEnabled Ext_markdown_in_html_blocks opts)
302− then contents <> blankline
303− else tagWithAttrs "div" attrs <> blankline <>
302+ return $ if isEnabled Ext_raw_html opts &&
303+ isEnabled Ext_markdown_in_html_blocks opts
304+ then tagWithAttrs "div" attrs <> blankline <>
304305 contents <> blankline <> "</div>" <> blankline
306+ else contents <> blankline
305307blockToMarkdown opts (Plain inlines) = do
306308 contents <- inlineListToMarkdown opts inlines
307309 -- escape if para starts with ordered list marker
@@ -676,11 +678,10 @@ escapeSpaces x = x
676678-- | Convert Pandoc inline element to markdown.
677679inlineToMarkdown :: WriterOptions -> Inline -> State WriterState Doc
678680inlineToMarkdown opts (Span attrs ils) = do
679− plain <- gets stPlain
680681 contents <- inlineListToMarkdown opts ils
681− return $ if plain
682− then contents
683− else tagWithAttrs "span" attrs <> contents <> text "</span>"
682+ return $ if isEnabled Ext_raw_html opts
683+ then tagWithAttrs "span" attrs <> contents <> text "</span>"
684+ else contents
684685inlineToMarkdown opts (Emph lst) = do
685686 plain <- gets stPlain
686687 contents <- inlineListToMarkdown opts lst
@@ -696,8 +697,7 @@ inlineToMarkdown opts (Strong lst) = do
696697 return $ "**" <> contents <> "**"
697698inlineToMarkdown opts (Strikeout lst) = do
698699 contents <- inlineListToMarkdown opts lst
699− plain <- gets stPlain
700− return $ if plain || isEnabled Ext_strikeout opts
700+ return $ if isEnabled Ext_strikeout opts
701701 then "~~" <> contents <> "~~"
702702 else "<s>" <> contents <> "</s>"
703703inlineToMarkdown opts (Superscript lst) = do
@@ -767,8 +767,10 @@ inlineToMarkdown opts (Math DisplayMath str)
767767 inlineListToMarkdown opts (texMathToInlines DisplayMath str)
768768inlineToMarkdown opts (RawInline f str) = do
769769 plain <- gets stPlain
770− if not plain && f == "html" || f == "markdown" ||
771− (isEnabled Ext_raw_tex opts && (f == "latex" || f == "tex"))
770+ if not plain &&
771+ ( f == "markdown" ||
772+ (isEnabled Ext_raw_tex opts && (f == "latex" || f == "tex")) ||
773+ (isEnabled Ext_raw_html opts && f == "html") )
772774 then return $ text str
773775 else return empty
774776inlineToMarkdown opts (LineBreak) = do
tests/writer.plain+1−1
@@ -486,7 +486,7 @@ Ellipses…and…and….
486486LaTeX
487487
488488
489−- \cite[22-23]{smith.1899}
489+-
490490- 2 + 2 = 4
491491- x ∈ y
492492- α ∧ ω