aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers
diff options
context:
space:
mode:
authormb21 <mb21@users.noreply.github.com>2019-05-11 18:54:43 +0200
committermb21 <mb21@users.noreply.github.com>2019-05-29 09:43:50 +0200
commita58304e00edc3c7d78c352c379e843cb908e6887 (patch)
tree7ff97b4bdeddb03c1fef74299be7c9e370842061 /src/Text/Pandoc/Writers
parent47249b05c4345a40353a37f4b7f7170aa2ea5773 (diff)
downloadpandoc-a58304e00edc3c7d78c352c379e843cb908e6887.tar.gz
HTML writer: output video and audio elements
depending on file extension of the image path
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs52
1 files changed, 22 insertions, 30 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index 5004f4111..ca44583ab 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -65,18 +65,21 @@ import Text.Blaze.Internal (preEscapedString, preEscapedText)
#endif
#if MIN_VERSION_blaze_html(0,5,1)
import qualified Text.Blaze.XHtml5 as H5
+import qualified Text.Blaze.XHtml5.Attributes as A5
#else
import qualified Text.Blaze.Html5 as H5
+import qualified Text.Blaze.Html5.Attributes as A5
#endif
import Control.Monad.Except (throwError)
import Data.Aeson (Value)
-import System.FilePath (takeBaseName, takeExtension)
+import System.FilePath (takeBaseName)
import Text.Blaze.Html.Renderer.Text (renderHtml)
import qualified Text.Blaze.XHtml1.Transitional as H
import qualified Text.Blaze.XHtml1.Transitional.Attributes as A
import Text.Pandoc.Class (PandocMonad, report, runPure)
import Text.Pandoc.Error
import Text.Pandoc.Logging
+import Text.Pandoc.MIME (mediaCategory)
import Text.TeXMath
import Text.XML.Light (elChildren, unode, unqual)
import qualified Text.XML.Light as XML
@@ -665,18 +668,6 @@ dimensionsToAttrList attr = consolidateStyles $ go Width ++ go Height
(Just x) -> [("style", show dir ++ ":" ++ show x)]
Nothing -> []
-imageExts :: [String]
-imageExts = [ "art", "bmp", "cdr", "cdt", "cpt", "cr2", "crw", "djvu", "erf",
- "gif", "ico", "ief", "jng", "jpg", "jpeg", "nef", "orf", "pat", "pbm",
- "pcx", "pgm", "png", "pnm", "ppm", "psd", "ras", "rgb", "svg", "tiff",
- "wbmp", "xbm", "xpm", "xwd" ]
-
-treatAsImage :: FilePath -> Bool
-treatAsImage fp =
- let path = maybe fp uriPath (parseURIReference fp)
- ext = map toLower $ drop 1 $ takeExtension path
- in null ext || ext `elem` imageExts
-
figure :: PandocMonad m
=> WriterOptions -> Attr -> [Inline] -> (String, String)
-> StateT WriterState m Html
@@ -1135,8 +1126,8 @@ inlineToHtml opts inline = do
return $ if null tit
then link'
else link' ! A.title (toValue tit)
- (Image attr txt (s,tit)) | treatAsImage s -> do
- let alternate' = stringify txt
+ (Image attr txt (s,tit)) -> do
+ let alternate = stringify txt
slideVariant <- gets stSlideVariant
let isReveal = slideVariant == RevealJsSlides
attrs <- imgAttrsToHtml opts attr
@@ -1146,22 +1137,23 @@ inlineToHtml opts inline = do
then customAttribute "data-src" $ toValue s
else A.src $ toValue s) :
[A.title $ toValue tit | not (null tit)] ++
- [A.alt $ toValue alternate' | not (null txt)] ++
- attrs
- let tag = if html5 then H5.img else H.img
- return $ foldl (!) tag attributes
- -- note: null title included, as in Markdown.pl
- (Image attr _ (s,tit)) -> do
- slideVariant <- gets stSlideVariant
- let isReveal = slideVariant == RevealJsSlides
- attrs <- imgAttrsToHtml opts attr
- let attributes =
- (if isReveal
- then customAttribute "data-src" $ toValue s
- else A.src $ toValue s) :
- [A.title $ toValue tit | not (null tit)] ++
attrs
- return $ foldl (!) H5.embed attributes
+ imageTag = (if html5 then H5.img else H.img
+ , [A.alt $ toValue alternate | not (null txt)] )
+ mediaTag tg fallbackTxt =
+ let linkTxt = if null txt
+ then fallbackTxt
+ else alternate
+ in (tg $ H.a ! A.href (toValue s) $ toHtml linkTxt
+ , [A5.controls ""] )
+ normSrc = maybe s uriPath (parseURIReference s)
+ (tag, specAttrs) = case mediaCategory normSrc of
+ Just "image" -> imageTag
+ Just "video" -> mediaTag H5.video "Video"
+ Just "audio" -> mediaTag H5.audio "Audio"
+ Just _ -> (H5.embed, [])
+ _ -> imageTag
+ return $ foldl (!) tag $ attributes ++ specAttrs
-- note: null title included, as in Markdown.pl
(Note contents) -> do
notes <- gets stNotes