diff options
author | John MacFarlane <jgm@berkeley.edu> | 2020-11-19 10:08:43 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2020-11-19 10:08:43 -0800 |
commit | c1fbe7b91af03a43c6a771edca85b29334975070 (patch) | |
tree | 80baff48b4fcda9b82a937303093e71228bcf737 /src/Text/Pandoc | |
parent | 433605f9b94c3e64fa79b9c6ff85f7bcb05d9228 (diff) | |
download | pandoc-c1fbe7b91af03a43c6a771edca85b29334975070.tar.gz |
--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).
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/SelfContained.hs | 15 |
1 files changed, 11 insertions, 4 deletions
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) |