git.iko.soy/typeable/pandoc
on master help sign in
Markdown writer: New approach for citations.

* Reverts 1.11 change that caused citations to be rendered as markdown citations, even if `--biblio` was specified, unless `citation` extension is disabled. Now, formatted citations are always printed if `--biblio` was specified. If you want to reformat markdown keeping pandoc markdown citations intact, just don't specify `--biblio`. * Reverted now unnecessary changes to Text.Pandoc.Biblio adding the raw block to mark the bibliography, and to Text.Pandoc.Writers.Markdown to remove the bibliography if `citations` not specified. * If the content of a `Cite` inline is a `RawInline "latex"`, which means that a LaTeX citation command was parsed and `--biblio` wasn't specified, then render it as a pandoc markdown citation. This means that `pandoc -f latex -t markdown`, without `--biblio`, will convert LaTeX citation commands to pandoc markdown citations.

commit835deee58bf4d8d7249735016063e9a988937015 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSun 17 Mar 2013, 10:33 (14 years ago) parent8ca5198
3 files changed+6−16
src/Text/Pandoc/Biblio.hs+1−1 src/Text/Pandoc/Writers/Markdown.hs+4−14 tests/Tests/Old.hs+1−1
src/Text/Pandoc/Biblio.hs+1−1
@@ -54,7 +54,7 @@ processBiblio (Just style) r p =
5454 cits_map = M.fromList $ zip grps (citations result)
5555 biblioList = map (renderPandoc' style) (bibliography result)
5656 Pandoc m b = bottomUp mvPunct . deNote . bottomUp (processCite style cits_map) $ p'
57− in Pandoc m $ b ++ (RawBlock "pandoc" "references" : biblioList)
57+ in Pandoc m $ b ++ biblioList
5858
5959-- | Substitute 'Cite' elements with formatted citations.
6060processCite :: Style -> M.Map [Citation] [FormattedOutput] -> Inline -> Inline
src/Text/Pandoc/Writers/Markdown.hs+4−14
@@ -61,8 +61,7 @@ writeMarkdown opts document =
6161 evalState (pandocToMarkdown opts{
6262 writerWrapText = writerWrapText opts &&
6363 not (isEnabled Ext_hard_line_breaks opts) }
64− document') def
65− where document' = maybeRemoveBiblio opts document
64+ document) def
6665
6766-- | Convert Pandoc to plain text (like markdown, but without links,
6867-- pictures, or inline formatting).
@@ -72,16 +71,7 @@ writePlain opts document =
7271 writerExtensions = Set.delete Ext_escaped_line_breaks $
7372 writerExtensions opts }
7473 document') def{ stPlain = True }
75− where document' = plainify $ maybeRemoveBiblio opts document
76−
77−-- If we're rendering citations as pandoc markdown citations,
78−-- then we don't want to include a bibliography.
79−maybeRemoveBiblio :: WriterOptions -> Pandoc -> Pandoc
80−maybeRemoveBiblio opts (Pandoc meta bs) = Pandoc meta bs'
81− where bs' = if isEnabled Ext_citations opts
82− then takeWhile
83− (/= RawBlock "pandoc" "references") bs
84− else bs
74+ where document' = plainify document
8575
8676plainify :: Pandoc -> Pandoc
8777plainify = bottomUp go
@@ -653,7 +643,7 @@ inlineToMarkdown opts (LineBreak)
653643 | isEnabled Ext_escaped_line_breaks opts = return $ "\\" <> cr
654644 | otherwise = return $ " " <> cr
655645inlineToMarkdown _ Space = return space
656−inlineToMarkdown opts (Cite (c:cs) lst)
646+inlineToMarkdown opts (Cite (c:cs) lst@[RawInline "latex" _])
657647 | not (isEnabled Ext_citations opts) = inlineListToMarkdown opts lst
658648 | citationMode c == AuthorInText = do
659649 suffs <- inlineListToMarkdown opts $ citationSuffix c
@@ -680,7 +670,7 @@ inlineToMarkdown opts (Cite (c:cs) lst)
680670 return $ pdoc <+> r
681671 modekey SuppressAuthor = "-"
682672 modekey _ = ""
683−inlineToMarkdown _ (Cite _ _) = return $ text ""
673+inlineToMarkdown opts (Cite _ lst) = inlineListToMarkdown opts lst
684674inlineToMarkdown opts (Link txt (src, tit)) = do
685675 linktext <- inlineListToMarkdown opts txt
686676 let linktitle = if null tit
tests/Tests/Old.hs+1−1
@@ -186,7 +186,7 @@ markdownCitationTests
186186 ++ [test "natbib" wopts "markdown-citations.txt"
187187 "markdown-citations.txt"]
188188 where
189− ropts = ["-r", "markdown", "-w", "markdown-citations", "--bibliography",
189+ ropts = ["-r", "markdown", "-w", "markdown", "--bibliography",
190190 "biblio.bib", "--no-wrap"]
191191 wopts = ["-r", "markdown", "-w", "markdown", "--no-wrap", "--natbib"]
192192 styleToTest style = test style (ropts ++ ["--csl", style ++ ".csl"])