aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-05-04 08:45:43 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-05-04 08:45:43 -0700
commit9dd2eefded7879df85150484c0476410dd77a4f7 (patch)
tree4bee5336bf35702a21514547304c2116e2df614e
parentd73cb5f1a86679e42f226125d7f4dbf2564f79af (diff)
downloadpandoc-9dd2eefded7879df85150484c0476410dd77a4f7.tar.gz
JATS writer: fix citations with PMID so they validate.
Closes #5481. This includes an update to data/jats.csl.
-rw-r--r--data/jats.csl6
-rw-r--r--src/Text/Pandoc/Writers/JATS.hs16
2 files changed, 12 insertions, 10 deletions
diff --git a/data/jats.csl b/data/jats.csl
index adb364400..8f3f643d5 100644
--- a/data/jats.csl
+++ b/data/jats.csl
@@ -64,7 +64,7 @@
<if type="book" match="any">
<group prefix="{{jats}}&lt;source&gt;{{/jats}}" suffix="{{jats}}&lt;/source&gt;{{/jats}}">
<text variable="title"/>
- </group>
+ </group>
</if>
<else>
<group prefix="{{jats}}&lt;article-title&gt;{{/jats}}" suffix="{{jats}}&lt;/article-title&gt;{{/jats}}">
@@ -90,8 +90,7 @@
</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}}"/>
+ <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>
@@ -202,4 +201,3 @@
</layout>
</bibliography>
</style>
-
diff --git a/src/Text/Pandoc/Writers/JATS.hs b/src/Text/Pandoc/Writers/JATS.hs
index 6cbe35bdc..e2c4e1e72 100644
--- a/src/Text/Pandoc/Writers/JATS.hs
+++ b/src/Text/Pandoc/Writers/JATS.hs
@@ -18,7 +18,7 @@ import Prelude
import Control.Monad.Reader
import Data.Char (toLower)
import Data.Generics (everywhere, mkT)
-import Data.List (isSuffixOf, partition)
+import Data.List (isSuffixOf, partition, isPrefixOf)
import Data.Maybe (fromMaybe)
import Data.Text (Text)
import Text.Pandoc.Class (PandocMonad, report)
@@ -322,11 +322,15 @@ inlinesToJATS :: PandocMonad m => WriterOptions -> [Inline] -> JATS m Doc
inlinesToJATS opts lst = hcat <$> mapM (inlineToJATS opts) (fixCitations lst)
where
fixCitations [] = []
- fixCitations (x@(RawInline (Format "jats") "<pub-id pub-id-type=\"doi\">") : xs) =
- let isRawInline (RawInline{}) = True
- isRawInline _ = False
- (ys,zs) = break isRawInline xs
- in x : Str (stringify ys) : fixCitations zs
+ fixCitations (x:xs) | needsFixing x =
+ x : Str (stringify ys) : fixCitations zs
+ where
+ needsFixing (RawInline (Format "jats") z) =
+ "<pub-id pub-id-type=" `isPrefixOf` z
+ needsFixing _ = False
+ isRawInline (RawInline{}) = True
+ isRawInline _ = False
+ (ys,zs) = break isRawInline xs
fixCitations (x:xs) = x : fixCitations xs
-- | Convert an inline element to JATS.