git.iko.soy/typeable/pandoc
on master help sign in
Merge branch 'altcite'
b1d08a8John MacFarlane
src/Text/Pandoc/Biblio.hs+4−1
@@ -55,7 +55,10 @@ processBiblio (Just style) r p =
55 cits_map = M.fromList $ zip grps (citations result)
55 cits_map = M.fromList $ zip grps (citations result)
56 biblioList = map (renderPandoc' style) (bibliography result)
56 biblioList = map (renderPandoc' style) (bibliography result)
57 Pandoc m b = bottomUp mvPunct . deNote . topDown (processCite style cits_map) $ p'
57 Pandoc m b = bottomUp mvPunct . deNote . topDown (processCite style cits_map) $ p'
58+ (bs, lastb) = case reverse b of
59+ x@(Header _ _ _) : xs -> (reverse xs, [x])
60+ _ -> (b, [])
58− in Pandoc m $ b ++ biblioList
61+ in Pandoc m $ bs ++ [Div ("",["references"],[]) (lastb ++ biblioList)]
59
62
60-- | Substitute 'Cite' elements with formatted citations.
63-- | Substitute 'Cite' elements with formatted citations.
61processCite :: Style -> M.Map [Citation] [FormattedOutput] -> Inline -> Inline
64processCite :: Style -> M.Map [Citation] [FormattedOutput] -> Inline -> Inline
src/Text/Pandoc/Readers/Markdown.hs+12−9
@@ -55,7 +55,6 @@ import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXBlock )
55import Text.Pandoc.Readers.HTML ( htmlTag, htmlInBalanced, isInlineTag, isBlockTag,
55import Text.Pandoc.Readers.HTML ( htmlTag, htmlInBalanced, isInlineTag, isBlockTag,
56 isTextTag, isCommentTag )
56 isTextTag, isCommentTag )
57import Text.Pandoc.Biblio (processBiblio)
57import Text.Pandoc.Biblio (processBiblio)
58−import qualified Text.CSL as CSL
59import Data.Monoid (mconcat, mempty)
58import Data.Monoid (mconcat, mempty)
60import Control.Applicative ((<$>), (<*), (*>), (<$))
59import Control.Applicative ((<$>), (<*), (*>), (<$))
61import Control.Monad
60import Control.Monad
@@ -1797,11 +1796,13 @@ rawHtmlInline = do
1797cite :: MarkdownParser (F Inlines)
1796cite :: MarkdownParser (F Inlines)
1798cite = do
1797cite = do
1799 guardEnabled Ext_citations
1798 guardEnabled Ext_citations
1800− getOption readerReferences >>= guard . not . null
1801− citations <- textualCite <|> normalCite
1799+ citations <- textualCite <|> (fmap (flip B.cite unknownC) <$> normalCite)
1802− return $ flip B.cite mempty <$> citations
1800+ return citations
1801+
1802+unknownC :: Inlines
1803+unknownC = B.str "???"
1803
1804
1804−textualCite :: MarkdownParser (F [Citation])
1805+textualCite :: MarkdownParser (F Inlines)
1805textualCite = try $ do
1806textualCite = try $ do
1806 (_, key) <- citeKey
1807 (_, key) <- citeKey
1807 let first = Citation{ citationId = key
1808 let first = Citation{ citationId = key
@@ -1813,8 +1814,12 @@ textualCite = try $ do
1813 }
1814 }
1814 mbrest <- option Nothing $ try $ spnl >> Just <$> normalCite
1815 mbrest <- option Nothing $ try $ spnl >> Just <$> normalCite
1815 case mbrest of
1816 case mbrest of
1816− Just rest -> return $ (first:) <$> rest
1817+ Just rest -> return $ (flip B.cite unknownC . (first:)) <$> rest
1817− Nothing -> option (return [first]) $ bareloc first
1818+ Nothing -> (fmap (flip B.cite unknownC) <$> bareloc first) <|>
1819+ return (do st <- askF
1820+ return $ case M.lookup key (stateExamples st) of
1821+ Just n -> B.str (show n)
1822+ _ -> B.cite [first] unknownC)
1818
1823
1819bareloc :: Citation -> MarkdownParser (F [Citation])
1824bareloc :: Citation -> MarkdownParser (F [Citation])
1820bareloc c = try $ do
1825bareloc c = try $ do
@@ -1846,8 +1851,6 @@ citeKey = try $ do
1846 let internal p = try $ p >>~ lookAhead (letter <|> digit)
1851 let internal p = try $ p >>~ lookAhead (letter <|> digit)
1847 rest <- many $ letter <|> digit <|> internal (oneOf ":.#$%&-_+?<>~/")
1852 rest <- many $ letter <|> digit <|> internal (oneOf ":.#$%&-_+?<>~/")
1848 let key = first:rest
1853 let key = first:rest
1849− citations' <- map CSL.refId <$> getOption readerReferences
1850− guard $ key `elem` citations'
1851 return (suppress_author, key)
1854 return (suppress_author, key)
1852
1855
1853suffix :: MarkdownParser (F Inlines)
1856suffix :: MarkdownParser (F Inlines)
src/Text/Pandoc/Writers/Markdown.hs+21−14
@@ -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
193+ _ -> blocks
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
722+ | otherwise =
716− | citationMode c == AuthorInText = do
723+ if citationMode c == AuthorInText
724+ then do
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 "]"
725 where
733 where
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
tests/Tests/Old.hs+1−1
@@ -196,7 +196,7 @@ markdownCitationTests
196 ++ [test "natbib" wopts "markdown-citations.txt"
196 ++ [test "natbib" wopts "markdown-citations.txt"
197 "markdown-citations.txt"]
197 "markdown-citations.txt"]
198 where
198 where
199− ropts = ["-r", "markdown", "-w", "markdown", "--bibliography",
199+ ropts = ["-r", "markdown", "-w", "markdown-citations", "--bibliography",
200 "biblio.bib", "--no-wrap"]
200 "biblio.bib", "--no-wrap"]
201 wopts = ["-r", "markdown", "-w", "markdown", "--no-wrap", "--natbib"]
201 wopts = ["-r", "markdown", "-w", "markdown", "--no-wrap", "--natbib"]
202 styleToTest style = test style (ropts ++ ["--csl", style ++ ".csl"])
202 styleToTest style = test style (ropts ++ ["--csl", style ++ ".csl"])
tests/markdown-citations.chicago-author-date.txt+8−2
@@ -1,9 +1,9 @@
1Pandoc with citeproc-hs
1Pandoc with citeproc-hs
2=======================
2=======================
3
3
4−- [@nonexistent]
4+- ([CSL BIBLIOGRAPHIC DATA ERROR: reference "nonexistent" not found.])
5
5
6−- @nonexistent
6+- ([CSL BIBLIOGRAPHIC DATA ERROR: reference "nonexistent" not found.])
7
7
8- Doe (2005) says blah.
8- Doe (2005) says blah.
9
9
@@ -29,15 +29,21 @@ Pandoc with citeproc-hs
29
29
30- With some markup (*see* Doe 2005, 32).
30- With some markup (*see* Doe 2005, 32).
31
31
32+<div class="references">
33+
32References
34References
33==========
35==========
34
36
37+“Nonexistent Not Found!”
38+
35Doe, John. 2005. *First Book*. Cambridge: Cambridge University Press.
39Doe, John. 2005. *First Book*. Cambridge: Cambridge University Press.
36
40
37———. 2006. “Article.” *Journal of Generic Studies* 6: 33–34.
41———. 2006. “Article.” *Journal of Generic Studies* 6: 33–34.
38
42
39Doe, John, and Jenny Roe. 2007. “Why Water Is Wet.” In *Third Book*, edited by Sam Smith. Oxford: Oxford University Press.
43Doe, John, and Jenny Roe. 2007. “Why Water Is Wet.” In *Third Book*, edited by Sam Smith. Oxford: Oxford University Press.
40
44
45+</div>
46+
41[^1]: Doe and Roe (2007, 12) and a citation without locators (Doe and Roe 2007).
47[^1]: Doe and Roe (2007, 12) and a citation without locators (Doe and Roe 2007).
42
48
43[^2]: Some citations (see Doe 2005, chap. 3; Doe and Roe 2007; Doe 2006).
49[^2]: Some citations (see Doe 2005, chap. 3; Doe and Roe 2007; Doe 2006).
tests/markdown-citations.ieee.txt+23−17
@@ -1,45 +1,51 @@
1Pandoc with citeproc-hs
1Pandoc with citeproc-hs
2=======================
2=======================
3
3
4−- [@nonexistent]
4+- []
5
5
6−- @nonexistent
6+-
7
7
8−- Reference 1 says blah.
8+- Reference 2 says blah.
9
9
10−- Reference 1 says blah.
10+- Reference 2 says blah.
11
11
12−- Reference 1 says blah.
12+- Reference 2 says blah.
13
13
14−- Reference 1 [3] says blah.
14+- Reference 2 [4] says blah.
15
15
16- In a note.[^1]
16- In a note.[^1]
17
17
18−- A citation group [1], [3].
18+- A citation group [2], [4].
19
19
20−- Another one [1].
20+- Another one [2].
21
21
22- And another one in a note.[^2]
22- And another one in a note.[^2]
23
23
24−- Citation with a suffix and locator [1].
24+- Citation with a suffix and locator [2].
25
25
26−- Citation with suffix only [1].
26+- Citation with suffix only [2].
27
27
28- Now some modifiers.[^3]
28- Now some modifiers.[^3]
29
29
30−- With some markup [1].
30+- With some markup [2].
31+
32+<div class="references">
31
33
32References
34References
33==========
35==========
34
36
37+[1]“nonexistent not found!” .
38+
35−[1] J. Doe, *First Book*. Cambridge: Cambridge University Press, 2005.
39+[2] J. Doe, *First Book*. Cambridge: Cambridge University Press, 2005.
40+
41+[3] J. Doe, “Article,” *Journal of Generic Studies*, vol. 6, pp. 33–34, 2006.
36
42
37−[2] J. Doe, “Article,” *Journal of Generic Studies*, vol. 6, pp. 33–34, 2006.
43+[4] J. Doe and J. Roe, “Why Water Is Wet,” in *Third Book*, S. Smith, Ed. Oxford: Oxford University Press, 2007.
38
44
39−[3] J. Doe and J. Roe, “Why Water Is Wet,” in *Third Book*, S. Smith, Ed. Oxford: Oxford University Press, 2007.
45+</div>
40
46
41−[^1]: Reference 3 and a citation without locators [3].
47+[^1]: Reference 4 and a citation without locators [4].
42
48
43−[^2]: Some citations [1–3].
49+[^2]: Some citations [2–4].
44
50
45−[^3]: Like a citation without author: [1], and now Doe with a locator [2].
51+[^3]: Like a citation without author: [2], and now Doe with a locator [3].
tests/markdown-citations.mhra.txt+36−26
@@ -1,33 +1,35 @@
1Pandoc with citeproc-hs
1Pandoc with citeproc-hs
2=======================
2=======================
3
3
4−- [@nonexistent]
4+- [^1]
5
5
6−- @nonexistent
6+- [^2]
7
7
8−- John Doe[^1] says blah.
8+- John Doe[^3] says blah.
9
9
10−- Doe[^2] says blah.
10+- Doe[^4] says blah.
11
11
12−- Doe[^3] says blah.
12+- Doe[^5] says blah.
13
13
14−- Doe[^4] says blah.
14+- Doe[^6] says blah.
15
15
16−- In a note.[^5]
16+- In a note.[^7]
17
17
18−- A citation group.[^6]
18+- A citation group.[^8]
19
19
20−- Another one.[^7]
20+- Another one.[^9]
21
21
22−- And another one in a note.[^8]
22+- And another one in a note.[^10]
23
23
24−- Citation with a suffix and locator.[^9]
24+- Citation with a suffix and locator.[^11]
25
25
26−- Citation with suffix only.[^10]
26+- Citation with suffix only.[^12]
27
27
28−- Now some modifiers.[^11]
28+- Now some modifiers.[^13]
29
29
30−- With some markup.[^12]
30+- With some markup.[^14]
31+
32+<div class="references">
31
33
32References
34References
33==========
35==========
@@ -38,26 +40,34 @@ Doe, John, ‘Article’, *Journal of Generic Studies*, 6 (2006), 33–34.
38
40
39Doe, John, and Jenny Roe, ‘Why Water Is Wet’, in *Third Book*, ed. by Sam Smith (Oxford: Oxford University Press, 2007).
41Doe, John, and Jenny Roe, ‘Why Water Is Wet’, in *Third Book*, ed. by Sam Smith (Oxford: Oxford University Press, 2007).
40
42
43+‘Nonexistent Not Found!’.
44+
45+</div>
46+
47+[^1]: [CSL BIBLIOGRAPHIC DATA ERROR: reference "nonexistent" not found.].
48+
49+[^2]: [CSL STYLE ERROR: reference with no printed form.].
50+
41−[^1]: *First Book* (Cambridge: Cambridge University Press, 2005).
51+[^3]: *First Book* (Cambridge: Cambridge University Press, 2005).
42
52
43−[^2]: *First Book*, p. 30.
53+[^4]: *First Book*, p. 30.
44
54
45−[^3]: *First Book*, p. 30, with suffix.
55+[^5]: *First Book*, p. 30, with suffix.
46
56
47−[^4]: *First Book*; ‘Article’, *Journal of Generic Studies*, 6 (2006), 33–34 (p. 30); see also John Doe and Jenny Roe, ‘Why Water Is Wet’, in *Third Book*, ed. by Sam Smith (Oxford: Oxford University Press, 2007).
57+[^6]: *First Book*; ‘Article’, *Journal of Generic Studies*, 6 (2006), 33–34 (p. 30); see also John Doe and Jenny Roe, ‘Why Water Is Wet’, in *Third Book*, ed. by Sam Smith (Oxford: Oxford University Press, 2007).
48
58
49−[^5]: Doe and Roe, p. 12 and a citation without locators Doe and Roe.
59+[^7]: Doe and Roe, p. 12 and a citation without locators Doe and Roe.
50
60
51−[^6]: See Doe, *First Book*, chap. 3; also Doe and Roe, pp. 34–35.
61+[^8]: See Doe, *First Book*, chap. 3; also Doe and Roe, pp. 34–35.
52
62
53−[^7]: See Doe, *First Book*, pp. 34–35.
63+[^9]: See Doe, *First Book*, pp. 34–35.
54
64
55−[^8]: Some citations see Doe, *First Book*, chap. 3; Doe and Roe; Doe, ‘Article’, 33–34.
65+[^10]: Some citations see Doe, *First Book*, chap. 3; Doe and Roe; Doe, ‘Article’, 33–34.
56
66
57−[^9]: Doe, *First Book*, pp. 33, 35–37, and nowhere else.
67+[^11]: Doe, *First Book*, pp. 33, 35–37, and nowhere else.
58
68
59−[^10]: Doe, *First Book* and nowhere else.
69+[^12]: Doe, *First Book* and nowhere else.
60
70
61−[^11]: Like a citation without author: *First Book*, and now Doe with a locator ‘Article’, 33–34 (p. 44).
71+[^13]: Like a citation without author: *First Book*, and now Doe with a locator ‘Article’, 33–34 (p. 44).
62
72
63−[^12]: *See* Doe, *First Book*, p. 32.
73+[^14]: *See* Doe, *First Book*, p. 32.