HTML writer: Don't add data- prefix to RDFa attributes.

Closes #5403.
This commit is contained in:
John MacFarlane 2019-03-28 20:59:43 -07:00
parent 40865958ce
commit 1595860059

View file

@ -603,7 +603,7 @@ toAttrs kvs = do
return $ mapMaybe (\(x,y) -> return $ mapMaybe (\(x,y) ->
if html5 if html5
then then
if x `Set.member` html5Attributes if x `Set.member` (html5Attributes <> rdfaAttributes)
|| ':' `elem` x -- e.g. epub: namespace || ':' `elem` x -- e.g. epub: namespace
|| "data-" `isPrefixOf` x || "data-" `isPrefixOf` x
then Just $ customAttribute (fromString x) (toValue y) then Just $ customAttribute (fromString x) (toValue y)
@ -611,7 +611,7 @@ toAttrs kvs = do
(toValue y) (toValue y)
else else
if mbEpubVersion == Just EPUB2 && if mbEpubVersion == Just EPUB2 &&
not (x `Set.member` html4Attributes || not (x `Set.member` (html4Attributes <> rdfaAttributes) ||
"xml:" `isPrefixOf` x) "xml:" `isPrefixOf` x)
then Nothing then Nothing
else Just $ customAttribute (fromString x) (toValue y)) else Just $ customAttribute (fromString x) (toValue y))
@ -1471,6 +1471,23 @@ html5Attributes = Set.fromList
, "wrap" , "wrap"
] ]
-- See https://en.wikipedia.org/wiki/RDFa, https://www.w3.org/TR/rdfa-primer/
rdfaAttributes :: Set.Set String
rdfaAttributes = Set.fromList
[ "about"
, "rel"
, "rev"
, "src"
, "href"
, "resource"
, "property"
, "content"
, "datatype"
, "typeof"
, "vocab"
, "prefix"
]
html4Attributes :: Set.Set String html4Attributes :: Set.Set String
html4Attributes = Set.fromList html4Attributes = Set.fromList
[ "abbr" [ "abbr"