git.iko.soy/typeable/pandoc
on master help sign in
Markdown writer: Respect -raw_html.
f723a05John MacFarlane
src/Text/Pandoc/Writers/Markdown.hs+14−12
@@ -80,6 +80,8 @@ writePlain opts document =
80 writerExtensions = Set.delete Ext_escaped_line_breaks $
80 writerExtensions = Set.delete Ext_escaped_line_breaks $
81 Set.delete Ext_pipe_tables $
81 Set.delete Ext_pipe_tables $
82 Set.delete Ext_raw_html $
82 Set.delete Ext_raw_html $
83+ Set.delete Ext_markdown_in_html_blocks $
84+ Set.delete Ext_raw_tex $
83 Set.delete Ext_footnotes $
85 Set.delete Ext_footnotes $
84 Set.delete Ext_tex_math_dollars $
86 Set.delete Ext_tex_math_dollars $
85 Set.delete Ext_citations $
87 Set.delete Ext_citations $
@@ -296,12 +298,12 @@ blockToMarkdown :: WriterOptions -- ^ Options
296 -> State WriterState Doc
298 -> State WriterState Doc
297blockToMarkdown _ Null = return empty
299blockToMarkdown _ Null = return empty
298blockToMarkdown opts (Div attrs ils) = do
300blockToMarkdown opts (Div attrs ils) = do
299− plain <- gets stPlain
300 contents <- blockListToMarkdown opts ils
301 contents <- blockListToMarkdown opts ils
302+ return $ if isEnabled Ext_raw_html opts &&
301− return $ if plain || not (isEnabled Ext_markdown_in_html_blocks opts)
303+ isEnabled Ext_markdown_in_html_blocks opts
302− then contents <> blankline
303− else tagWithAttrs "div" attrs <> blankline <>
304+ then tagWithAttrs "div" attrs <> blankline <>
304 contents <> blankline <> "</div>" <> blankline
305 contents <> blankline <> "</div>" <> blankline
306+ else contents <> blankline
305blockToMarkdown opts (Plain inlines) = do
307blockToMarkdown opts (Plain inlines) = do
306 contents <- inlineListToMarkdown opts inlines
308 contents <- inlineListToMarkdown opts inlines
307 -- escape if para starts with ordered list marker
309 -- escape if para starts with ordered list marker
@@ -676,11 +678,10 @@ escapeSpaces x = x
676-- | Convert Pandoc inline element to markdown.
678-- | Convert Pandoc inline element to markdown.
677inlineToMarkdown :: WriterOptions -> Inline -> State WriterState Doc
679inlineToMarkdown :: WriterOptions -> Inline -> State WriterState Doc
678inlineToMarkdown opts (Span attrs ils) = do
680inlineToMarkdown opts (Span attrs ils) = do
679− plain <- gets stPlain
680 contents <- inlineListToMarkdown opts ils
681 contents <- inlineListToMarkdown opts ils
681− return $ if plain
682+ return $ if isEnabled Ext_raw_html opts
682− then contents
683− else tagWithAttrs "span" attrs <> contents <> text "</span>"
683+ then tagWithAttrs "span" attrs <> contents <> text "</span>"
684+ else contents
684inlineToMarkdown opts (Emph lst) = do
685inlineToMarkdown opts (Emph lst) = do
685 plain <- gets stPlain
686 plain <- gets stPlain
686 contents <- inlineListToMarkdown opts lst
687 contents <- inlineListToMarkdown opts lst
@@ -696,8 +697,7 @@ inlineToMarkdown opts (Strong lst) = do
696 return $ "**" <> contents <> "**"
697 return $ "**" <> contents <> "**"
697inlineToMarkdown opts (Strikeout lst) = do
698inlineToMarkdown opts (Strikeout lst) = do
698 contents <- inlineListToMarkdown opts lst
699 contents <- inlineListToMarkdown opts lst
699− plain <- gets stPlain
700− return $ if plain || isEnabled Ext_strikeout opts
700+ return $ if isEnabled Ext_strikeout opts
701 then "~~" <> contents <> "~~"
701 then "~~" <> contents <> "~~"
702 else "<s>" <> contents <> "</s>"
702 else "<s>" <> contents <> "</s>"
703inlineToMarkdown opts (Superscript lst) = do
703inlineToMarkdown opts (Superscript lst) = do
@@ -767,8 +767,10 @@ inlineToMarkdown opts (Math DisplayMath str)
767 inlineListToMarkdown opts (texMathToInlines DisplayMath str)
767 inlineListToMarkdown opts (texMathToInlines DisplayMath str)
768inlineToMarkdown opts (RawInline f str) = do
768inlineToMarkdown opts (RawInline f str) = do
769 plain <- gets stPlain
769 plain <- gets stPlain
770− if not plain && f == "html" || f == "markdown" ||
770+ if not plain &&
771+ ( f == "markdown" ||
771− (isEnabled Ext_raw_tex opts && (f == "latex" || f == "tex"))
772+ (isEnabled Ext_raw_tex opts && (f == "latex" || f == "tex")) ||
773+ (isEnabled Ext_raw_html opts && f == "html") )
772 then return $ text str
774 then return $ text str
773 else return empty
775 else return empty
774inlineToMarkdown opts (LineBreak) = do
776inlineToMarkdown opts (LineBreak) = do
tests/writer.plain+1−1
@@ -486,7 +486,7 @@ Ellipses…and…and….
486LaTeX
486LaTeX
487
487
488
488
489−- \cite[22-23]{smith.1899}
489+-
490- 2 + 2 = 4
490- 2 + 2 = 4
491- x ∈ y
491- x ∈ y
492- α ∧ ω
492- α ∧ ω