git.iko.soy/typeable/pandoc
on master help sign in
Use lazy loading for reveal.js slide shows.

* In HTML writer, with reveal.js we use data-src instead of src for images. * In SelfContained, we also load resources from data-src. Closes #2283.

commit612f1238aafc169f220d63611442a550c3ed0b83 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 20 Feb 2017, 22:21 (10 years ago) parent8b9448a
2 files changed+19−8
src/Text/Pandoc/SelfContained.hs+1−1 src/Text/Pandoc/Writers/HTML.hs+18−7
src/Text/Pandoc/SelfContained.hs+1−1
@@ -73,7 +73,7 @@ convertTag media sourceURL t@(TagOpen tagname as)
7373 as' <- mapM processAttribute as
7474 return $ TagOpen tagname as'
7575 where processAttribute (x,y) =
76− if x == "src" || x == "href" || x == "poster"
76+ if x == "src" || x == "data-src" || x == "href" || x == "poster"
7777 then do
7878 enc <- getDataURI media sourceURL (fromAttrib "type" t) y
7979 return (x, enc)
src/Text/Pandoc/Writers/HTML.hs+18−7
@@ -953,17 +953,28 @@ inlineToHtml opts inline = do
953953 else link'' ! A.title (toValue tit)
954954 (Image attr txt (s,tit)) | treatAsImage s -> do
955955 let alternate' = stringify txt
956− let attributes = [A.src $ toValue s] ++
957− [A.title $ toValue tit | not (null tit)] ++
958− [A.alt $ toValue alternate' | not (null txt)] ++
959− imgAttrsToHtml opts attr
956+ slideVariant <- gets stSlideVariant
957+ let isReveal = slideVariant == RevealJsSlides
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) :
963+ [A.title $ toValue tit | not (null tit)] ++
964+ [A.alt $ toValue alternate' | not (null txt)] ++
965+ imgAttrsToHtml opts attr
960966 let tag = if html5 then H5.img else H.img
961967 return $ foldl (!) tag attributes
962968 -- note: null title included, as in Markdown.pl
963969 (Image attr _ (s,tit)) -> do
964− let attributes = [A.src $ toValue s] ++
965− [A.title $ toValue tit | not (null tit)] ++
966− imgAttrsToHtml opts attr
970+ slideVariant <- gets stSlideVariant
971+ let isReveal = slideVariant == RevealJsSlides
972+ let attributes =
973+ (if isReveal
974+ then customAttribute "data-src" $ toValue s
975+ else A.src $ toValue s) :
976+ [A.title $ toValue tit | not (null tit)] ++
977+ imgAttrsToHtml opts attr
967978 return $ foldl (!) H5.embed attributes
968979 -- note: null title included, as in Markdown.pl
969980 (Note contents) -> do