@@ -65,18 +65,21 @@ import Text.Blaze.Internal (preEscapedString, preEscapedText)
6565#endif
6666#if MIN_VERSION_blaze_html(0,5,1)
6767import qualified Text.Blaze.XHtml5 as H5
68+import qualified Text.Blaze.XHtml5.Attributes as A5
6869#else
6970import qualified Text.Blaze.Html5 as H5
71+import qualified Text.Blaze.Html5.Attributes as A5
7072#endif
7173import Control.Monad.Except (throwError)
7274import Data.Aeson (Value)
73−import System.FilePath (takeBaseName, takeExtension)
75+import System.FilePath (takeBaseName)
7476import Text.Blaze.Html.Renderer.Text (renderHtml)
7577import qualified Text.Blaze.XHtml1.Transitional as H
7678import qualified Text.Blaze.XHtml1.Transitional.Attributes as A
7779import Text.Pandoc.Class (PandocMonad, report, runPure)
7880import Text.Pandoc.Error
7981import Text.Pandoc.Logging
82+import Text.Pandoc.MIME (mediaCategory)
8083import Text.TeXMath
8184import Text.XML.Light (elChildren, unode, unqual)
8285import qualified Text.XML.Light as XML
@@ -665,18 +668,6 @@ dimensionsToAttrList attr = consolidateStyles $ go Width ++ go Height
665668 (Just x) -> [("style", show dir ++ ":" ++ show x)]
666669 Nothing -> []
667670
668−imageExts :: [String]
669−imageExts = [ "art", "bmp", "cdr", "cdt", "cpt", "cr2", "crw", "djvu", "erf",
670− "gif", "ico", "ief", "jng", "jpg", "jpeg", "nef", "orf", "pat", "pbm",
671− "pcx", "pgm", "png", "pnm", "ppm", "psd", "ras", "rgb", "svg", "tiff",
672− "wbmp", "xbm", "xpm", "xwd" ]
673−
674−treatAsImage :: FilePath -> Bool
675−treatAsImage fp =
676− let path = maybe fp uriPath (parseURIReference fp)
677− ext = map toLower $ drop 1 $ takeExtension path
678− in null ext || ext `elem` imageExts
679−
680671figure :: PandocMonad m
681672 => WriterOptions -> Attr -> [Inline] -> (String, String)
682673 -> StateT WriterState m Html
@@ -1135,33 +1126,34 @@ inlineToHtml opts inline = do
11351126 return $ if null tit
11361127 then link'
11371128 else link' ! A.title (toValue tit)
1138− (Image attr txt (s,tit)) | treatAsImage s -> do
1139− let alternate' = stringify txt
1129+ (Image attr txt (s,tit)) -> do
1130+ let alternate = stringify txt
11401131 slideVariant <- gets stSlideVariant
11411132 let isReveal = slideVariant == RevealJsSlides
11421133 attrs <- imgAttrsToHtml opts attr
11431134 let attributes =
11441135 -- reveal.js uses data-src for lazy loading
1145− (if isReveal
1146− then customAttribute "data-src" $ toValue s
1147− else A.src $ toValue s) :
1148− [A.title $ toValue tit | not (null tit)] ++
1149− [A.alt $ toValue alternate' | not (null txt)] ++
1150− attrs
1151− let tag = if html5 then H5.img else H.img
1152− return $ foldl (!) tag attributes
1153− -- note: null title included, as in Markdown.pl
1154− (Image attr _ (s,tit)) -> do
1155− slideVariant <- gets stSlideVariant
1156− let isReveal = slideVariant == RevealJsSlides
1157− attrs <- imgAttrsToHtml opts attr
1158− let attributes =
11591136 (if isReveal
11601137 then customAttribute "data-src" $ toValue s
11611138 else A.src $ toValue s) :
11621139 [A.title $ toValue tit | not (null tit)] ++
11631140 attrs
1164− return $ foldl (!) H5.embed attributes
1141+ imageTag = (if html5 then H5.img else H.img
1142+ , [A.alt $ toValue alternate | not (null txt)] )
1143+ mediaTag tg fallbackTxt =
1144+ let linkTxt = if null txt
1145+ then fallbackTxt
1146+ else alternate
1147+ in (tg $ H.a ! A.href (toValue s) $ toHtml linkTxt
1148+ , [A5.controls ""] )
1149+ normSrc = maybe s uriPath (parseURIReference s)
1150+ (tag, specAttrs) = case mediaCategory normSrc of
1151+ Just "image" -> imageTag
1152+ Just "video" -> mediaTag H5.video "Video"
1153+ Just "audio" -> mediaTag H5.audio "Audio"
1154+ Just _ -> (H5.embed, [])
1155+ _ -> imageTag
1156+ return $ foldl (!) tag $ attributes ++ specAttrs
11651157 -- note: null title included, as in Markdown.pl
11661158 (Note contents) -> do
11671159 notes <- gets stNotes