@@ -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
@@ -168,6 +179,13 @@ blockToJATS opts (Div ('r':'e':'f':'-':_,_,_) [Para lst]) =
168179blockToJATS opts (Div ("refs",_,_) xs) = do
169180 contents <- blocksToJATS opts xs
170181 return $ inTagsIndented "ref-list" contents
182+blockToJATS opts (Div (ident,[cls],kvs) bs) | cls `elem` ["fig", "caption", "table-wrap"] = do
183+ contents <- blocksToJATS opts bs
184+ let attr = [("id", ident) | not (null ident)] ++
185+ [("xml:lang",l) | ("lang",l) <- kvs] ++
186+ [(k,v) | (k,v) <- kvs, k `elem` ["specific-use",
187+ "content-type", "orientation", "position"]]
188+ return $ inTags True cls attr contents
171189blockToJATS opts (Div (ident,_,kvs) bs) = do
172190 contents <- blocksToJATS opts bs
173191 let attr = [("id", ident) | not (null ident)] ++
@@ -175,35 +193,40 @@ blockToJATS opts (Div (ident,_,kvs) bs) = do
175193 [(k,v) | (k,v) <- kvs, k `elem` ["specific-use",
176194 "content-type", "orientation", "position"]]
177195 return $ inTags True "boxed-text" attr contents
178−blockToJATS _ h@(Header{}) = do
179− -- should not occur after hierarchicalize, except inside lists/blockquotes
180− report $ BlockNotRendered h
181− return empty
196+blockToJATS opts (Header _ _ title) = do
197+ title' <- inlinesToJATS opts title
198+ return $ inTagsSimple "title" title'
182199-- No Plain, everything needs to be in a block-level tag
183200blockToJATS opts (Plain lst) = blockToJATS opts (Para lst)
184201-- title beginning with fig: indicates that the image is a figure
185202blockToJATS opts (Para [Image (ident,_,kvs) txt
186203 (src,'f':'i':'g':':':tit)]) = do
187204 alt <- inlinesToJATS opts txt
205+ let (maintype, subtype) = imageMimeType src kvs
188206 let capt = if null txt
189207 then empty
190208 else inTagsSimple "caption" alt
191209 let attr = [("id", ident) | not (null ident)] ++
192210 [(k,v) | (k,v) <- kvs, k `elem` ["fig-type", "orientation",
193211 "position", "specific-use"]]
194− let mbMT = getMimeType src
195− let maintype = fromMaybe "image" $
196− lookup "mimetype" kvs `mplus`
197− (takeWhile (/='/') <$> mbMT)
198− let subtype = fromMaybe "" $
199− lookup "mime-subtype" kvs `mplus`
200− ((drop 1 . dropWhile (/='/')) <$> mbMT)
201212 let graphicattr = [("mimetype",maintype),
202− ("mime-subtype",drop 1 subtype),
213+ ("mime-subtype",subtype),
203214 ("xlink:href",src), -- do we need to URL escape this?
204215 ("xlink:title",tit)]
205216 return $ inTags True "fig" attr $
206217 capt $$ selfClosingTag "graphic" graphicattr
218+blockToJATS _ (Para [Image (ident,_,kvs) _ (src, tit)]) = do
219+ let (maintype, subtype) = imageMimeType src kvs
220+ let attr = [("id", ident) | not (null ident)] ++
221+ [("mimetype", maintype),
222+ ("mime-subtype", subtype),
223+ ("xlink:href", src)] ++
224+ [("xlink:title", tit) | not (null tit)] ++
225+ [(k,v) | (k,v) <- kvs, k `elem` ["baseline-shift",
226+ "content-type", "specific-use", "xlink:actuate",
227+ "xlink:href", "xlink:role", "xlink:show",
228+ "xlink:type"]]
229+ return $ selfClosingTag "graphic" attr
207230blockToJATS opts (Para lst) =
208231 inTagsIndented "p" <$> inlinesToJATS opts lst
209232blockToJATS opts (LineBlock lns) =
@@ -379,8 +402,8 @@ inlineToJATS _ (Link _attr [Str t] ('m':'a':'i':'l':'t':'o':':':email, _))
379402 return $ inTagsSimple "email" $ text (escapeStringForXML email)
380403inlineToJATS opts (Link (ident,_,kvs) txt ('#':src, _)) = do
381404 let attr = [("id", ident) | not (null ident)] ++
382− [("alt", stringify txt),
383− ("rid", src)] ++
405+ [("alt", stringify txt) | not (null txt)] ++
406+ [("rid", src)] ++
384407 [(k,v) | (k,v) <- kvs, k `elem` ["ref-type", "specific-use"]]
385408 contents <- inlinesToJATS opts txt
386409 return $ inTags False "xref" attr contents