git.iko.soy/typeable/pandoc
on master help sign in
HTML writer: omit unknown attributes in EPUB2 output.

This allows users to include `epub:type` attributes, which will be passed through to epub3 but not epub2.

commit99aae5d7cd4170b0d7c7d9cd635b3d138bffd85f authorJohn MacFarlane <jgm@berkeley.edu> dateThu 27 Sep 2018, 09:19 (8 years ago) parent13f8f3c
1 file changed+140−8
src/Text/Pandoc/Writers/HTML.hs+140−8
src/Text/Pandoc/Writers/HTML.hs+140−8
@@ -50,7 +50,7 @@ import Prelude
5050import Control.Monad.State.Strict
5151import Data.Char (ord, toLower)
5252import Data.List (intercalate, intersperse, isPrefixOf, partition)
53−import Data.Maybe (catMaybes, fromMaybe, isJust, isNothing)
53+import Data.Maybe (catMaybes, fromMaybe, isJust, isNothing, mapMaybe)
5454import qualified Data.Set as Set
5555import Data.String (fromString)
5656import Data.Text (Text)
@@ -577,13 +577,23 @@ toAttrs :: PandocMonad m
577577 => [(String, String)] -> StateT WriterState m [Attribute]
578578toAttrs kvs = do
579579 html5 <- gets stHtml5
580− return $ map (\(x,y) ->
581− customAttribute
582− (fromString (if not html5 || x `Set.member` html5Attributes
583− || "epub:" `isPrefixOf` x
584− || "data-" `isPrefixOf` x
585− then x
586− else "data-" ++ x)) (toValue y)) kvs
580+ mbEpubVersion <- gets stEPUBVersion
581+ return $ mapMaybe (\(x,y) ->
582+ if html5
583+ then
584+ if x `Set.member` html5Attributes
585+ || ':' `elem` x -- e.g. epub: namespace
586+ || "data-" `isPrefixOf` x
587+ then Just $ customAttribute (fromString x) (toValue y)
588+ else Just $ customAttribute (fromString ("data-" ++ x))
589+ (toValue y)
590+ else
591+ if mbEpubVersion == Just EPUB2 &&
592+ not (x `Set.member` html4Attributes ||
593+ "xml:" `isPrefixOf` x)
594+ then Nothing
595+ else Just $ customAttribute (fromString x) (toValue y))
596+ kvs
587597
588598attrsToHtml :: PandocMonad m
589599 => WriterOptions -> Attr -> StateT WriterState m [Attribute]
@@ -1419,3 +1429,125 @@ html5Attributes = Set.fromList
14191429 , "workertype"
14201430 , "wrap"
14211431 ]
1432+
1433+html4Attributes :: Set.Set String
1434+html4Attributes = Set.fromList
1435+ [ "abbr"
1436+ , "accept"
1437+ , "accept-charset"
1438+ , "accesskey"
1439+ , "action"
1440+ , "align"
1441+ , "alink"
1442+ , "alt"
1443+ , "archive"
1444+ , "axis"
1445+ , "background"
1446+ , "bgcolor"
1447+ , "border"
1448+ , "cellpadding"
1449+ , "cellspacing"
1450+ , "char"
1451+ , "charoff"
1452+ , "charset"
1453+ , "checked"
1454+ , "cite"
1455+ , "class"
1456+ , "classid"
1457+ , "clear"
1458+ , "code"
1459+ , "codebase"
1460+ , "codetype"
1461+ , "color"
1462+ , "cols"
1463+ , "colspan"
1464+ , "compact"
1465+ , "content"
1466+ , "coords"
1467+ , "data"
1468+ , "datetime"
1469+ , "declare"
1470+ , "defer"
1471+ , "dir"
1472+ , "disabled"
1473+ , "enctype"
1474+ , "face"
1475+ , "for"
1476+ , "frame"
1477+ , "frameborder"
1478+ , "headers"
1479+ , "height"
1480+ , "href"
1481+ , "hreflang"
1482+ , "hspace"
1483+ , "http-equiv"
1484+ , "id"
1485+ , "ismap"
1486+ , "label"
1487+ , "lang"
1488+ , "language"
1489+ , "link"
1490+ , "longdesc"
1491+ , "marginheight"
1492+ , "marginwidth"
1493+ , "maxlength"
1494+ , "media"
1495+ , "method"
1496+ , "multiple"
1497+ , "name"
1498+ , "nohref"
1499+ , "noresize"
1500+ , "noshade"
1501+ , "nowrap"
1502+ , "object"
1503+ , "onblur"
1504+ , "onchange"
1505+ , "onclick"
1506+ , "ondblclick"
1507+ , "onfocus"
1508+ , "onkeydown"
1509+ , "onkeypress"
1510+ , "onkeyup"
1511+ , "onload"
1512+ , "onmousedown"
1513+ , "onmousemove"
1514+ , "onmouseout"
1515+ , "onmouseover"
1516+ , "onmouseup"
1517+ , "onreset"
1518+ , "onselect"
1519+ , "onsubmit"
1520+ , "onunload"
1521+ , "profile"
1522+ , "prompt"
1523+ , "readonly"
1524+ , "rel"
1525+ , "rev"
1526+ , "rows"
1527+ , "rowspan"
1528+ , "rules"
1529+ , "scheme"
1530+ , "scope"
1531+ , "scrolling"
1532+ , "selected"
1533+ , "shape"
1534+ , "size"
1535+ , "span"
1536+ , "src"
1537+ , "standby"
1538+ , "start"
1539+ , "style"
1540+ , "summary"
1541+ , "tabindex"
1542+ , "target"
1543+ , "text"
1544+ , "title"
1545+ , "usemap"
1546+ , "valign"
1547+ , "value"
1548+ , "valuetype"
1549+ , "version"
1550+ , "vlink"
1551+ , "vspace"
1552+ , "width"
1553+ ]