git.iko.soy/typeable/pandoc
on master help sign in
Deduplicate JATS writer image mime type code
commitfa0241592c0341c85246e94b5a0342ef3a301755 authorHamish Mackenzie <Hamish.K.Mackenzie@googlemail.com> dateThu 14 Dec 2017, 18:38 (9 years ago) parentec16935
2 files changed+15−16
src/Text/Pandoc/Writers/JATS.hs+14−15 test/writer.jats+1−1
src/Text/Pandoc/Writers/JATS.hs+14−15
@@ -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),
test/writer.jats+1−1
@@ -1379,7 +1379,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{</preformat>
13791379 </p>
13801380 <fig>
13811381 <caption>lalune</caption>
1382− <graphic mimetype="image" mime-subtype="peg" xlink:href="lalune.jpg" xlink:title="Voyage dans la Lune" />
1382+ <graphic mimetype="image" mime-subtype="jpeg" xlink:href="lalune.jpg" xlink:title="Voyage dans la Lune" />
13831383 </fig>
13841384 <p>
13851385 Here is a movie