git.iko.soy/typeable/pandoc
on master help sign in
Use lazy loading for reveal.js slide shows.
612f123John MacFarlane
src/Text/Pandoc/SelfContained.hs+1−1
@@ -73,7 +73,7 @@ convertTag media sourceURL t@(TagOpen tagname as)
73 as' <- mapM processAttribute as
73 as' <- mapM processAttribute as
74 return $ TagOpen tagname as'
74 return $ TagOpen tagname as'
75 where processAttribute (x,y) =
75 where processAttribute (x,y) =
76− if x == "src" || x == "href" || x == "poster"
76+ if x == "src" || x == "data-src" || x == "href" || x == "poster"
77 then do
77 then do
78 enc <- getDataURI media sourceURL (fromAttrib "type" t) y
78 enc <- getDataURI media sourceURL (fromAttrib "type" t) y
79 return (x, enc)
79 return (x, enc)
src/Text/Pandoc/Writers/HTML.hs+18−7
@@ -953,17 +953,28 @@ inlineToHtml opts inline = do
953 else link'' ! A.title (toValue tit)
953 else link'' ! A.title (toValue tit)
954 (Image attr txt (s,tit)) | treatAsImage s -> do
954 (Image attr txt (s,tit)) | treatAsImage s -> do
955 let alternate' = stringify txt
955 let alternate' = stringify txt
956+ slideVariant <- gets stSlideVariant
957+ let isReveal = slideVariant == RevealJsSlides
956− let attributes = [A.src $ toValue s] ++
958+ let attributes =
959+ -- reveal.js uses data-src for lazy loading
960+ (if isReveal
961+ then customAttribute "data-src" $ toValue s
962+ else A.src $ toValue s) :
957− [A.title $ toValue tit | not (null tit)] ++
963+ [A.title $ toValue tit | not (null tit)] ++
958− [A.alt $ toValue alternate' | not (null txt)] ++
964+ [A.alt $ toValue alternate' | not (null txt)] ++
959− imgAttrsToHtml opts attr
965+ imgAttrsToHtml opts attr
960 let tag = if html5 then H5.img else H.img
966 let tag = if html5 then H5.img else H.img
961 return $ foldl (!) tag attributes
967 return $ foldl (!) tag attributes
962 -- note: null title included, as in Markdown.pl
968 -- note: null title included, as in Markdown.pl
963 (Image attr _ (s,tit)) -> do
969 (Image attr _ (s,tit)) -> do
970+ slideVariant <- gets stSlideVariant
971+ let isReveal = slideVariant == RevealJsSlides
964− let attributes = [A.src $ toValue s] ++
972+ let attributes =
973+ (if isReveal
974+ then customAttribute "data-src" $ toValue s
975+ else A.src $ toValue s) :
965− [A.title $ toValue tit | not (null tit)] ++
976+ [A.title $ toValue tit | not (null tit)] ++
966− imgAttrsToHtml opts attr
977+ imgAttrsToHtml opts attr
967 return $ foldl (!) H5.embed attributes
978 return $ foldl (!) H5.embed attributes
968 -- note: null title included, as in Markdown.pl
979 -- note: null title included, as in Markdown.pl
969 (Note contents) -> do
980 (Note contents) -> do