JATS writer: fix citations (#7018)

* JATS writer: keep code lines at 80 chars or below

* JATS writer: fix citations
This commit is contained in:
Albert Krewinkel 2021-01-11 00:35:48 +01:00 committed by GitHub
parent a41cb09afe
commit 68fa437999
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 241 deletions

View file

@ -181,7 +181,7 @@ http://github.com/paulrouget/dzslides
Released under the Do What the Fuck You Want To Public License.
------------------------------------------------------------------------
Pandoc embeds a lua interpreter (via hslua).
Pandoc embeds a Lua interpreter (via hslua).
Copyright © 19942020 Lua.org, PUC-Rio.
@ -203,12 +203,3 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------
The template pandoc.jats is Copyright 2013--2015 Martin Fenner,
released under GPL version 2 or later.
The file data/jats.csl is derived from a csl file by Martin Fenner,
revised by Martin Paul Eve and then John MacFarlane.
"This work is licensed under a Creative Commons Attribution-ShareAlike 3.0
License. Originally by Martin Fenner."

View file

@ -1,203 +0,0 @@
<?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" delimiter=" ">
<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" delimiter=" ">
<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;pub-id pub-id-type=&quot;pmid&quot;&gt;{{/jats}}" suffix="{{jats}}&lt;/pub-id&gt;{{/jats}}">
<text variable="PMID"/>
</group>
</if>
</choose>
<choose>
<if variable="URL" match="any">
<text variable="URL" />
</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>

View file

@ -180,8 +180,6 @@ data-files:
data/pandoc.List.lua
-- bash completion template
data/bash_completion.tpl
-- jats csl
data/jats.csl
-- citeproc
data/default.csl
citeproc/biblatex-localization/*.lbx.strings

View file

@ -50,10 +50,9 @@ import Text.Pandoc.App.Opt (Opt (..), LineEnding (..), defaultOpts,
import Text.Pandoc.App.CommandLineOptions (parseOptions, options)
import Text.Pandoc.App.OutputSettings (OutputSettings (..), optToOutputSettings)
import Text.Pandoc.BCP47 (Lang (..), parseBCP47)
import Text.Pandoc.Builder (setMeta)
import Text.Pandoc.Filter (Filter (JSONFilter, LuaFilter), applyFilters)
import Text.Pandoc.PDF (makePDF)
import Text.Pandoc.SelfContained (makeDataURI, makeSelfContained)
import Text.Pandoc.SelfContained (makeSelfContained)
import Text.Pandoc.Shared (eastAsianLineBreakFilter, stripEmptyParagraphs,
headerShift, isURI, tabFilter, uriPathToPath, filterIpynbOutput,
defaultUserDataDirs, tshow, findM)
@ -190,17 +189,6 @@ convertWithOpts opts = do
Nothing -> readDataFile "abbreviations"
Just f -> readFileStrict f
metadata <- if format == "jats" &&
isNothing (lookupMeta "csl" (optMetadata opts)) &&
isNothing (lookupMeta "citation-style"
(optMetadata opts))
then do
jatsCSL <- readDataFile "jats.csl"
let jatsEncoded = makeDataURI
("application/xml", jatsCSL)
return $ setMeta "csl" jatsEncoded $ optMetadata opts
else return $ optMetadata opts
case lookupMetaString "lang" (optMetadata opts) of
"" -> setTranslations $ Lang "en" "" "US" []
l -> case parseBCP47 l of
@ -286,7 +274,7 @@ convertWithOpts opts = do
then fillMediaBag
else return)
>=> return . adjustMetadata (metadataFromFile <>)
>=> return . adjustMetadata (<> metadata)
>=> return . adjustMetadata (<> optMetadata opts)
>=> applyTransforms transforms
>=> applyFilters readerOpts filters [T.unpack format]
>=> maybe return extractMedia (optExtractMedia opts)

View file

@ -3,7 +3,7 @@
{-# LANGUAGE ViewPatterns #-}
{- |
Module : Text.Pandoc.Writers.JATS
Copyright : Copyright (C) 2017-2021 John MacFarlane
Copyright : 2017-2021 John MacFarlane
License : GNU GPL, version 2 or above
Maintainer : John MacFarlane <jgm@berkeley.edu>
@ -168,13 +168,15 @@ plainToPara x = x
-- | Convert a list of pairs of terms and definitions into a list of
-- JATS varlistentrys.
deflistItemsToJATS :: PandocMonad m
=> WriterOptions -> [([Inline],[[Block]])] -> JATS m (Doc Text)
=> WriterOptions
-> [([Inline],[[Block]])] -> JATS m (Doc Text)
deflistItemsToJATS opts items =
vcat <$> mapM (uncurry (deflistItemToJATS opts)) items
-- | Convert a term and a list of blocks into a JATS varlistentry.
deflistItemToJATS :: PandocMonad m
=> WriterOptions -> [Inline] -> [[Block]] -> JATS m (Doc Text)
=> WriterOptions
-> [Inline] -> [[Block]] -> JATS m (Doc Text)
deflistItemToJATS opts term defs = do
term' <- inlinesToJATS opts term
def' <- wrappedBlocksToJATS (not . isPara)
@ -186,7 +188,8 @@ deflistItemToJATS opts term defs = do
-- | Convert a list of lists of blocks to a list of JATS list items.
listItemsToJATS :: PandocMonad m
=> WriterOptions -> Maybe [Text] -> [[Block]] -> JATS m (Doc Text)
=> WriterOptions
-> Maybe [Text] -> [[Block]] -> JATS m (Doc Text)
listItemsToJATS opts markers items =
case markers of
Nothing -> vcat <$> mapM (listItemToJATS opts Nothing) items
@ -194,12 +197,13 @@ listItemsToJATS opts markers items =
-- | Convert a list of blocks into a JATS list item.
listItemToJATS :: PandocMonad m
=> WriterOptions -> Maybe Text -> [Block] -> JATS m (Doc Text)
=> WriterOptions
-> Maybe Text -> [Block] -> JATS m (Doc Text)
listItemToJATS opts mbmarker item = do
contents <- wrappedBlocksToJATS (not . isParaOrList) opts
(walk demoteHeaderAndRefs item)
return $ inTagsIndented "list-item" $
maybe empty (\lbl -> inTagsSimple "label" (text $ T.unpack lbl)) mbmarker
maybe empty (inTagsSimple "label" . text . T.unpack) mbmarker
$$ contents
imageMimeType :: Text -> [(Text, Text)] -> (Text, Text)
@ -247,7 +251,9 @@ blockToJATS opts (Div (id',"section":_,kvs) (Header _lvl _ ils : xs)) = do
return $ inTags True "sec" attribs $
inTagsSimple "title" title' $$ contents
-- Bibliography reference:
blockToJATS opts (Div (T.stripPrefix "ref-" -> Just _,_,_) [Para lst]) =
blockToJATS opts (Div (ident,_,_) [Para lst]) | "ref-" `T.isPrefixOf` ident =
inTags True "ref" [("id", ident)] .
inTagsSimple "mixed-citation" <$>
inlinesToJATS opts lst
blockToJATS opts (Div ("refs",_,_) xs) = do
contents <- blocksToJATS opts xs
@ -470,10 +476,13 @@ inlineToJATS _ (Link _attr [Str t] (T.stripPrefix "mailto:" -> Just email, _))
| escapeURI t == email =
return $ inTagsSimple "email" $ literal (escapeStringForXML email)
inlineToJATS opts (Link (ident,_,kvs) txt (T.uncons -> Just ('#', src), _)) = do
let attr = [("id", ident) | not (T.null ident)] ++
[("alt", stringify txt) | not (null txt)] ++
[("rid", src)] ++
[(k,v) | (k,v) <- kvs, k `elem` ["ref-type", "specific-use"]]
let attr = mconcat
[ [("id", ident) | not (T.null ident)]
, [("alt", stringify txt) | not (null txt)]
, [("rid", src)]
, [(k,v) | (k,v) <- kvs, k `elem` ["ref-type", "specific-use"]]
, [("ref-type", "bibr") | "ref-" `T.isPrefixOf` src]
]
if null txt
then return $ selfClosingTag "xref" attr
else do
@ -529,7 +538,7 @@ demoteHeaderAndRefs (Div ("refs",cls,kvs) bs) =
demoteHeaderAndRefs x = x
parseDate :: Text -> Maybe Day
parseDate s = msum (map (\fs -> parsetimeWith fs $ T.unpack s) formats) :: Maybe Day
parseDate s = msum (map (`parsetimeWith` T.unpack s) formats)
where parsetimeWith = parseTimeM True defaultTimeLocale
formats = ["%x","%m/%d/%Y", "%D","%F", "%d %b %Y",
"%e %B %Y", "%b. %e, %Y", "%B %e, %Y",

48
test/command/7016.md Normal file
View file

@ -0,0 +1,48 @@
```
% pandoc --citeproc --to=jats_archiving --standalone
---
csl: command/apa.csl
references:
- id: doe
type: article
author:
- family: Doe
given: Jane
container-title: Proceedings of the Academy of Test Inputs
doi: 10.x/nope
issued: 2021
title: Another article
...
Blah [@doe].
^D
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.2 20190208//EN"
"JATS-archivearticle1.dtd">
<article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" dtd-version="1.2" article-type="other">
<front>
<journal-meta>
<journal-id></journal-id>
<journal-title-group>
</journal-title-group>
<issn></issn>
<publisher>
<publisher-name></publisher-name>
</publisher>
</journal-meta>
<article-meta>
</article-meta>
</front>
<body>
<p>Blah (Doe, 2021).</p>
</body>
<back>
<ref-list>
<ref id="ref-doe">
<mixed-citation>Doe, J. (2021). Another article. <italic>Proceedings
of the Academy of Test Inputs</italic>.
doi:<ext-link ext-link-type="uri" xlink:href="https://doi.org/10.x/nope">10.x/nope</ext-link></mixed-citation>
</ref>
</ref-list>
</back>
</article>
```