aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-03-17 09:57:27 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-03-17 09:57:27 -0700
commit99f9126d7215b1e962dc8a10f8379fa028c47d35 (patch)
tree05376a0652133b2c6ecfbc0e683044ba6991acc9 /src/Text/Pandoc
parentcae52ecc315a0635f81cb2547b4f268ec8a8befa (diff)
downloadpandoc-99f9126d7215b1e962dc8a10f8379fa028c47d35.tar.gz
Markdown writer: Omit bibliography when `citations` enabled.
In 1.11, citations would be rendered as pandoc markdown citations, but the bibliography would still be printed. We avoid that by adding a `RawBlock "pandoc" "references"` before the references. This allows the markdown writer to find the references and strip them off when `citations` is enabled.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Biblio.hs2
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs14
2 files changed, 13 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Biblio.hs b/src/Text/Pandoc/Biblio.hs
index 4dd82dd08..4116e3cbd 100644
--- a/src/Text/Pandoc/Biblio.hs
+++ b/src/Text/Pandoc/Biblio.hs
@@ -54,7 +54,7 @@ processBiblio (Just style) r p =
cits_map = M.fromList $ zip grps (citations result)
biblioList = map (renderPandoc' style) (bibliography result)
Pandoc m b = bottomUp mvPunct . deNote . bottomUp (processCite style cits_map) $ p'
- in Pandoc m $ b ++ biblioList
+ in Pandoc m $ b ++ (RawBlock "pandoc" "references" : biblioList)
-- | Substitute 'Cite' elements with formatted citations.
processCite :: Style -> M.Map [Citation] [FormattedOutput] -> Inline -> Inline
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index b496c8011..bfd4c0898 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -61,7 +61,8 @@ writeMarkdown opts document =
evalState (pandocToMarkdown opts{
writerWrapText = writerWrapText opts &&
not (isEnabled Ext_hard_line_breaks opts) }
- document) def
+ document') def
+ where document' = maybeRemoveBiblio opts document
-- | Convert Pandoc to plain text (like markdown, but without links,
-- pictures, or inline formatting).
@@ -71,7 +72,16 @@ writePlain opts document =
writerExtensions = Set.delete Ext_escaped_line_breaks $
writerExtensions opts }
document') def{ stPlain = True }
- where document' = plainify document
+ where document' = plainify $ maybeRemoveBiblio opts document
+
+-- If we're rendering citations as pandoc markdown citations,
+-- then we don't want to include a bibliography.
+maybeRemoveBiblio :: WriterOptions -> Pandoc -> Pandoc
+maybeRemoveBiblio opts (Pandoc meta bs) = Pandoc meta bs'
+ where bs' = if isEnabled Ext_citations opts
+ then takeWhile
+ (/= RawBlock "pandoc" "references") bs
+ else bs
plainify :: Pandoc -> Pandoc
plainify = bottomUp go