@@ -159,6 +159,17 @@ listItemToJATS opts mbmarker item = do
159 maybe empty (\lbl -> inTagsIndented "label" (text lbl)) mbmarker
159 maybe empty (\lbl -> inTagsIndented "label" (text lbl)) mbmarker
160 $$ contents
160 $$ contents
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)
162-- | Convert a Pandoc block element to JATS.
173-- | Convert a Pandoc block element to JATS.
163blockToJATS :: PandocMonad m => WriterOptions -> Block -> JATS m Doc
174blockToJATS :: PandocMonad m => WriterOptions -> Block -> JATS m Doc
164blockToJATS _ Null = return empty
175blockToJATS _ Null = return empty
@@ -191,33 +202,21 @@ blockToJATS opts (Plain lst) = blockToJATS opts (Para lst)
191blockToJATS opts (Para [Image (ident,_,kvs) txt
202blockToJATS opts (Para [Image (ident,_,kvs) txt
192 (src,'f':'i':'g':':':tit)]) = do
203 (src,'f':'i':'g':':':tit)]) = do
193 alt <- inlinesToJATS opts txt
204 alt <- inlinesToJATS opts txt
205+ let (maintype, subtype) = imageMimeType src kvs
194 let capt = if null txt
206 let capt = if null txt
195 then empty
207 then empty
196 else inTagsSimple "caption" alt
208 else inTagsSimple "caption" alt
197 let attr = [("id", ident) | not (null ident)] ++
209 let attr = [("id", ident) | not (null ident)] ++
198 [(k,v) | (k,v) <- kvs, k `elem` ["fig-type", "orientation",
210 [(k,v) | (k,v) <- kvs, k `elem` ["fig-type", "orientation",
199 "position", "specific-use"]]
211 "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)
207 let graphicattr = [("mimetype",maintype),
212 let graphicattr = [("mimetype",maintype),
208− ("mime-subtype",drop 1 subtype),
213+ ("mime-subtype",subtype),
209 ("xlink:href",src), -- do we need to URL escape this?
214 ("xlink:href",src), -- do we need to URL escape this?
210 ("xlink:title",tit)]
215 ("xlink:title",tit)]
211 return $ inTags True "fig" attr $
216 return $ inTags True "fig" attr $
212 capt $$ selfClosingTag "graphic" graphicattr
217 capt $$ selfClosingTag "graphic" graphicattr
213blockToJATS _ (Para [Image (ident,_,kvs) _ (src, tit)]) = do
218blockToJATS _ (Para [Image (ident,_,kvs) _ (src, tit)]) = do
214− let mbMT = getMimeType src
219+ let (maintype, subtype) = imageMimeType src kvs
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)
221 let attr = [("id", ident) | not (null ident)] ++
220 let attr = [("id", ident) | not (null ident)] ++
222 [("mimetype", maintype),
221 [("mimetype", maintype),
223 ("mime-subtype", subtype),
222 ("mime-subtype", subtype),