--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).
This commit is contained in:
John MacFarlane 2020-11-19 10:08:43 -08:00
parent 433605f9b9
commit c1fbe7b91a

View file

@ -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)