Skip to content

Commit

Permalink
--self-contained: increase coverage.
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
jgm committed Nov 19, 2020
1 parent 433605f commit c1fbe7b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Text/Pandoc/SelfContained.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c1fbe7b

Please sign in to comment.