summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnMacFarlane <>2018-02-26 07:21:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2018-02-26 07:21:00 (GMT)
commit67f23880956ad13d7ddeb02a3588580c50903267 (patch)
treebcb23ae5629a4c26cbe37f2a3917b1ce2161440d
parentf89e3729991490c205ba3eb965231ef0d1f103a8 (diff)
version 0.14.1.50.14.1.5
-rw-r--r--changelog6
-rw-r--r--pandoc-citeproc.cabal2
-rw-r--r--src/Text/CSL/Eval/Output.hs7
-rw-r--r--src/Text/CSL/Util.hs4
-rw-r--r--tests/annales.csl334
-rw-r--r--tests/issue322.expected.native5
-rw-r--r--tests/issue322.in.native2
-rw-r--r--tests/jats.csl208
-rw-r--r--tests/test-pandoc-citeproc.hs49
9 files changed, 596 insertions, 21 deletions
diff --git a/changelog b/changelog
index 9002dc1..f6e2d06 100644
--- a/changelog
+++ b/changelog
@@ -1,3 +1,9 @@
+pandoc-citeproc (0.14.1.5)
+
+ * Fixed 'capitalize-first' when the element begins with emphasis
+ or some other inline container. Closes #322.
+ * test-pandoc-citeproc: make --accept work with biblio2yaml tests.
+
pandoc-citeproc (0.14.1.4)
* Fixed sort order bugs (#320):
diff --git a/pandoc-citeproc.cabal b/pandoc-citeproc.cabal
index 91f57a6..663f22a 100644
--- a/pandoc-citeproc.cabal
+++ b/pandoc-citeproc.cabal
@@ -1,5 +1,5 @@
name: pandoc-citeproc
-version: 0.14.1.4
+version: 0.14.1.5
cabal-version: >= 1.12
synopsis: Supports using pandoc with citeproc
diff --git a/src/Text/CSL/Eval/Output.hs b/src/Text/CSL/Eval/Output.hs
index fe75296..cd52425 100644
--- a/src/Text/CSL/Eval/Output.hs
+++ b/src/Text/CSL/Eval/Output.hs
@@ -213,7 +213,7 @@ addFormatting f =
_ -> ils
text_case (Formatted []) = Formatted []
- text_case (Formatted ils@(i:is))
+ text_case (Formatted ils@(i:is'))
| noCase f = Formatted [Span ("",["nocase"],[]) ils]
| otherwise = Formatted $
case textCase f of
@@ -221,7 +221,10 @@ addFormatting f =
"uppercase" -> walk uppercaseStr ils
"capitalize-all" -> walk capitalizeStr ils
"title" -> titlecase ils
- "capitalize-first" -> walk capitalizeStr i : is
+ "capitalize-first"
+ -> case i of
+ Str cs -> Str (capitalize cs) : is'
+ _ -> unTitlecase [i] ++ is'
"sentence" -> unTitlecase ils
_ -> ils
diff --git a/src/Text/CSL/Util.hs b/src/Text/CSL/Util.hs
index 93c2e3b..ce5d8a0 100644
--- a/src/Text/CSL/Util.hs
+++ b/src/Text/CSL/Util.hs
@@ -344,8 +344,8 @@ caseTransform xform = fmap reverse . foldM go [] . splitUpStr
go acc (Quoted qt xs) = (:acc) <$> (Quoted qt <$> caseTransform xform xs)
go acc (Emph xs) = (:acc) <$> (Emph <$> caseTransform xform xs)
go acc (Strong xs) = (:acc) <$> (Strong <$> caseTransform xform xs)
- go acc (Link at xs t) = (:acc) <$> (Link at <$> caseTransform xform xs <*> pure t)
- go acc (Image at xs t) = (:acc) <$> (Link at <$> caseTransform xform xs <*> pure t)
+ go acc (Link at xs t) = (:acc) <$> (Link at <$> caseTransform xform xs <*> pure t)
+ go acc (Image at xs t) = (:acc) <$> (Link at <$> caseTransform xform xs <*> pure t)
go acc (Span attr xs) = (:acc) <$> (Span attr <$> caseTransform xform xs)
go acc x = return $ x : acc
diff --git a/tests/annales.csl b/tests/annales.csl
new file mode 100644
index 0000000..ee370da
--- /dev/null
+++ b/tests/annales.csl
@@ -0,0 +1,334 @@
+<?xml version="1.0" encoding="utf-8"?>
+<style xmlns="http://purl.org/net/xbiblio/csl" class="note" default-locale="fr-FR" version="1.0" page-range-format="expanded" demote-non-dropping-particle="sort-only">
+ <info>
+ <title>Annales. Histoire, Sciences sociales (French)</title>
+ <id>http://www.zotero.org/styles/annales</id>
+ <link href="http://www.zotero.org/styles/annales" rel="self"/>
+ <link href="http://annales.ehess.fr/?lang=en/" rel="documentation"/>
+ <author>
+ <name>Franziska Heimburger</name>
+ <email>zotero@franziska.fr</email>
+ </author>
+ <category citation-format="note"/>
+ <category field="social_science"/>
+ <issn>0395-2649</issn>
+ <updated>2013-08-29T04:18:55+00:00</updated>
+ <rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights>
+ </info>
+ <locale xml:lang="fr">
+ <terms>
+ <term name="ordinal-01">ère</term>
+ <term name="ordinal-02">e</term>
+ <term name="ordinal-03">e</term>
+ <term name="ordinal-04">e</term>
+ <term name="cited">op.&#160;cit.</term>
+ <term name="page" form="short">
+ <single>p.</single>
+ <multiple>p.</multiple>
+ </term>
+ <term name="editor" form="short">
+ <single>dir.</single>
+ <multiple>dir.</multiple>
+ </term>
+ </terms>
+ </locale>
+ <macro name="author">
+ <names variable="author">
+ <name form="long" and="text" delimiter-precedes-last="never">
+ <name-part name="family" font-variant="small-caps"/>
+ </name>
+ <label form="short" prefix="&#160;(" suffix=")"/>
+ <substitute>
+ <names variable="editor"/>
+ <names variable="translator"/>
+ <text macro="title"/>
+ </substitute>
+ </names>
+ </macro>
+ <macro name="author-short">
+ <names variable="author">
+ <name form="long" and="text" initialize-with=". " delimiter-precedes-last="never">
+ <name-part name="family" font-variant="small-caps"/>
+ </name>
+ <label form="short" prefix="&#160;(" suffix=")"/>
+ <substitute>
+ <names variable="editor"/>
+ <names variable="translator"/>
+ <text macro="title"/>
+ </substitute>
+ </names>
+ </macro>
+ <macro name="editor">
+ <names variable="editor">
+ <name form="long" and="text" delimiter-precedes-last="never" sort-separator=" " font-style="normal">
+ </name>
+ <label form="short" prefix="&#160;(" suffix=".)"/>
+ </names>
+ </macro>
+ <macro name="translator">
+ <names variable="translator">
+ <name form="long" and="text" delimiter-precedes-last="never" sort-separator=" " font-style="normal" prefix=" trad. fr. ">
+ <name-part name="family" font-variant="small-caps"/>
+ </name>
+ </names>
+ </macro>
+ <macro name="title">
+ <choose>
+ <if type="bill book graphic legal_case motion_picture report song" match="any">
+ <text variable="title" text-case="capitalize-first" font-style="italic"/>
+ </if>
+ <else-if type="article-journal article-newspaper article-magazine" match="any">
+ <group delimiter=", ">
+ <text variable="title" text-case="capitalize-first" quotes="true" font-style="normal"/>
+ <text variable="container-title" font-style="italic"/>
+ </group>
+ </else-if>
+ <else-if type="thesis" match="any">
+ <group>
+ <text variable="title" text-case="capitalize-first" quotes="true" font-style="normal"/>
+ <text variable="genre" suffix=", " prefix=" "/>
+ <text variable="publisher"/>
+ </group>
+ </else-if>
+ <else-if type="manuscript" match="any">
+ <group delimiter=",">
+ <text variable="title" text-case="capitalize-first" quotes="true" font-style="normal"/>
+ <text variable="genre" prefix=" "/>
+ </group>
+ </else-if>
+ <else-if type="chapter entry-dictionary entry-encyclopedia" match="any">
+ <group>
+ <text variable="title" text-case="capitalize-first" quotes="true" suffix=","/>
+ <text value="in" font-style="italic" suffix=" " prefix=" "/>
+ <text macro="editor" suffix=", "/>
+ <text variable="container-title" text-case="capitalize-first" font-style="italic"/>
+ </group>
+ </else-if>
+ <else-if type="webpage" match="any">
+ <group>
+ <text variable="title" text-case="capitalize-first" font-style="italic" suffix=", "/>
+ <text variable="URL" text-decoration="underline"/>
+ </group>
+ </else-if>
+ <else>
+ <text variable="title" quotes="true"/>
+ </else>
+ </choose>
+ </macro>
+ <macro name="pub-place">
+ <choose>
+ <if type="bill book chapter entry-dictionary entry-encyclopedia thesis graphic legal_case manuscript motion_picture paper-conference report song" match="any">
+ <text variable="publisher-place"/>
+ </if>
+ </choose>
+ </macro>
+ <macro name="publisher">
+ <choose>
+ <if type="bill book chapter entry-dictionary entry-encyclopedia graphic legal_case motion_picture paper-conference report song" match="any">
+ <text variable="publisher"/>
+ </if>
+ </choose>
+ </macro>
+ <macro name="yearpage">
+ <choose>
+ <if type="bill book graphic legal_case motion_picture paper-conference manuscript report song thesis" match="any">
+ <group delimiter=", " font-style="normal">
+ <date variable="issued">
+ <date-part name="year"/>
+ </date>
+ <group delimiter=" ">
+ <text term="volume" form="short"/>
+ <text variable="volume"/>
+ </group>
+ <group delimiter="&#8239;">
+ <label variable="locator" form="short"/>
+ <text variable="locator"/>
+ </group>
+ </group>
+ </if>
+ <else-if type="chapter entry-dictionary entry-encyclopedia" match="any">
+ <group delimiter=" " font-style="normal">
+ <date variable="issued">
+ <date-part name="year" suffix=", "/>
+ </date>
+ <group>
+ <text term="volume" form="short" suffix="."/>
+ <text variable="number-of-volumes" prefix=". " suffix="/"/>
+ <text variable="volume" suffix=","/>
+ </group>
+ <label variable="page" form="short"/>
+ <group delimiter=", ">
+ <text variable="page"/>
+ <group delimiter="&#8239;">
+ <label variable="locator" form="short"/>
+ <text variable="locator"/>
+ </group>
+ </group>
+ </group>
+ </else-if>
+ <else-if type="article-journal" match="any">
+ <group delimiter=" " font-style="normal">
+ <label variable="page" form="short"/>
+ <group delimiter=", ">
+ <text variable="page"/>
+ <group delimiter="&#8239;">
+ <label variable="locator" form="short"/>
+ <text variable="locator"/>
+ </group>
+ </group>
+ </group>
+ </else-if>
+ <else-if type="article-newspaper article-magazine" match="any">
+ <group delimiter=" " font-style="normal">
+ <date variable="issued" form="numeric">
+ <date-part name="day"/>
+ <date-part name="month"/>
+ <date-part name="year"/>
+ </date>
+ <group delimiter=" " font-style="normal">
+ <choose>
+ <if variable="locator" match="any">
+ <group delimiter="&#8239;">
+ <label variable="locator" form="short"/>
+ <text variable="locator"/>
+ </group>
+ </if>
+ <else-if variable="locator" match="none">
+ <label variable="page" form="short"/>
+ </else-if>
+ </choose>
+ </group>
+ </group>
+ </else-if>
+ <else-if type="webpage" match="any">
+ <group delimiter=" " font-style="normal">
+ <text value="consulté le" suffix=" " prefix=" "/>
+ <date variable="accessed" form="text">
+ <date-part name="day"/>
+ <date-part name="month"/>
+ <date-part name="year"/>
+ </date>
+ </group>
+ </else-if>
+ </choose>
+ </macro>
+ <macro name="edition">
+ <choose>
+ <if type="bill book graphic legal_case motion_picture report song chapter paper-conference" match="any">
+ <choose>
+ <if is-numeric="edition">
+ <group delimiter=" ">
+ <number variable="edition" form="ordinal"/>
+ <text term="edition" form="short"/>
+ </group>
+ </if>
+ <else>
+ <text variable="edition" text-case="capitalize-first" suffix="."/>
+ </else>
+ </choose>
+ </if>
+ <else-if type="article-journal article-magazine" match="any">
+ <group font-style="normal">
+ <choose>
+ <if variable="issued">
+ <date variable="issued">
+ <date-part name="year"/>
+ </date>
+ <text macro="volume" prefix=", "/>
+ </if>
+ <else>
+ <text macro="volume" text-case="capitalize-first"/>
+ </else>
+ </choose>
+ </group>
+ </else-if>
+ </choose>
+ <text macro="issue" prefix=", "/>
+ </macro>
+ <macro name="volume">
+ <choose>
+ <if is-numeric="volume">
+ <text term="volume" form="short" suffix=".&#160;"/>
+ <text variable="volume"/>
+ </if>
+ <else>
+ <text variable="volume"/>
+ </else>
+ </choose>
+ </macro>
+ <macro name="issue">
+ <choose>
+ <if is-numeric="issue">
+ <text term="issue" form="short" suffix="&#160;"/>
+ <text variable="issue"/>
+ </if>
+ <else>
+ <text variable="issue"/>
+ </else>
+ </choose>
+ </macro>
+ <citation>
+ <layout suffix="." delimiter="&#160;; ">
+ <choose>
+ <if position="ibid-with-locator">
+ <group delimiter=", ">
+ <text term="ibid" text-case="capitalize-first" font-style="italic" suffix="."/>
+ <group delimiter="&#8239;">
+ <label variable="locator" form="short"/>
+ <text variable="locator"/>
+ </group>
+ </group>
+ </if>
+ <else-if position="ibid">
+ <text term="ibid" text-case="capitalize-first" font-style="italic"/>
+ </else-if>
+ <else-if position="subsequent">
+ <group delimiter=", ">
+ <text macro="author-short"/>
+ <choose>
+ <if type="bill book graphic legal_case motion_picture report song thesis" match="any">
+ <text variable="title" form="short" font-style="italic"/>
+ </if>
+ <else>
+ <text variable="title" text-case="capitalize-first" form="short" quotes="true" font-style="normal"/>
+ </else>
+ </choose>
+ <text term="cited" font-style="italic" suffix="."/>
+ <group delimiter="&#8239;">
+ <label variable="locator" form="short"/>
+ <text variable="locator"/>
+ </group>
+ </group>
+ </else-if>
+ <else>
+ <group delimiter=", ">
+ <text macro="author"/>
+ <text macro="title"/>
+ <text macro="translator"/>
+ <text macro="edition"/>
+ <text macro="pub-place"/>
+ <text macro="publisher"/>
+ <text macro="yearpage"/>
+ </group>
+ </else>
+ </choose>
+ </layout>
+ </citation>
+ <bibliography>
+ <sort>
+ <key macro="author" names-min="3" names-use-first="3"/>
+ <key variable="issued" sort="descending"/>
+ </sort>
+ <layout suffix=".">
+ <group delimiter=", ">
+ <text macro="author"/>
+ <text macro="title"/>
+ <text macro="translator"/>
+ <text macro="edition"/>
+ <text macro="pub-place"/>
+ <text macro="publisher"/>
+ <text macro="yearpage"/>
+ </group>
+ </layout>
+ </bibliography>
+</style>
diff --git a/tests/issue322.expected.native b/tests/issue322.expected.native
new file mode 100644
index 0000000..6f8ceee
--- /dev/null
+++ b/tests/issue322.expected.native
@@ -0,0 +1,5 @@
+Pandoc (Meta {unMeta = fromList [("csl",MetaInlines [Str "tests/annales.csl"]),("references",MetaList [MetaMap (fromList [("author",MetaList [MetaMap (fromList [("family",MetaInlines [Str "Timmory"]),("given",MetaInlines [Str "Fran\231ois"])])]),("container-title",MetaInlines [Str "L\8217\201cran",Space,Str "fran\231ais"]),("id",MetaInlines [Str "timmory__justice_1950"]),("issue",MetaInlines [Str "272"]),("issued",MetaList [MetaMap (fromList [("day",MetaString "25"),("month",MetaString "9"),("year",MetaString "1950")])]),("language",MetaInlines [Str "fr-FR"]),("page",MetaInlines [Str "12"]),("title",MetaInlines [Emph [Str "Justice",Space,Str "est",Space,Str "faite"],Space,Str ":",Space,Str "soyons",Space,Str "justes"]),("type",MetaInlines [Str "article-journal"])])])]})
+[Para [Str "Foo",Cite [Citation {citationId = "timmory__justice_1950", citationPrefix = [], citationSuffix = [], citationMode = NormalCitation, citationNoteNum = 0, citationHash = 1}] [Note [Para [Str "Fran\231ois",Space,SmallCaps [Str "Timmory"],Str ",",Space,Str "\171\160",Emph [Str "Justice",Space,Str "est",Space,Str "faite"],Space,Str ":",Space,Str "soyons",Space,Str "justes\160\187,",Space,Emph [Str "L\8217\201cran",Space,Str "fran\231ais"],Str ",",Space,Str "1950,",Space,Str "n\7506\160\&272,",Space,Str "p.",Space,Str "12."]]],Str "."]
+,Div ("refs",["references"],[])
+ [Div ("ref-timmory__justice_1950",[],[])
+ [Para [Str "Fran\231ois",Space,SmallCaps [Str "Timmory"],Str ",",Space,Str "\171\160",Emph [Str "Justice",Space,Str "est",Space,Str "faite"],Space,Str ":",Space,Str "soyons",Space,Str "justes\160\187,",Space,Emph [Str "L\8217\201cran",Space,Str "fran\231ais"],Str ",",Space,Str "1950,",Space,Str "n\7506\160\&272,",Space,Str "p.",Space,Str "12."]]]]
diff --git a/tests/issue322.in.native b/tests/issue322.in.native
new file mode 100644
index 0000000..a5b8270
--- /dev/null
+++ b/tests/issue322.in.native
@@ -0,0 +1,2 @@
+Pandoc (Meta {unMeta = fromList [("csl",MetaInlines [Str "tests/annales.csl"]),("references",MetaList [MetaMap (fromList [("author",MetaList [MetaMap (fromList [("family",MetaInlines [Str "Timmory"]),("given",MetaInlines [Str "Fran\231ois"])])]),("container-title",MetaInlines [Str "L\8217\201cran",Space,Str "fran\231ais"]),("id",MetaInlines [Str "timmory__justice_1950"]),("issue",MetaInlines [Str "272"]),("issued",MetaList [MetaMap (fromList [("day",MetaString "25"),("month",MetaString "9"),("year",MetaString "1950")])]),("language",MetaInlines [Str "fr-FR"]),("page",MetaInlines [Str "12"]),("title",MetaInlines [Emph [Str "Justice",Space,Str "est",Space,Str "faite"],Space,Str ":",Space,Str "soyons",Space,Str "justes"]),("type",MetaInlines [Str "article-journal"])])])]})
+[Para [Str "Foo",Cite [Citation {citationId = "timmory__justice_1950", citationPrefix = [], citationSuffix = [], citationMode = NormalCitation, citationNoteNum = 0, citationHash = 0}] [Str "[@timmory__justice_1950]"],Str "."]]
diff --git a/tests/jats.csl b/tests/jats.csl
new file mode 100644
index 0000000..6487286
--- /dev/null
+++ b/tests/jats.csl
@@ -0,0 +1,208 @@
+<?xml version="1.0" encoding="utf-8"?>
+<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" default-locale="en-US">
+ <info>
+ <title>Journal Article Tag Suite</title>
+ <title-short>JATS</title-short>
+ <id>http://www.zotero.org/styles/journal-article-tag-suite</id>
+ <link href="https://github.com/MartinPaulEve/JATS-CSL/blob/master/jats.csl" rel="self"/>
+ <link rel="documentation" href="http://jats.nlm.nih.gov/archiving/tag-library/1.0/index.html"/>
+ <author>
+ <name>Martin Paul Eve</name>
+ <email>martin@martineve.com</email>
+ </author>
+ <category citation-format="numeric"/>
+ <category field="medicine"/>
+ <category field="biology"/>
+ <summary>Use this style to generate bibliographic data in Journal Article Tagging Suite (JATS) 1.0 XML format</summary>
+ <updated>2014-06-21T17:41:26+00:00</updated>
+ <rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Originally by Martin Fenner.</rights>
+ </info>
+ <locale xml:lang="en">
+ <terms>
+ <term name="et-al">{{jats}}&lt;etal/&gt;{{/jats}}</term>
+ </terms>
+ </locale>
+ <macro name="citation-number">
+ <text variable="citation-number" prefix="{{jats}}id=&quot;ref-{{/jats}}" suffix="{{jats}}&quot;&gt;{{/jats}}"/>
+ </macro>
+ <macro name="author">
+ <names variable="author">
+ <name prefix="{{jats}}&lt;name&gt;{{/jats}}" suffix="{{jats}}&lt;/name&gt;{{/jats}}" name-as-sort-order="all" sort-separator="">
+ <name-part name="family" text-case="capitalize-first" prefix="{{jats}}&lt;surname&gt;{{/jats}}" suffix="{{jats}}&lt;/surname&gt;{{/jats}}"/>
+ <name-part name="given" text-case="capitalize-first" prefix="{{jats}}&lt;given-names&gt;{{/jats}}" suffix="{{jats}}&lt;/given-names&gt;{{/jats}}"/>
+ </name>
+ <substitute>
+ <names variable="editor"/>
+ </substitute>
+ </names>
+ </macro>
+
+ <macro name="editor">
+ <names variable="editor" prefix="{{jats}}&lt;person-group person-group-type=&quot;editor&quot;&gt;{{/jats}}" suffix="{{jats}}&lt;/person-group&gt;{{/jats}}">
+ <name prefix="{{jats}}&lt;name&gt;{{/jats}}" suffix="{{jats}}&lt;/name&gt;{{/jats}}" name-as-sort-order="all" sort-separator="">
+ <name-part name="family" text-case="capitalize-first" prefix="{{jats}}&lt;surname&gt;{{/jats}}" suffix="{{jats}}&lt;/surname&gt;{{/jats}}"/>
+ <name-part name="given" text-case="capitalize-first" prefix="{{jats}}&lt;given-names&gt;{{/jats}}" suffix="{{jats}}&lt;/given-names&gt;{{/jats}}"/>
+ </name>
+ <substitute>
+ <names variable="editor"/>
+ </substitute>
+ </names>
+ </macro>
+
+ <macro name="editor">
+ <group delimiter=": ">
+ <names variable="editor">
+ <name prefix="{{jats}}&lt;name&gt;{{/jats}}" suffix="{{jats}}&lt;/name&gt;{{/jats}}" name-as-sort-order="all" sort-separator="">
+ <name-part name="family" text-case="capitalize-first" prefix="{{jats}}&lt;surname&gt;{{/jats}}" suffix="{{jats}}&lt;/surname&gt;{{/jats}}"/>
+ <name-part name="given" text-case="capitalize-first" prefix="{{jats}}&lt;given-names&gt;{{/jats}}" suffix="{{jats}}&lt;given-names&gt;{{/jats}}"/>
+ </name>
+ </names>
+ </group>
+ </macro>
+ <macro name="title">
+ <choose>
+ <if type="book" match="any">
+ <group prefix="{{jats}}&lt;source&gt;{{/jats}}" suffix="{{jats}}&lt;/source&gt;{{/jats}}">
+ <text variable="title"/>
+ </group>
+ </if>
+ <else>
+ <group prefix="{{jats}}&lt;article-title&gt;{{/jats}}" suffix="{{jats}}&lt;/article-title&gt;{{/jats}}">
+ <text variable="title"/>
+ </group>
+ </else>
+ </choose>
+ </macro>
+ <macro name="container-title">
+ <text variable="container-title" form="short" prefix="{{jats}}&lt;source&gt;{{/jats}}" suffix="{{jats}}&lt;/source&gt;{{/jats}}"/>
+ </macro>
+ <macro name="publisher">
+ <text variable="publisher" prefix="{{jats}}&lt;publisher-name&gt;{{/jats}}" suffix="{{jats}}&lt;/publisher-name&gt;{{/jats}}"/>
+ <text variable="publisher-place" prefix="{{jats}}&lt;publisher-loc&gt;{{/jats}}" suffix="{{jats}}&lt;/publisher-loc&gt;{{/jats}}"/>
+ </macro>
+ <macro name="link">
+ <choose>
+ <if match="any" variable="DOI">
+ <group prefix="{{jats}}&lt;pub-id pub-id-type=&quot;doi&quot;&gt;{{/jats}}" suffix="{{jats}}&lt;/pub-id&gt;{{/jats}}">
+ <text variable="DOI"/>
+ </group>
+ </if>
+ </choose>
+ <choose>
+ <if match="any" variable="PMID">
+ <group prefix="{{jats}}&lt;ext-link ext-link-type=&quot;pmid&quot; {{/jats}}" suffix="{{jats}}&lt;/ext-link&gt;{{/jats}}">
+ <text variable="PMID" prefix="{{jats}}xlink:href=&quot;http://www.ncbi.nlm.nih.gov/pubmed/{{/jats}}" suffix="{{jats}}&quot; xlink:type=&quot;simple&quot;&gt;{{/jats}}"/>
+ <text variable="PMID"/>
+ </group>
+ </if>
+ </choose>
+ <choose>
+ <if variable="URL" match="any">
+ <group prefix="{{jats}}&lt;ext-link ext-link-type=&quot;uri&quot; {{/jats}}" suffix="{{jats}}&lt;/ext-link&gt;{{/jats}}">
+ <text variable="URL" prefix="{{jats}}xlink:href=&quot;{{/jats}}" suffix="{{jats}}&quot; xlink:type=&quot;simple&quot;&gt;{{/jats}}"/>
+ <text variable="URL"/>
+ </group>
+ </if>
+ </choose>
+ </macro>
+ <macro name="date">
+ <choose>
+ <if type="article-journal article-magazine article-newspaper report patent book" match="any">
+ <group prefix="{{jats}}&lt;date&gt;{{/jats}}" suffix="{{jats}}&lt;/date&gt;{{/jats}}">
+ <date variable="issued">
+ <date-part name="day" form="numeric-leading-zeros" prefix="{{jats}}&lt;day&gt;{{/jats}}" suffix="{{jats}}&lt;/day&gt;{{/jats}}"/>
+ <date-part name="month" form="numeric-leading-zeros" prefix="{{jats}}&lt;month&gt;{{/jats}}" suffix="{{jats}}&lt;/month&gt;{{/jats}}"/>
+ <date-part name="year" prefix="{{jats}}&lt;year&gt;{{/jats}}" suffix="{{jats}}&lt;/year&gt;{{/jats}}"/>
+ </date>
+ </group>
+ </if>
+ <else>
+ <group prefix="{{jats}}&lt;date-in-citation content-type=&quot;access-date&quot;{{/jats}}" suffix="{{jats}}&lt;/date-in-citation&gt;{{/jats}}">
+ <date variable="accessed" prefix="{{jats}} iso-8601-date=&quot;{{/jats}}" suffix="{{jats}}&quot;&gt;{{/jats}}">
+ <date-part name="year"/>
+ <date-part name="month" form="numeric-leading-zeros" prefix="{{jats}}-{{/jats}}"/>
+ <date-part name="day" form="numeric-leading-zeros" prefix="{{jats}}-{{/jats}}"/>
+ </date>
+ <date variable="accessed">
+ <date-part name="day" prefix="{{jats}}&lt;day&gt;{{/jats}}" suffix="{{jats}}&lt;/day&gt;{{/jats}}"/>
+ <date-part name="month" form="numeric-leading-zeros" prefix="{{jats}}&lt;month&gt;{{/jats}}" suffix="{{jats}}&lt;/month&gt;{{/jats}}"/>
+ <date-part name="year" prefix="{{jats}}&lt;year&gt;{{/jats}}" suffix="{{jats}}&lt;/year&gt;{{/jats}}"/>
+ </date>
+ </group>
+ </else>
+ </choose>
+ </macro>
+ <macro name="location">
+ <choose>
+ <if type="article-journal article-magazine" match="any">
+ <text variable="volume" prefix="{{jats}}&lt;volume&gt;{{/jats}}" suffix="{{jats}}&lt;/volume&gt;{{/jats}}"/>
+ <text variable="issue" prefix="{{jats}}&lt;issue&gt;{{/jats}}" suffix="{{jats}}&lt;/issue&gt;{{/jats}}"/>
+ </if>
+ </choose>
+ <choose>
+ <if type="article-journal article-magazine article-newspaper chapter" match="any">
+ <text variable="page-first" prefix="{{jats}}&lt;fpage&gt;{{/jats}}" suffix="{{jats}}&lt;/fpage&gt;{{/jats}}"/>
+ </if>
+ </choose>
+ </macro>
+ <macro name="publication-type">
+ <group prefix="{{jats}} publication-type=&quot;{{/jats}}" suffix="{{jats}}&quot;&gt;{{/jats}}">
+ <choose>
+ <if type="article-journal article-magazine article-newspaper" match="any">
+ <text value="journal"/>
+ </if>
+ <else-if type="book" match="any">
+ <text value="book"/>
+ </else-if>
+ <else-if type="chapter" match="any">
+ <text value="bookchapter"/>
+ </else-if>
+ <else-if type="dataset" match="any">
+ <text value="dataset"/>
+ </else-if>
+ <else-if type="patent" match="any">
+ <text value="patent"/>
+ </else-if>
+ <else-if type="report" match="any">
+ <text value="report"/>
+ </else-if>
+ <else-if type="review" match="any">
+ <text value="review"/>
+ </else-if>
+ <else>
+ <text value="standard"/>
+ </else>
+ </choose>
+ </group>
+ </macro>
+ <citation collapse="citation-number">
+ <sort>
+ <key variable="citation-number"/>
+ </sort>
+ <layout delimiter=",">
+ <group prefix="{{jats}}&lt;xref ref-type=&quot;bibr&quot; rid=&quot;{{/jats}}" suffix="{{jats}}&lt;/xref&gt;{{/jats}}">
+ <text variable="citation-number" prefix="{{jats}}ref-{{/jats}}" suffix="{{jats}}&quot;&gt;{{/jats}}"/>
+ <text variable="citation-number"/>
+ </group>
+ </layout>
+ </citation>
+ <bibliography sort-separator="">
+ <layout>
+ <group prefix="{{jats}}&lt;ref {{/jats}}" suffix="{{jats}}&lt;/ref&gt;{{/jats}}">
+ <text macro="citation-number"/>
+ <group prefix="{{jats}}&lt;element-citation{{/jats}}" suffix="{{jats}}&lt;/element-citation&gt;{{/jats}}">
+ <text macro="publication-type"/>
+ <text macro="author" prefix="{{jats}}&lt;person-group person-group-type=&quot;author&quot;&gt;{{/jats}}" suffix="{{jats}}&lt;/person-group&gt;{{/jats}}"/>
+ <text macro="title" />
+ <text macro="container-title"/>
+ <text macro="editor"/>
+ <text macro="publisher"/>
+ <text macro="date"/>
+ <text macro="location"/>
+ <text macro="link"/>
+ </group>
+ </group>
+ </layout>
+ </bibliography>
+</style>
+
diff --git a/tests/test-pandoc-citeproc.hs b/tests/test-pandoc-citeproc.hs
index 945cf11..79d5e4c 100644
--- a/tests/test-pandoc-citeproc.hs
+++ b/tests/test-pandoc-citeproc.hs
@@ -1,7 +1,6 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Main where
-import Control.Monad (when)
import qualified Data.Aeson as Aeson
import Data.List (isSuffixOf)
import Data.Maybe (fromMaybe)
@@ -29,7 +28,7 @@ main = do
citeprocTests <- mapM (testCase regenerate) testnames
fs <- filter (\f -> takeExtension f `elem` [".bibtex",".biblatex"])
`fmap` getDirectoryContents "tests/biblio2yaml"
- biblio2yamlTests <- mapM biblio2yamlTest fs
+ biblio2yamlTests <- mapM (biblio2yamlTest regenerate) fs
let allTests = citeprocTests ++ biblio2yamlTests
let numpasses = length $ filter (== Passed) allTests
let numskipped = length $ filter (== Skipped) allTests
@@ -71,17 +70,21 @@ testCase regenerate csl = do
let outDoc = fromMaybe mempty $Aeson.decode jsonOut
if outDoc == expectedDoc
then err "PASSED" >> return Passed
- else do
- err "FAILED"
- showDiff (writeNative expectedDoc) (writeNative outDoc)
- when regenerate $
- UTF8.writeFile ("tests/" ++ csl ++ ".expected.native") $
+ else
+ if regenerate
+ then do
+ UTF8.writeFile ("tests/" ++ csl ++ ".expected.native") $
#if MIN_VERSION_pandoc(1,19,0)
- writeNative outDoc
+ writeNative outDoc
#else
- writeNative outDoc
+ writeNative outDoc
#endif
- return Failed
+ err "PASSED (accepted)"
+ return Passed
+ else do
+ err "FAILED"
+ showDiff (writeNative expectedDoc) (writeNative outDoc)
+ return Failed
else do
err "ERROR"
err $ "Error status " ++ show ec
@@ -99,8 +102,8 @@ showDiff expected result =
_ <- rawSystem "diff" ["-U1","expected","actual"]
setCurrentDirectory oldDir
-biblio2yamlTest :: String -> IO TestResult
-biblio2yamlTest fp = do
+biblio2yamlTest :: Bool -> String -> IO TestResult
+biblio2yamlTest regenerate fp = do
hPutStr stderr $ "[biblio2yaml/" ++ fp ++ "] "
let yamld = "tests/biblio2yaml/"
#if MIN_VERSION_pandoc(2,0,0)
@@ -129,10 +132,24 @@ biblio2yamlTest fp = do
then do
if expected == result
then err "PASSED" >> return Passed
- else do
- err $ "FAILED"
- showDiff expected result
- return Failed
+ else
+ if regenerate
+ then do
+ let accepted = bib ++ result
+#if MIN_VERSION_pandoc(2,0,0)
+ p2version <- doesFileExist (yamld ++ "/pandoc-2/" ++ fp)
+ UTF8.writeFile (if p2version
+ then (yamld ++ "/pandoc-2/" ++ fp)
+ else (yamld ++ fp)) accepted
+#else
+ UTF8.writeFile (yamld ++ fp) accepted
+#endif
+ err "PASSED (accepted)"
+ return Passed
+ else do
+ err $ "FAILED"
+ showDiff expected result
+ return Failed
else do
err "ERROR"
err $ "Error status " ++ show ec