git.iko.soy/typeable/pandoc
on master help sign in
Added option to write citation markup in markdown writer.
commitc81495a07afc61cf39af51e1517586d1131c203a authorNathan Gass <gass@search.ch> dateMon 13 Dec 2010, 21:27 (16 years ago) parent48600fd
2 files changed+30−2
src/Text/Pandoc/Writers/Markdown.hs+29−1 src/pandoc.hs+1−1
src/Text/Pandoc/Writers/Markdown.hs+29−1
@@ -77,6 +77,7 @@ plainify = processWith go
7777 go (HtmlInline _ : ys) = Str "" : go ys
7878 go (Link xs _ : ys) = go xs ++ go ys
7979 go (Image _ _ : ys) = go ys
80+ go (Cite _ cits : ys) = go cits ++ go ys
8081 go (x : ys) = x : go ys
8182 go [] = []
8283
@@ -400,7 +401,34 @@ inlineToMarkdown _ (TeX str) = return $ text str
400401inlineToMarkdown _ (HtmlInline str) = return $ text str
401402inlineToMarkdown _ (LineBreak) = return $ text " \n"
402403inlineToMarkdown _ Space = return $ char ' '
403−inlineToMarkdown opts (Cite _ cits) = inlineListToMarkdown opts cits
404+inlineToMarkdown opts (Cite (c:cs) lst)
405+ | writerCiteMethod opts == Citeproc = inlineListToMarkdown opts lst
406+ | citationMode c == AuthorInText = do
407+ suffs <- inlineListToMarkdown opts $ citationSuffix c
408+ rest <- mapM convertOne cs
409+ let inbr = suffs <+> joincits rest
410+ br = if isEmpty inbr then empty else brackets inbr
411+ return $ text ("@" ++ citationId c) <+> br
412+ | otherwise = do
413+ cits <- mapM convertOne (c:cs)
414+ return $ text "[" <> joincits cits <> text "]"
415+ where
416+ joincits = hcat . punctuate (text "; ") . filter (not . isEmpty)
417+ convertOne Citation { citationId = k
418+ , citationPrefix = pinlines
419+ , citationSuffix = sinlines
420+ , citationMode = m }
421+ = do
422+ pdoc <- inlineListToMarkdown opts pinlines
423+ sdoc <- inlineListToMarkdown opts sinlines
424+ let k' = text (modekey m ++ "@" ++ k)
425+ r = case sinlines of
426+ Str (y:_):_ | y `elem` ",;]@" -> k' <> sdoc
427+ _ -> k' <+> sdoc
428+ return $ pdoc <+> r
429+ modekey SuppressAuthor = "-"
430+ modekey _ = ""
431+inlineToMarkdown _ (Cite _ _) = return $ text ""
404432inlineToMarkdown opts (Link txt (src', tit)) = do
405433 linktext <- inlineListToMarkdown opts txt
406434 let linktitle = if null tit then empty else text $ " \"" ++ tit ++ "\""
src/pandoc.hs+1−1
@@ -463,7 +463,7 @@ options =
463463 (\arg opt -> return opt { optCslFile = arg })
464464 "FILENAME")
465465 ""
466− , Option "" ["natbib"]
466+ , Option "" ["natbib", "no-citeproc"]
467467 (NoArg
468468 (\opt -> return opt { optCiteMethod = Natbib }))
469469 "" -- "Use natbib cite commands in LaTeX output"