git.iko.soy/typeable/pandoc
on master help sign in
Added option to write citation markup in markdown writer.
c81495aNathan Gass
src/Text/Pandoc/Writers/Markdown.hs+29−1
@@ -77,6 +77,7 @@ plainify = processWith go
77 go (HtmlInline _ : ys) = Str "" : go ys
77 go (HtmlInline _ : ys) = Str "" : go ys
78 go (Link xs _ : ys) = go xs ++ go ys
78 go (Link xs _ : ys) = go xs ++ go ys
79 go (Image _ _ : ys) = go ys
79 go (Image _ _ : ys) = go ys
80+ go (Cite _ cits : ys) = go cits ++ go ys
80 go (x : ys) = x : go ys
81 go (x : ys) = x : go ys
81 go [] = []
82 go [] = []
82
83
@@ -400,7 +401,34 @@ inlineToMarkdown _ (TeX str) = return $ text str
400inlineToMarkdown _ (HtmlInline str) = return $ text str
401inlineToMarkdown _ (HtmlInline str) = return $ text str
401inlineToMarkdown _ (LineBreak) = return $ text " \n"
402inlineToMarkdown _ (LineBreak) = return $ text " \n"
402inlineToMarkdown _ Space = return $ char ' '
403inlineToMarkdown _ 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 ""
404inlineToMarkdown opts (Link txt (src', tit)) = do
432inlineToMarkdown opts (Link txt (src', tit)) = do
405 linktext <- inlineListToMarkdown opts txt
433 linktext <- inlineListToMarkdown opts txt
406 let linktitle = if null tit then empty else text $ " \"" ++ tit ++ "\""
434 let linktitle = if null tit then empty else text $ " \"" ++ tit ++ "\""
src/pandoc.hs+1−1
@@ -463,7 +463,7 @@ options =
463 (\arg opt -> return opt { optCslFile = arg })
463 (\arg opt -> return opt { optCslFile = arg })
464 "FILENAME")
464 "FILENAME")
465 ""
465 ""
466− , Option "" ["natbib"]
466+ , Option "" ["natbib", "no-citeproc"]
467 (NoArg
467 (NoArg
468 (\opt -> return opt { optCiteMethod = Natbib }))
468 (\opt -> return opt { optCiteMethod = Natbib }))
469 "" -- "Use natbib cite commands in LaTeX output"
469 "" -- "Use natbib cite commands in LaTeX output"