diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-02-20 22:21:20 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-02-20 22:21:20 +0100 |
commit | 612f1238aafc169f220d63611442a550c3ed0b83 (patch) | |
tree | a00000b1a851a6b5d6adb77dbba68c8baf96409c | |
parent | 8b9448aa17e330f9ff25fc7ddf909151fb876132 (diff) | |
download | pandoc-612f1238aafc169f220d63611442a550c3ed0b83.tar.gz |
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.
-rw-r--r-- | src/Text/Pandoc/SelfContained.hs | 2 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/HTML.hs | 25 |
2 files changed, 19 insertions, 8 deletions
diff --git a/src/Text/Pandoc/SelfContained.hs b/src/Text/Pandoc/SelfContained.hs index 85b298a85..5258aa5f7 100644 --- a/src/Text/Pandoc/SelfContained.hs +++ b/src/Text/Pandoc/SelfContained.hs @@ -73,7 +73,7 @@ convertTag media sourceURL t@(TagOpen tagname as) as' <- mapM processAttribute as return $ TagOpen tagname as' where processAttribute (x,y) = - if x == "src" || x == "href" || x == "poster" + if x == "src" || x == "data-src" || x == "href" || x == "poster" then do enc <- getDataURI media sourceURL (fromAttrib "type" t) y return (x, enc) diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 99f8c5b42..6661ffc2d 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -953,17 +953,28 @@ inlineToHtml opts inline = do else link'' ! A.title (toValue tit) (Image attr txt (s,tit)) | treatAsImage s -> do let alternate' = stringify txt - let attributes = [A.src $ toValue s] ++ - [A.title $ toValue tit | not (null tit)] ++ - [A.alt $ toValue alternate' | not (null txt)] ++ - imgAttrsToHtml opts attr + slideVariant <- gets stSlideVariant + let isReveal = slideVariant == RevealJsSlides + let attributes = + -- reveal.js uses data-src for lazy loading + (if isReveal + 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)] ++ + imgAttrsToHtml opts attr 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 - let attributes = [A.src $ toValue s] ++ - [A.title $ toValue tit | not (null tit)] ++ - imgAttrsToHtml opts attr + slideVariant <- gets stSlideVariant + let isReveal = slideVariant == RevealJsSlides + let attributes = + (if isReveal + then customAttribute "data-src" $ toValue s + else A.src $ toValue s) : + [A.title $ toValue tit | not (null tit)] ++ + imgAttrsToHtml opts attr return $ foldl (!) H5.embed attributes -- note: null title included, as in Markdown.pl (Note contents) -> do |