git.iko.soy/typeable/pandoc
on master help sign in
HTML reader: read `data-foo` attribute into `foo`.

The HTML writer adds the `data-` prefix for HTML5 for nonstandard attributes. But the attributes are represented in the AST without the `data-` prefix, so we should strip this when reading HTML. Closes #5392.

commit052684712b8a36854c622468f5d4ddd367199c1c authorJohn MacFarlane <jgm@berkeley.edu> dateMon 25 Mar 2019, 08:43 (8 years ago) parente91af0a
2 files changed+3−2
src/Text/Pandoc/Readers/HTML.hs+2−1 test/Tests/Readers/HTML.hs+1−1
src/Text/Pandoc/Readers/HTML.hs+2−1
@@ -807,7 +807,8 @@ mathMLToTeXMath s = writeTeX <$> readMathML s
807807
808808toStringAttr :: [(Text, Text)] -> [(String, String)]
809809toStringAttr = map go
810− where go (x,y) = (T.unpack x, T.unpack y)
810+ where go (x,y) = (T.unpack (fromMaybe x $ T.stripPrefix "data-" x),
811+ T.unpack y)
811812
812813pScriptMath :: PandocMonad m => TagParser m Inlines
813814pScriptMath = try $ do
test/Tests/Readers/HTML.hs+1−1
@@ -83,7 +83,7 @@ tests = [ testGroup "base tag"
8383 , test htmlNativeDivs "<main role=X> becomes <div role=X>" $ "<main role=foobar>hello</main>" =?>
8484 doc (divWith ("", [], [("role", "foobar")]) (plain (text "hello")))
8585 , test htmlNativeDivs "<main> has attributes preserved" $ "<main id=foo class=bar data-baz=qux>hello</main>" =?>
86− doc (divWith ("foo", ["bar"], [("role", "main"), ("data-baz", "qux")]) (plain (text "hello")))
86+ doc (divWith ("foo", ["bar"], [("role", "main"), ("baz", "qux")]) (plain (text "hello")))
8787 , test htmlNativeDivs "<main> closes <p>" $ "<p>hello<main>main content</main>" =?>
8888 doc (para (text "hello") <> divWith ("", [], [("role", "main")]) (plain (text "main content")))
8989 , test htmlNativeDivs "<main> followed by text" $ "<main>main content</main>non-main content" =?>