@@ -159,6 +159,17 @@ listItemToJATS opts mbmarker item = do
159159 maybe empty (\lbl -> inTagsIndented "label" (text lbl)) mbmarker
160160 $$ contents
161161
162+imageMimeType :: String -> [(String, String)] -> (String, String)
163+imageMimeType src kvs =
164+ let mbMT = getMimeType src
165+ maintype = fromMaybe "image" $
166+ lookup "mimetype" kvs `mplus`
167+ (takeWhile (/='/') <$> mbMT)
168+ subtype = fromMaybe "" $
169+ lookup "mime-subtype" kvs `mplus`
170+ ((drop 1 . dropWhile (/='/')) <$> mbMT)
171+ in (maintype, subtype)
172+
162173-- | Convert a Pandoc block element to JATS.
163174blockToJATS :: PandocMonad m => WriterOptions -> Block -> JATS m Doc
164175blockToJATS _ Null = return empty
@@ -191,33 +202,21 @@ blockToJATS opts (Plain lst) = blockToJATS opts (Para lst)
191202blockToJATS opts (Para [Image (ident,_,kvs) txt
192203 (src,'f':'i':'g':':':tit)]) = do
193204 alt <- inlinesToJATS opts txt
205+ let (maintype, subtype) = imageMimeType src kvs
194206 let capt = if null txt
195207 then empty
196208 else inTagsSimple "caption" alt
197209 let attr = [("id", ident) | not (null ident)] ++
198210 [(k,v) | (k,v) <- kvs, k `elem` ["fig-type", "orientation",
199211 "position", "specific-use"]]
200− let mbMT = getMimeType src
201− let maintype = fromMaybe "image" $
202− lookup "mimetype" kvs `mplus`
203− (takeWhile (/='/') <$> mbMT)
204− let subtype = fromMaybe "" $
205− lookup "mime-subtype" kvs `mplus`
206− ((drop 1 . dropWhile (/='/')) <$> mbMT)
207212 let graphicattr = [("mimetype",maintype),
208− ("mime-subtype",drop 1 subtype),
213+ ("mime-subtype",subtype),
209214 ("xlink:href",src), -- do we need to URL escape this?
210215 ("xlink:title",tit)]
211216 return $ inTags True "fig" attr $
212217 capt $$ selfClosingTag "graphic" graphicattr
213218blockToJATS _ (Para [Image (ident,_,kvs) _ (src, tit)]) = do
214− let mbMT = getMimeType src
215− let maintype = fromMaybe "image" $
216− lookup "mimetype" kvs `mplus`
217− (takeWhile (/='/') <$> mbMT)
218− let subtype = fromMaybe "" $
219− lookup "mime-subtype" kvs `mplus`
220− ((drop 1 . dropWhile (/='/')) <$> mbMT)
219+ let (maintype, subtype) = imageMimeType src kvs
221220 let attr = [("id", ident) | not (null ident)] ++
222221 [("mimetype", maintype),
223222 ("mime-subtype", subtype),