aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2023-05-17 17:02:59 -0700
committerJohn MacFarlane <[email protected]>2023-05-17 17:02:59 -0700
commit903d11b537de938434b92a38f8d9b2f8c623a49b (patch)
treebc3bf35b601fe061987bc08096accaff5aed9aa7
parentbb412768d823463855fb2a9d5f2d6d4a18d23da1 (diff)
HTML reader: fix iframe with data URI of an image.
Closes #8856. In this case we don't want to try to parse the data at the URL. Instead, create an image inside a div.
-rw-r--r--src/Text/Pandoc/Readers/HTML.hs17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs
index eff642d2e..3ef95e020 100644
--- a/src/Text/Pandoc/Readers/HTML.hs
+++ b/src/Text/Pandoc/Readers/HTML.hs
@@ -476,11 +476,18 @@ pIframe = try $ do
if T.null url
then ignore $ renderTags' [tag, TagClose "iframe"]
else catchError
- (do (bs, _) <- openURL url
- let inp = UTF8.toText bs
- opts <- readerOpts <$> getState
- Pandoc _ contents <- readHtml opts inp
- return $ B.divWith ("",["iframe"],[]) $ B.fromList contents)
+ (do (bs, mbMime) <- openURL url
+ case mbMime of
+ Just mt
+ | "text/html" `T.isPrefixOf` mt -> do
+ let inp = UTF8.toText bs
+ opts <- readerOpts <$> getState
+ Pandoc _ contents <- readHtml opts inp
+ return $ B.divWith ("",["iframe"],[]) $ B.fromList contents
+ | "image/" `T.isPrefixOf` mt -> do
+ return $ B.divWith ("",["iframe"],[]) $
+ B.plain $ B.image url "" mempty
+ _ -> return $ B.divWith ("",["iframe"],[("src", url)]) $ mempty)
(\e -> do
logMessage $ CouldNotFetchResource url (renderError e)
ignore $ renderTags' [tag, TagClose "iframe"])