@@ -186,7 +186,12 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
186 let toc = if writerTableOfContents opts
186 let toc = if writerTableOfContents opts
187 then tableOfContents opts headerBlocks
187 then tableOfContents opts headerBlocks
188 else empty
188 else empty
189+ -- Strip off final 'references' header if markdown citations enabled
190+ let blocks' = case reverse blocks of
191+ (Div (_,["references"],_) _):xs
192+ | isEnabled Ext_citations opts -> reverse xs
189− body <- blockListToMarkdown opts blocks
194+ body <- blockListToMarkdown opts blocks'
190 st <- get
195 st <- get
191 notes' <- notesToMarkdown opts (reverse $ stNotes st)
196 notes' <- notesToMarkdown opts (reverse $ stNotes st)
192 st' <- get -- note that the notes may contain refs
197 st' <- get -- note that the notes may contain refs
@@ -304,10 +309,10 @@ blockToMarkdown _ Null = return empty
304blockToMarkdown opts (Div attrs ils) = do
309blockToMarkdown opts (Div attrs ils) = do
305 isPlain <- gets stPlain
310 isPlain <- gets stPlain
306 contents <- blockListToMarkdown opts ils
311 contents <- blockListToMarkdown opts ils
307− return $ if isPlain
312+ return $ if isPlain || not (isEnabled Ext_markdown_in_html_blocks opts)
308 then contents <> blankline
313 then contents <> blankline
309 else tagWithAttrs "div" attrs <> blankline <>
314 else tagWithAttrs "div" attrs <> blankline <>
310− contents <> blankline <> "</div>" <> blankline
315+ contents <> blankline <> "</div>" <> blankline
311blockToMarkdown opts (Plain inlines) = do
316blockToMarkdown opts (Plain inlines) = do
312 contents <- inlineListToMarkdown opts inlines
317 contents <- inlineListToMarkdown opts inlines
313 return $ contents <> cr
318 return $ contents <> cr
@@ -711,17 +716,20 @@ inlineToMarkdown opts (LineBreak)
711 | isEnabled Ext_escaped_line_breaks opts = return $ "\\" <> cr
716 | isEnabled Ext_escaped_line_breaks opts = return $ "\\" <> cr
712 | otherwise = return $ " " <> cr
717 | otherwise = return $ " " <> cr
713inlineToMarkdown _ Space = return space
718inlineToMarkdown _ Space = return space
714−inlineToMarkdown opts (Cite (c:cs) lst@[RawInline "latex" _])
719+inlineToMarkdown opts (Cite [] lst) = inlineListToMarkdown opts lst
720+inlineToMarkdown opts (Cite (c:cs) lst)
715 | not (isEnabled Ext_citations opts) = inlineListToMarkdown opts lst
721 | not (isEnabled Ext_citations opts) = inlineListToMarkdown opts lst
716− | citationMode c == AuthorInText = do
723+ if citationMode c == AuthorInText
717− suffs <- inlineListToMarkdown opts $ citationSuffix c
725+ suffs <- inlineListToMarkdown opts $ citationSuffix c
718− rest <- mapM convertOne cs
726+ rest <- mapM convertOne cs
719− let inbr = suffs <+> joincits rest
727+ let inbr = suffs <+> joincits rest
720− br = if isEmpty inbr then empty else char '[' <> inbr <> char ']'
728+ br = if isEmpty inbr then empty else char '[' <> inbr <> char ']'
721− return $ text ("@" ++ citationId c) <+> br
729+ return $ text ("@" ++ citationId c) <+> br
722− | otherwise = do
730+ else do
723− cits <- mapM convertOne (c:cs)
731+ cits <- mapM convertOne (c:cs)
724− return $ text "[" <> joincits cits <> text "]"
732+ return $ text "[" <> joincits cits <> text "]"
726 joincits = hcat . intersperse (text "; ") . filter (not . isEmpty)
734 joincits = hcat . intersperse (text "; ") . filter (not . isEmpty)
727 convertOne Citation { citationId = k
735 convertOne Citation { citationId = k
@@ -738,7 +746,6 @@ inlineToMarkdown opts (Cite (c:cs) lst@[RawInline "latex" _])
738 return $ pdoc <+> r
746 return $ pdoc <+> r
739 modekey SuppressAuthor = "-"
747 modekey SuppressAuthor = "-"
740 modekey _ = ""
748 modekey _ = ""
741−inlineToMarkdown opts (Cite _ lst) = inlineListToMarkdown opts lst
742inlineToMarkdown opts (Link txt (src, tit)) = do
749inlineToMarkdown opts (Link txt (src, tit)) = do
743 linktext <- inlineListToMarkdown opts txt
750 linktext <- inlineListToMarkdown opts txt
744 let linktitle = if null tit
751 let linktitle = if null tit