git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: citation handling changes.
f7229b1John MacFarlane
pandoc.cabal+2
@@ -109,6 +109,7 @@ Extra-Source-Files:
109 tests/lalune.jpg,
109 tests/lalune.jpg,
110 tests/movie.jpg,
110 tests/movie.jpg,
111 tests/biblio.bib,
111 tests/biblio.bib,
112+ tests/biblio.mods,
112 tests/chicago-author-date.csl,
113 tests/chicago-author-date.csl,
113 tests/ieee.csl,
114 tests/ieee.csl,
114 tests/mhra.csl,
115 tests/mhra.csl,
@@ -383,6 +384,7 @@ Test-Suite test-pandoc
383 QuickCheck >= 2.4 && < 2.6,
384 QuickCheck >= 2.4 && < 2.6,
384 HUnit >= 1.2 && < 1.3,
385 HUnit >= 1.2 && < 1.3,
385 containers >= 0.1 && < 0.6,
386 containers >= 0.1 && < 0.6,
387+ citeproc-hs >= 0.3 && < 0.4,
386 ansi-terminal >= 0.5 && < 0.7
388 ansi-terminal >= 0.5 && < 0.7
387 Other-Modules: Tests.Old
389 Other-Modules: Tests.Old
388 Tests.Helpers
390 Tests.Helpers
src/Text/Pandoc/Readers/LaTeX.hs+8−3
@@ -1021,7 +1021,10 @@ cites mode multi = try $ do
1021citation :: String -> CitationMode -> Bool -> LP Inlines
1021citation :: String -> CitationMode -> Bool -> LP Inlines
1022citation name mode multi = do
1022citation name mode multi = do
1023 (c,raw) <- withRaw $ cites mode multi
1023 (c,raw) <- withRaw $ cites mode multi
1024+ refs <- getOption readerReferences
1025+ return $ if null refs
1024− return $ cite c (rawInline "latex" $ "\\" ++ name ++ raw)
1026+ then rawInline "latex" $ "\\" ++ name ++ raw
1027+ else cite c mempty
1025
1028
1026complexNatbibCitation :: CitationMode -> LP Inlines
1029complexNatbibCitation :: CitationMode -> LP Inlines
1027complexNatbibCitation mode = try $ do
1030complexNatbibCitation mode = try $ do
@@ -1040,8 +1043,10 @@ complexNatbibCitation mode = try $ do
1040 optional $ char ';'
1043 optional $ char ';'
1041 return $ addPrefix pref $ addSuffix suff $ cits'
1044 return $ addPrefix pref $ addSuffix suff $ cits'
1042 (c:cits, raw) <- withRaw $ grouped parseOne
1045 (c:cits, raw) <- withRaw $ grouped parseOne
1046+ refs <- getOption readerReferences
1047+ return $ if null refs
1048+ then rawInline "latex" $ "\\citetext" ++ raw
1043− return $ cite (c{ citationMode = mode }:cits)
1049+ else cite (c{ citationMode = mode}:cits) mempty
1044− (rawInline "latex" $ "\\citetext" ++ raw)
1045
1050
1046-- tables
1051-- tables
1047
1052
src/Text/Pandoc/Writers/Markdown.hs+2−1
@@ -644,7 +644,8 @@ inlineToMarkdown opts (LineBreak)
644 | otherwise = return $ " " <> cr
644 | otherwise = return $ " " <> cr
645inlineToMarkdown _ Space = return space
645inlineToMarkdown _ Space = return space
646inlineToMarkdown opts (Cite (c:cs) lst)
646inlineToMarkdown opts (Cite (c:cs) lst)
647− | not (isEnabled Ext_citations opts) = inlineListToMarkdown opts lst
647+ | not (null lst) = inlineListToMarkdown opts lst
648+ -- if lst is null, citeproc wasn't run; print a pandoc markdown citation
648 | citationMode c == AuthorInText = do
649 | citationMode c == AuthorInText = do
649 suffs <- inlineListToMarkdown opts $ citationSuffix c
650 suffs <- inlineListToMarkdown opts $ citationSuffix c
650 rest <- mapM convertOne cs
651 rest <- mapM convertOne cs
tests/Tests/Old.hs+1−1
@@ -186,7 +186,7 @@ markdownCitationTests
186 ++ [test "natbib" wopts "markdown-citations.txt"
186 ++ [test "natbib" wopts "markdown-citations.txt"
187 "markdown-citations.txt"]
187 "markdown-citations.txt"]
188 where
188 where
189− ropts = ["-r", "markdown", "-w", "markdown-citations", "--bibliography",
189+ ropts = ["-r", "markdown", "-w", "markdown", "--bibliography",
190 "biblio.bib", "--no-wrap"]
190 "biblio.bib", "--no-wrap"]
191 wopts = ["-r", "markdown", "-w", "markdown", "--no-wrap", "--natbib"]
191 wopts = ["-r", "markdown", "-w", "markdown", "--no-wrap", "--natbib"]
192 styleToTest style = test style (ropts ++ ["--csl", style ++ ".csl"])
192 styleToTest style = test style (ropts ++ ["--csl", style ++ ".csl"])
tests/Tests/Readers/LaTeX.hs+8−2
@@ -2,14 +2,20 @@
2module Tests.Readers.LaTeX (tests) where
2module Tests.Readers.LaTeX (tests) where
3
3
4import Text.Pandoc.Definition
4import Text.Pandoc.Definition
5+import Data.Monoid (mempty)
6+import Text.CSL (Reference, readBiblioFile)
5import Test.Framework
7import Test.Framework
6import Tests.Helpers
8import Tests.Helpers
7import Tests.Arbitrary()
9import Tests.Arbitrary()
8import Text.Pandoc.Builder
10import Text.Pandoc.Builder
9import Text.Pandoc
11import Text.Pandoc
12+import System.IO.Unsafe (unsafePerformIO)
13+
14+refs :: [Reference]
15+refs = unsafePerformIO $ readBiblioFile "biblio.mods"
10
16
11latex :: String -> Pandoc
17latex :: String -> Pandoc
12−latex = readLaTeX def
18+latex = readLaTeX def{ readerReferences = refs }
13
19
14infix 4 =:
20infix 4 =:
15(=:) :: ToString c
21(=:) :: ToString c
@@ -71,7 +77,7 @@ baseCitation = Citation{ citationId = "item1"
71 }
77 }
72
78
73rt :: String -> Inlines
79rt :: String -> Inlines
74−rt = rawInline "latex"
80+rt = const mempty -- rawInline "latex"
75
81
76natbibCitations :: Test
82natbibCitations :: Test
77natbibCitations = testGroup "natbib"
83natbibCitations = testGroup "natbib"
tests/biblio.modsnew file+106
@@ -0,0 +1,106 @@
1+<?xml version="1.0" encoding="UTF-8"?>
2+<modsCollection xmlns="http://www.loc.gov/mods/v3">
3+<mods ID="item1">
4+ <titleInfo>
5+ <title>First Book</title>
6+ </titleInfo>
7+ <name type="personal">
8+ <namePart type="given">John</namePart>
9+ <namePart type="family">Doe</namePart>
10+ <role>
11+ <roleTerm authority="marcrelator" type="text">author</roleTerm>
12+ </role>
13+ </name>
14+ <originInfo>
15+ <issuance>monographic</issuance>
16+ <dateIssued>2005</dateIssued>
17+ <publisher>Cambridge University Press</publisher>
18+ <place>
19+ <placeTerm type="text">Cambridge</placeTerm>
20+ </place>
21+ </originInfo>
22+ <typeOfResource>text</typeOfResource>
23+ <genre authority="marcgt">book</genre>
24+ <identifier type="citekey">item1</identifier>
25+</mods>
26+<mods ID="item2">
27+ <titleInfo>
28+ <title>Article</title>
29+ </titleInfo>
30+ <name type="personal">
31+ <namePart type="given">John</namePart>
32+ <namePart type="family">Doe</namePart>
33+ <role>
34+ <roleTerm authority="marcrelator" type="text">author</roleTerm>
35+ </role>
36+ </name>
37+ <originInfo>
38+ <dateIssued>2006</dateIssued>
39+ </originInfo>
40+ <typeOfResource>text</typeOfResource>
41+ <relatedItem type="host">
42+ <titleInfo>
43+ <title>Journal of Generic Studies</title>
44+ </titleInfo>
45+ <originInfo>
46+ <issuance>continuing</issuance>
47+ </originInfo>
48+ <genre authority="marcgt">periodical</genre>
49+ <genre>academic journal</genre>
50+ </relatedItem>
51+ <identifier type="citekey">item2</identifier>
52+ <part>
53+ <date>2006</date>
54+ <detail type="volume"><number>6</number></detail>
55+ <extent unit="page">
56+ <start>33</start>
57+ <end>34</end>
58+ </extent>
59+ </part>
60+</mods>
61+<mods ID="пункт3">
62+ <titleInfo>
63+ <title>Why Water Is Wet</title>
64+ </titleInfo>
65+ <name type="personal">
66+ <namePart type="given">John</namePart>
67+ <namePart type="family">Doe</namePart>
68+ <role>
69+ <roleTerm authority="marcrelator" type="text">author</roleTerm>
70+ </role>
71+ </name>
72+ <name type="personal">
73+ <namePart type="given">Jenny</namePart>
74+ <namePart type="family">Roe</namePart>
75+ <role>
76+ <roleTerm authority="marcrelator" type="text">author</roleTerm>
77+ </role>
78+ </name>
79+ <originInfo>
80+ <issuance>monographic</issuance>
81+ <dateIssued>2007</dateIssued>
82+ </originInfo>
83+ <typeOfResource>text</typeOfResource>
84+ <relatedItem type="host">
85+ <titleInfo>
86+ <title>Third Book</title>
87+ </titleInfo>
88+ <name type="personal">
89+ <namePart type="given">Sam</namePart>
90+ <namePart type="family">Smith</namePart>
91+ <role>
92+ <roleTerm authority="marcrelator" type="text">editor</roleTerm>
93+ </role>
94+ </name>
95+ <originInfo>
96+ <dateIssued>2007</dateIssued>
97+ <publisher>Oxford University Press</publisher>
98+ <place>
99+ <placeTerm type="text">Oxford</placeTerm>
100+ </place>
101+ </originInfo>
102+ <genre>collection</genre>
103+ </relatedItem>
104+ <identifier type="citekey">пункт3</identifier>
105+</mods>
106+</modsCollection>
tests/latex-reader.native+1−1
@@ -260,7 +260,7 @@ Pandoc (Meta {docTitle = [Str "Pandoc",Space,Str "Test",Space,Str "Suite"], docA
260,HorizontalRule
260,HorizontalRule
261,Header 1 ("",[],[]) [Str "LaTeX"]
261,Header 1 ("",[],[]) [Str "LaTeX"]
262,BulletList
262,BulletList
263− [[Para [Cite [Citation {citationId = "smith.1899", citationPrefix = [], citationSuffix = [Str ",",Space,Str "22-23"], citationMode = AuthorInText, citationNoteNum = 0, citationHash = 0}] [RawInline "latex" "\\cite[22-23]{smith.1899}"]]]
263+ [[Para [RawInline "latex" "\\cite[22-23]{smith.1899}"]]
264 ,[Para [RawInline "latex" "\\doublespacing"]]
264 ,[Para [RawInline "latex" "\\doublespacing"]]
265 ,[Para [Math InlineMath "2+2=4"]]
265 ,[Para [Math InlineMath "2+2=4"]]
266 ,[Para [Math InlineMath "x \\in y"]]
266 ,[Para [Math InlineMath "x \\in y"]]