From c1fbe7b91af03a43c6a771edca85b29334975070 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 19 Nov 2020 10:08:43 -0800 Subject: --self-contained: increase coverage. Previously we only self-contained attributes for certain tag names (`img`, `embed`, `video`, `input`, `audio`, `source`, `track`, `section`). Now we self-contain any occurrence of `src`, `data-src`, `poster`, or `data-background-image`, on any tag; and also `href` on `link` tags. Closes #6854 (which specifically asked about `asciinema-player` tags). --- src/Text/Pandoc/SelfContained.hs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/SelfContained.hs b/src/Text/Pandoc/SelfContained.hs index 07ef6f6d4..061361aba 100644 --- a/src/Text/Pandoc/SelfContained.hs +++ b/src/Text/Pandoc/SelfContained.hs @@ -50,19 +50,26 @@ makeDataURI (mime, raw) = then mime <> ";charset=utf-8" else mime -- mime type already has charset +isSourceAttribute :: T.Text -> (T.Text, T.Text) -> Bool +isSourceAttribute tagname (x,_) = + x == "src" || + x == "data-src" || + (x == "href" && tagname == "link") || + x == "poster" || + x == "data-background-image" + convertTags :: PandocMonad m => [Tag T.Text] -> m [Tag T.Text] convertTags [] = return [] convertTags (t@TagOpen{}:ts) | fromAttrib "data-external" t == "1" = (t:) <$> convertTags ts convertTags (t@(TagOpen tagname as):ts) - | tagname `elem` - ["img", "embed", "video", "input", "audio", "source", "track", - "section"] = do + | any (isSourceAttribute tagname) as + = do as' <- mapM processAttribute as rest <- convertTags ts return $ TagOpen tagname as' : rest where processAttribute (x,y) = - if x `elem` ["src", "data-src", "href", "poster", "data-background-image"] + if isSourceAttribute tagname (x,y) then do enc <- getDataURI (fromAttrib "type" t) y return (x, enc) -- cgit v1.2.3