diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2018-09-27 09:19:32 -0700 | 
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2018-09-27 09:47:22 -0700 | 
| commit | 99aae5d7cd4170b0d7c7d9cd635b3d138bffd85f (patch) | |
| tree | 97156f21579aae00d5a653fac213671613571e89 /src/Text/Pandoc/Writers | |
| parent | 13f8f3c1a8b4a8b01a7ba71a7e42afa6615e537b (diff) | |
| download | pandoc-99aae5d7cd4170b0d7c7d9cd635b3d138bffd85f.tar.gz | |
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.
Diffstat (limited to 'src/Text/Pandoc/Writers')
| -rw-r--r-- | src/Text/Pandoc/Writers/HTML.hs | 148 | 
1 files changed, 140 insertions, 8 deletions
| diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 851b48956..272454290 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -50,7 +50,7 @@ import Prelude  import Control.Monad.State.Strict  import Data.Char (ord, toLower)  import Data.List (intercalate, intersperse, isPrefixOf, partition) -import Data.Maybe (catMaybes, fromMaybe, isJust, isNothing) +import Data.Maybe (catMaybes, fromMaybe, isJust, isNothing, mapMaybe)  import qualified Data.Set as Set  import Data.String (fromString)  import Data.Text (Text) @@ -577,13 +577,23 @@ toAttrs :: PandocMonad m          => [(String, String)] -> StateT WriterState m [Attribute]  toAttrs kvs = do    html5 <- gets stHtml5 -  return $ map (\(x,y) -> -     customAttribute -        (fromString (if not html5 || x `Set.member` html5Attributes -                                  || "epub:" `isPrefixOf` x -                                  || "data-" `isPrefixOf` x -                        then x -                        else "data-" ++ x)) (toValue y)) kvs +  mbEpubVersion <- gets stEPUBVersion +  return $ mapMaybe (\(x,y) -> +            if html5 +               then +                  if x `Set.member` html5Attributes +                     || ':' `elem` x -- e.g. epub: namespace +                     || "data-" `isPrefixOf` x +                     then Just $ customAttribute (fromString x) (toValue y) +                     else Just $ customAttribute (fromString ("data-" ++ x)) +                                  (toValue y) +               else +                 if mbEpubVersion == Just EPUB2 && +                    not (x `Set.member` html4Attributes || +                         "xml:" `isPrefixOf` x) +                    then Nothing +                    else Just $ customAttribute (fromString x) (toValue y)) +            kvs  attrsToHtml :: PandocMonad m              => WriterOptions -> Attr -> StateT WriterState m [Attribute] @@ -1419,3 +1429,125 @@ html5Attributes = Set.fromList    , "workertype"    , "wrap"    ] + +html4Attributes :: Set.Set String +html4Attributes = Set.fromList +  [ "abbr" +  , "accept" +  , "accept-charset" +  , "accesskey" +  , "action" +  , "align" +  , "alink" +  , "alt" +  , "archive" +  , "axis" +  , "background" +  , "bgcolor" +  , "border" +  , "cellpadding" +  , "cellspacing" +  , "char" +  , "charoff" +  , "charset" +  , "checked" +  , "cite" +  , "class" +  , "classid" +  , "clear" +  , "code" +  , "codebase" +  , "codetype" +  , "color" +  , "cols" +  , "colspan" +  , "compact" +  , "content" +  , "coords" +  , "data" +  , "datetime" +  , "declare" +  , "defer" +  , "dir" +  , "disabled" +  , "enctype" +  , "face" +  , "for" +  , "frame" +  , "frameborder" +  , "headers" +  , "height" +  , "href" +  , "hreflang" +  , "hspace" +  , "http-equiv" +  , "id" +  , "ismap" +  , "label" +  , "lang" +  , "language" +  , "link" +  , "longdesc" +  , "marginheight" +  , "marginwidth" +  , "maxlength" +  , "media" +  , "method" +  , "multiple" +  , "name" +  , "nohref" +  , "noresize" +  , "noshade" +  , "nowrap" +  , "object" +  , "onblur" +  , "onchange" +  , "onclick" +  , "ondblclick" +  , "onfocus" +  , "onkeydown" +  , "onkeypress" +  , "onkeyup" +  , "onload" +  , "onmousedown" +  , "onmousemove" +  , "onmouseout" +  , "onmouseover" +  , "onmouseup" +  , "onreset" +  , "onselect" +  , "onsubmit" +  , "onunload" +  , "profile" +  , "prompt" +  , "readonly" +  , "rel" +  , "rev" +  , "rows" +  , "rowspan" +  , "rules" +  , "scheme" +  , "scope" +  , "scrolling" +  , "selected" +  , "shape" +  , "size" +  , "span" +  , "src" +  , "standby" +  , "start" +  , "style" +  , "summary" +  , "tabindex" +  , "target" +  , "text" +  , "title" +  , "usemap" +  , "valign" +  , "value" +  , "valuetype" +  , "version" +  , "vlink" +  , "vspace" +  , "width" +  ] | 
