JATS writer: fix citations with PMID so they validate.

Closes #5481. This includes an update to data/jats.csl.
This commit is contained in:
John MacFarlane 2019-05-04 08:45:43 -07:00
parent d73cb5f1a8
commit 9dd2eefded
2 changed files with 12 additions and 10 deletions

View file

@ -64,7 +64,7 @@
<if type="book" match="any"> <if type="book" match="any">
<group prefix="{{jats}}&lt;source&gt;{{/jats}}" suffix="{{jats}}&lt;/source&gt;{{/jats}}"> <group prefix="{{jats}}&lt;source&gt;{{/jats}}" suffix="{{jats}}&lt;/source&gt;{{/jats}}">
<text variable="title"/> <text variable="title"/>
</group> </group>
</if> </if>
<else> <else>
<group prefix="{{jats}}&lt;article-title&gt;{{/jats}}" suffix="{{jats}}&lt;/article-title&gt;{{/jats}}"> <group prefix="{{jats}}&lt;article-title&gt;{{/jats}}" suffix="{{jats}}&lt;/article-title&gt;{{/jats}}">
@ -90,8 +90,7 @@
</choose> </choose>
<choose> <choose>
<if match="any" variable="PMID"> <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}}"> <group prefix="{{jats}}&lt;pub-id pub-id-type=&quot;pmid&quot;&gt;{{/jats}}" suffix="{{jats}}&lt;/pub-id&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"/> <text variable="PMID"/>
</group> </group>
</if> </if>
@ -202,4 +201,3 @@
</layout> </layout>
</bibliography> </bibliography>
</style> </style>

View file

@ -18,7 +18,7 @@ import Prelude
import Control.Monad.Reader import Control.Monad.Reader
import Data.Char (toLower) import Data.Char (toLower)
import Data.Generics (everywhere, mkT) import Data.Generics (everywhere, mkT)
import Data.List (isSuffixOf, partition) import Data.List (isSuffixOf, partition, isPrefixOf)
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
import Data.Text (Text) import Data.Text (Text)
import Text.Pandoc.Class (PandocMonad, report) 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) inlinesToJATS opts lst = hcat <$> mapM (inlineToJATS opts) (fixCitations lst)
where where
fixCitations [] = [] fixCitations [] = []
fixCitations (x@(RawInline (Format "jats") "<pub-id pub-id-type=\"doi\">") : xs) = fixCitations (x:xs) | needsFixing x =
let isRawInline (RawInline{}) = True x : Str (stringify ys) : fixCitations zs
isRawInline _ = False where
(ys,zs) = break isRawInline xs needsFixing (RawInline (Format "jats") z) =
in x : Str (stringify ys) : fixCitations zs "<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 fixCitations (x:xs) = x : fixCitations xs
-- | Convert an inline element to JATS. -- | Convert an inline element to JATS.