mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-26 18:26:36 +00:00
Recognize data-external when reading HTML img tags (#7429)
Preserve all attributes in img tags. If attributes have a `data-` prefix, it will be stripped. In particular, this preserves a `data-external` attribute as an `external` attribute in the pandoc AST.
This commit is contained in:
@@ -722,17 +722,12 @@ pLink = try $ do
|
||||
|
||||
pImage :: PandocMonad m => TagParser m Inlines
|
||||
pImage = do
|
||||
tag <- pSelfClosing (=="img") (isJust . lookup "src")
|
||||
tag@(TagOpen _ attr') <- pSelfClosing (=="img") (isJust . lookup "src")
|
||||
url <- canonicalizeUrl $ fromAttrib "src" tag
|
||||
let title = fromAttrib "title" tag
|
||||
let alt = fromAttrib "alt" tag
|
||||
let uid = fromAttrib "id" tag
|
||||
let cls = T.words $ fromAttrib "class" tag
|
||||
let getAtt k = case fromAttrib k tag of
|
||||
"" -> []
|
||||
v -> [(k, v)]
|
||||
let kvs = concatMap getAtt ["width", "height", "sizes", "srcset"]
|
||||
return $ B.imageWith (uid, cls, kvs) (escapeURI url) title (B.text alt)
|
||||
let attr = toAttr $ filter (\(k,_) -> k /= "alt" && k /= "title" && k /= "src") attr'
|
||||
return $ B.imageWith attr (escapeURI url) title (B.text alt)
|
||||
|
||||
pSvg :: PandocMonad m => TagParser m Inlines
|
||||
pSvg = do
|
||||
|
||||
@@ -74,6 +74,12 @@ tests = [ testGroup "base tag"
|
||||
[ test html "anchor without href" $ "<a name=\"anchor\"/>" =?>
|
||||
plain (spanWith ("anchor",[],[]) mempty)
|
||||
]
|
||||
, testGroup "img"
|
||||
[ test html "data-external attribute" $ "<img data-external=\"1\" src=\"http://example.com/stickman.gif\">" =?>
|
||||
plain (imageWith ("", [], [("external", "1")]) "http://example.com/stickman.gif" "" "")
|
||||
, test html "title" $ "<img title=\"The title\" src=\"http://example.com/stickman.gif\">" =?>
|
||||
plain (imageWith ("", [], []) "http://example.com/stickman.gif" "The title" "")
|
||||
]
|
||||
, testGroup "lang"
|
||||
[ test html "lang on <html>" $ "<html lang=\"es\">hola" =?>
|
||||
setMeta "lang" (text "es") (doc (plain (text "hola")))
|
||||
|
||||
Reference in New Issue
Block a user