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.
This commit is contained in:
John MacFarlane 2014-08-08 13:34:57 -07:00
parent 7b47042ae6
commit f723a0575d
2 changed files with 15 additions and 13 deletions

View file

@ -80,6 +80,8 @@ writePlain opts document =
writerExtensions = Set.delete Ext_escaped_line_breaks $ writerExtensions = Set.delete Ext_escaped_line_breaks $
Set.delete Ext_pipe_tables $ Set.delete Ext_pipe_tables $
Set.delete Ext_raw_html $ Set.delete Ext_raw_html $
Set.delete Ext_markdown_in_html_blocks $
Set.delete Ext_raw_tex $
Set.delete Ext_footnotes $ Set.delete Ext_footnotes $
Set.delete Ext_tex_math_dollars $ Set.delete Ext_tex_math_dollars $
Set.delete Ext_citations $ Set.delete Ext_citations $
@ -296,12 +298,12 @@ blockToMarkdown :: WriterOptions -- ^ Options
-> State WriterState Doc -> State WriterState Doc
blockToMarkdown _ Null = return empty blockToMarkdown _ Null = return empty
blockToMarkdown opts (Div attrs ils) = do blockToMarkdown opts (Div attrs ils) = do
plain <- gets stPlain
contents <- blockListToMarkdown opts ils contents <- blockListToMarkdown opts ils
return $ if plain || not (isEnabled Ext_markdown_in_html_blocks opts) return $ if isEnabled Ext_raw_html opts &&
then contents <> blankline isEnabled Ext_markdown_in_html_blocks opts
else tagWithAttrs "div" attrs <> blankline <> then tagWithAttrs "div" attrs <> blankline <>
contents <> blankline <> "</div>" <> blankline contents <> blankline <> "</div>" <> blankline
else contents <> blankline
blockToMarkdown opts (Plain inlines) = do blockToMarkdown opts (Plain inlines) = do
contents <- inlineListToMarkdown opts inlines contents <- inlineListToMarkdown opts inlines
-- escape if para starts with ordered list marker -- escape if para starts with ordered list marker
@ -676,11 +678,10 @@ escapeSpaces x = x
-- | Convert Pandoc inline element to markdown. -- | Convert Pandoc inline element to markdown.
inlineToMarkdown :: WriterOptions -> Inline -> State WriterState Doc inlineToMarkdown :: WriterOptions -> Inline -> State WriterState Doc
inlineToMarkdown opts (Span attrs ils) = do inlineToMarkdown opts (Span attrs ils) = do
plain <- gets stPlain
contents <- inlineListToMarkdown opts ils contents <- inlineListToMarkdown opts ils
return $ if plain return $ if isEnabled Ext_raw_html opts
then contents then tagWithAttrs "span" attrs <> contents <> text "</span>"
else tagWithAttrs "span" attrs <> contents <> text "</span>" else contents
inlineToMarkdown opts (Emph lst) = do inlineToMarkdown opts (Emph lst) = do
plain <- gets stPlain plain <- gets stPlain
contents <- inlineListToMarkdown opts lst contents <- inlineListToMarkdown opts lst
@ -696,8 +697,7 @@ inlineToMarkdown opts (Strong lst) = do
return $ "**" <> contents <> "**" return $ "**" <> contents <> "**"
inlineToMarkdown opts (Strikeout lst) = do inlineToMarkdown opts (Strikeout lst) = do
contents <- inlineListToMarkdown opts lst contents <- inlineListToMarkdown opts lst
plain <- gets stPlain return $ if isEnabled Ext_strikeout opts
return $ if plain || isEnabled Ext_strikeout opts
then "~~" <> contents <> "~~" then "~~" <> contents <> "~~"
else "<s>" <> contents <> "</s>" else "<s>" <> contents <> "</s>"
inlineToMarkdown opts (Superscript lst) = do inlineToMarkdown opts (Superscript lst) = do
@ -767,8 +767,10 @@ inlineToMarkdown opts (Math DisplayMath str)
inlineListToMarkdown opts (texMathToInlines DisplayMath str) inlineListToMarkdown opts (texMathToInlines DisplayMath str)
inlineToMarkdown opts (RawInline f str) = do inlineToMarkdown opts (RawInline f str) = do
plain <- gets stPlain plain <- gets stPlain
if not plain && f == "html" || f == "markdown" || if not plain &&
(isEnabled Ext_raw_tex opts && (f == "latex" || f == "tex")) ( f == "markdown" ||
(isEnabled Ext_raw_tex opts && (f == "latex" || f == "tex")) ||
(isEnabled Ext_raw_html opts && f == "html") )
then return $ text str then return $ text str
else return empty else return empty
inlineToMarkdown opts (LineBreak) = do inlineToMarkdown opts (LineBreak) = do

View file

@ -486,7 +486,7 @@ Ellipses…and…and….
LaTeX LaTeX
- \cite[22-23]{smith.1899} -
- 2+2=4 - 2+2=4
- xy - xy
- α ∧ ω - α ∧ ω