summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnMacFarlane <>2019-11-04 17:32:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2019-11-04 17:32:00 (GMT)
commit78281e4c951a7d6951cfae313b1df6536e864379 (patch)
treefc7817be6bae5e5b23f84c7169b80e3a36915d0b
parent898eb6a14392168fb56987459b92b9cc0c60603e (diff)
version 0.16.3.10.16.3.1
-rw-r--r--changelog8
-rw-r--r--pandoc-citeproc.cabal2
-rw-r--r--src/Text/CSL/Data.hs46
-rw-r--r--src/Text/CSL/Input/Bibtex.hs5
-rwxr-xr-xsrc/Text/CSL/Pandoc.hs4
-rw-r--r--stack.yaml11
-rw-r--r--tests/jats.csl208
7 files changed, 255 insertions, 29 deletions
diff --git a/changelog b/changelog
index ed8c439..9c7c339 100644
--- a/changelog
+++ b/changelog
@@ -1,3 +1,11 @@
+pandoc-citeproc (0.16.3.1)
+
+ * Fix how LANG is set for bibtex conversion.
+ We were using a `-` where `_` is standard.
+ * Make locale retrieval more robust (#420).
+ Previously an error was raised if the locale was 'C'.
+ Now 'C' is treated as default (en-US locale is used).
+
pandoc-citeproc (0.16.3)
* Set `hanging-indent` class on `refs` Div if specified by the style (#410).
diff --git a/pandoc-citeproc.cabal b/pandoc-citeproc.cabal
index f8cf597..b255c4d 100644
--- a/pandoc-citeproc.cabal
+++ b/pandoc-citeproc.cabal
@@ -1,5 +1,5 @@
name: pandoc-citeproc
-version: 0.16.3
+version: 0.16.3.1
cabal-version: 1.12
synopsis: Supports using pandoc with citeproc
diff --git a/src/Text/CSL/Data.hs b/src/Text/CSL/Data.hs
index c3cb2d7..79c933a 100644
--- a/src/Text/CSL/Data.hs
+++ b/src/Text/CSL/Data.hs
@@ -48,33 +48,37 @@ instance E.Exception CSLLocaleException
-- | Raises 'CSLLocaleException' on error.
getLocale :: String -> IO L.ByteString
getLocale s = do
+ let baseLocale = takeWhile (/='.') s
#ifdef EMBED_DATA_FILES
let toLazy x = L.fromChunks [x]
- case length s of
- 0 -> maybe (E.throwIO $ CSLLocaleNotFound "en-US")
- (return . toLazy)
+ let returnDefaultLocale =
+ maybe (E.throwIO $ CSLLocaleNotFound "en-US") (return . toLazy)
$ lookup "locales-en-US.xml" localeFiles
- 2 -> let fn = ("locales-" ++ fromMaybe s (lookup s langBase) ++ ".xml")
- in case lookup fn localeFiles of
- Just x' -> return $ toLazy x'
- _ -> E.throwIO $ CSLLocaleNotFound s
- _ -> case lookup ("locales-" ++ take 5 s ++ ".xml") localeFiles of
+ case length baseLocale of
+ 0 -> returnDefaultLocale
+ 1 | baseLocale == "C" -> returnDefaultLocale
+ _ -> case lookup ("locales-" ++ baseLocale ++ ".xml") localeFiles of
Just x' -> return $ toLazy x'
- _ -> -- try again with 2-letter locale
- let s' = take 2 s in
- case lookup ("locales-" ++ fromMaybe s'
- (lookup s' langBase) ++ ".xml") localeFiles of
- Just x'' -> return $ toLazy x''
- _ -> E.throwIO $ CSLLocaleNotFound s
+ Nothing ->
+ -- try again with 2-letter locale (lang only)
+ let shortLocale = takeWhile (/='-') baseLocale in
+ case lookup ("locales-" ++ fromMaybe shortLocale
+ (lookup shortLocale langBase) ++ ".xml")
+ localeFiles of
+ Just x'' -> return $ toLazy x''
+ _ -> E.throwIO $ CSLLocaleNotFound s
#else
- f <- case length s of
- 0 -> return "locales/locales-en-US.xml"
- 2 -> getDataFileName ("locales/locales-" ++
- fromMaybe s (lookup s langBase) ++ ".xml")
- _ -> getDataFileName ("locales/locales-" ++ take 5 s ++ ".xml")
+ f <- getDataFileName $
+ case length baseLocale of
+ 0 -> "locales/locales-en-US.xml"
+ 1 | baseLocale == "C" -> "locales/locales-en-US.xml"
+ 2 -> "locales/locales-" ++
+ fromMaybe s (lookup s langBase) ++ ".xml"
+ _ -> "locales/locales-" ++ take 5 s ++ ".xml"
exists <- doesFileExist f
- if not exists && length s > 2
- then getLocale $ take 2 s -- try again with base locale
+ if not exists && length baseLocale > 2
+ then getLocale $ dropWhile (/='-') baseLocale
+ -- try again with lang only
else E.handle (E.throwIO . CSLLocaleReadError) $ L.readFile f
#endif
diff --git a/src/Text/CSL/Input/Bibtex.hs b/src/Text/CSL/Input/Bibtex.hs
index 6807dd5..1950672 100644
--- a/src/Text/CSL/Input/Bibtex.hs
+++ b/src/Text/CSL/Input/Bibtex.hs
@@ -100,7 +100,8 @@ getLangFromEnv :: IO Lang
getLangFromEnv = do
env <- getEnvironment
return $ case lookup "LANG" env of
- Just x -> case splitWhen (\c -> c == '.' || c == '_' || c == '-') x of
+ Just x -> case splitWhen (\c -> c == '_' || c == '-')
+ (takeWhile (/='.') x) of
(w:z:_) -> Lang w z
[w] | not (null w) -> Lang w mempty
_ -> Lang "en" "US"
@@ -368,7 +369,7 @@ data Lang = Lang String String -- e.g. "en" "US"
-- | Prints a 'Lang' in BCP 47 format.
langToLocale :: Lang -> String
-langToLocale (Lang x y) = x ++ ('-':y)
+langToLocale (Lang x y) = x ++ (if null y then [] else '-':y)
-- Biblatex Localization Keys (see Biblatex manual)
-- Currently we only map a subset likely to be used in Biblatex *databases*
diff --git a/src/Text/CSL/Pandoc.hs b/src/Text/CSL/Pandoc.hs
index 27dce55..4e76f6a 100755
--- a/src/Text/CSL/Pandoc.hs
+++ b/src/Text/CSL/Pandoc.hs
@@ -222,8 +222,8 @@ processCites' (Pandoc meta blocks) = do
if null envlang
then do
-- Note that LANG needs to be set for bibtex conversion:
- setEnv "LANG" "en-US.UTF-8"
- setEnv "LC_ALL" "en-US.UTF-8"
+ setEnv "LANG" "en_US.UTF-8"
+ setEnv "LC_ALL" "en_US.UTF-8"
else
setEnv "LC_ALL" envlang
let citids = query getCitationIds (Pandoc meta blocks)
diff --git a/stack.yaml b/stack.yaml
index 99e02fc..92c2312 100644
--- a/stack.yaml
+++ b/stack.yaml
@@ -12,10 +12,15 @@ extra-deps:
- pandoc-types-1.17.6.1
- HsYAML-0.2.0.0
- HsYAML-aeson-0.2.0.0
-- doctemplates-0.6.1
-- doclayout-0.1
+- texmath-0.11.3
+- haddock-library-1.8.0
+- skylighting-0.8.2.3
+- skylighting-core-0.8.2.3
+- regex-pcre-builtin-0.95.0.8.8.35
+- doctemplates-0.7
+- doclayout-0.2.0.1
- git: https://github.com/jgm/pandoc.git
- commit: b64410ff9ce64d6a2c7e09b43694b6f4245f9129
+ commit: 8f3b3afc70d163afe5e103abec77a4ffafb995bd
ghc-options:
"$locals": -fhide-source-paths
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>
+