aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/Writers/JATS.hs29
-rw-r--r--test/writer.jats2
2 files changed, 15 insertions, 16 deletions
diff --git a/src/Text/Pandoc/Writers/JATS.hs b/src/Text/Pandoc/Writers/JATS.hs
index fe5a36d13..8824eeb24 100644
--- a/src/Text/Pandoc/Writers/JATS.hs
+++ b/src/Text/Pandoc/Writers/JATS.hs
@@ -159,6 +159,17 @@ listItemToJATS opts mbmarker item = do
maybe empty (\lbl -> inTagsIndented "label" (text lbl)) mbmarker
$$ contents
+imageMimeType :: String -> [(String, String)] -> (String, String)
+imageMimeType src kvs =
+ let mbMT = getMimeType src
+ maintype = fromMaybe "image" $
+ lookup "mimetype" kvs `mplus`
+ (takeWhile (/='/') <$> mbMT)
+ subtype = fromMaybe "" $
+ lookup "mime-subtype" kvs `mplus`
+ ((drop 1 . dropWhile (/='/')) <$> mbMT)
+ in (maintype, subtype)
+
-- | Convert a Pandoc block element to JATS.
blockToJATS :: PandocMonad m => WriterOptions -> Block -> JATS m Doc
blockToJATS _ Null = return empty
@@ -191,33 +202,21 @@ blockToJATS opts (Plain lst) = blockToJATS opts (Para lst)
blockToJATS opts (Para [Image (ident,_,kvs) txt
(src,'f':'i':'g':':':tit)]) = do
alt <- inlinesToJATS opts txt
+ let (maintype, subtype) = imageMimeType src kvs
let capt = if null txt
then empty
else inTagsSimple "caption" alt
let attr = [("id", ident) | not (null ident)] ++
[(k,v) | (k,v) <- kvs, k `elem` ["fig-type", "orientation",
"position", "specific-use"]]
- let mbMT = getMimeType src
- let maintype = fromMaybe "image" $
- lookup "mimetype" kvs `mplus`
- (takeWhile (/='/') <$> mbMT)
- let subtype = fromMaybe "" $
- lookup "mime-subtype" kvs `mplus`
- ((drop 1 . dropWhile (/='/')) <$> mbMT)
let graphicattr = [("mimetype",maintype),
- ("mime-subtype",drop 1 subtype),
+ ("mime-subtype",subtype),
("xlink:href",src), -- do we need to URL escape this?
("xlink:title",tit)]
return $ inTags True "fig" attr $
capt $$ selfClosingTag "graphic" graphicattr
blockToJATS _ (Para [Image (ident,_,kvs) _ (src, tit)]) = do
- let mbMT = getMimeType src
- let maintype = fromMaybe "image" $
- lookup "mimetype" kvs `mplus`
- (takeWhile (/='/') <$> mbMT)
- let subtype = fromMaybe "" $
- lookup "mime-subtype" kvs `mplus`
- ((drop 1 . dropWhile (/='/')) <$> mbMT)
+ let (maintype, subtype) = imageMimeType src kvs
let attr = [("id", ident) | not (null ident)] ++
[("mimetype", maintype),
("mime-subtype", subtype),
diff --git a/test/writer.jats b/test/writer.jats
index 0f52965bc..507e9f672 100644
--- a/test/writer.jats
+++ b/test/writer.jats
@@ -1379,7 +1379,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{</preformat>
</p>
<fig>
<caption>lalune</caption>
- <graphic mimetype="image" mime-subtype="peg" xlink:href="lalune.jpg" xlink:title="Voyage dans la Lune" />
+ <graphic mimetype="image" mime-subtype="jpeg" xlink:href="lalune.jpg" xlink:title="Voyage dans la Lune" />
</fig>
<p>
Here is a movie