git.iko.soy/typeable/pandoc
on master help sign in
HTML reader: Use sets instead of lists for block tag lookup.
eb6fb62John MacFarlane
src/Text/Pandoc/Readers/HTML.hs+43−50
@@ -869,62 +869,54 @@ pSpace = many1 (satisfy isSpace) >>= \xs ->
869-- Constants
869-- Constants
870--
870--
871
871
872−eitherBlockOrInline :: [String]
872+eitherBlockOrInline :: Set.Set String
873+eitherBlockOrInline = Set.fromList
873−eitherBlockOrInline = ["audio", "applet", "button", "iframe", "embed",
874+ ["audio", "applet", "button", "iframe", "embed",
874− "del", "ins",
875− "progress", "map", "area", "noscript", "script",
875+ "del", "ins", "progress", "map", "area", "noscript", "script",
876− "object", "svg", "video", "source"]
876+ "object", "svg", "video", "source"]
877−
877+
878−{-
879−inlineHtmlTags :: [[Char]]
880−inlineHtmlTags = ["a", "abbr", "acronym", "b", "basefont", "bdo", "big",
881− "br", "cite", "code", "dfn", "em", "font", "i", "img",
882− "input", "kbd", "label", "q", "s", "samp", "select",
883− "small", "span", "strike", "strong", "sub", "sup",
884− "textarea", "tt", "u", "var"]
885−-}
886−
887−blockHtmlTags :: [String]
878+blockHtmlTags :: Set.Set String
879+blockHtmlTags = Set.fromList
888−blockHtmlTags = ["?xml", "!DOCTYPE", "address", "article", "aside",
880+ ["?xml", "!DOCTYPE", "address", "article", "aside",
889− "blockquote", "body", "canvas",
881+ "blockquote", "body", "canvas",
890− "caption", "center", "col", "colgroup", "dd", "details",
882+ "caption", "center", "col", "colgroup", "dd", "details",
891− "dir", "div",
892− "dl", "dt", "fieldset", "figcaption", "figure",
883+ "dir", "div", "dl", "dt", "fieldset", "figcaption", "figure",
893− "footer", "form", "h1", "h2", "h3", "h4",
884+ "footer", "form", "h1", "h2", "h3", "h4",
894− "h5", "h6", "head", "header", "hgroup", "hr", "html",
885+ "h5", "h6", "head", "header", "hgroup", "hr", "html",
895− "isindex", "menu", "noframes", "ol", "output", "p", "pre",
886+ "isindex", "menu", "noframes", "ol", "output", "p", "pre",
896− "section", "table", "tbody", "textarea",
887+ "section", "table", "tbody", "textarea",
897− "thead", "tfoot", "ul", "dd",
888+ "thead", "tfoot", "ul", "dd",
898− "dt", "frameset", "li", "tbody", "td", "tfoot",
889+ "dt", "frameset", "li", "tbody", "td", "tfoot",
899− "th", "thead", "tr", "script", "style"]
890+ "th", "thead", "tr", "script", "style"]
900
891
901-- We want to allow raw docbook in markdown documents, so we
892-- We want to allow raw docbook in markdown documents, so we
902-- include docbook block tags here too.
893-- include docbook block tags here too.
903−blockDocBookTags :: [String]
894+blockDocBookTags :: Set.Set String
895+blockDocBookTags = Set.fromList
904−blockDocBookTags = ["calloutlist", "bibliolist", "glosslist", "itemizedlist",
896+ ["calloutlist", "bibliolist", "glosslist", "itemizedlist",
905− "orderedlist", "segmentedlist", "simplelist",
897+ "orderedlist", "segmentedlist", "simplelist",
906− "variablelist", "caution", "important", "note", "tip",
898+ "variablelist", "caution", "important", "note", "tip",
907− "warning", "address", "literallayout", "programlisting",
899+ "warning", "address", "literallayout", "programlisting",
908− "programlistingco", "screen", "screenco", "screenshot",
900+ "programlistingco", "screen", "screenco", "screenshot",
909− "synopsis", "example", "informalexample", "figure",
901+ "synopsis", "example", "informalexample", "figure",
910− "informalfigure", "table", "informaltable", "para",
902+ "informalfigure", "table", "informaltable", "para",
911− "simpara", "formalpara", "equation", "informalequation",
903+ "simpara", "formalpara", "equation", "informalequation",
912− "figure", "screenshot", "mediaobject", "qandaset",
904+ "figure", "screenshot", "mediaobject", "qandaset",
913− "procedure", "task", "cmdsynopsis", "funcsynopsis",
905+ "procedure", "task", "cmdsynopsis", "funcsynopsis",
914− "classsynopsis", "blockquote", "epigraph", "msgset",
906+ "classsynopsis", "blockquote", "epigraph", "msgset",
915− "sidebar", "title"]
907+ "sidebar", "title"]
916−
908+
917−epubTags :: [String]
909+epubTags :: Set.Set String
918−epubTags = ["case", "switch", "default"]
910+epubTags = Set.fromList ["case", "switch", "default"]
919−
911+
920−blockTags :: [String]
912+blockTags :: Set.Set String
921−blockTags = blockHtmlTags ++ blockDocBookTags ++ epubTags
913+blockTags = Set.unions [blockHtmlTags, blockDocBookTags, epubTags]
922
914
923isInlineTag :: Tag String -> Bool
915isInlineTag :: Tag String -> Bool
924isInlineTag t = tagOpen isInlineTagName (const True) t ||
916isInlineTag t = tagOpen isInlineTagName (const True) t ||
925 tagClose isInlineTagName t ||
917 tagClose isInlineTagName t ||
926 tagComment (const True) t
918 tagComment (const True) t
927− where isInlineTagName x = x `notElem` blockTags
919+ where isInlineTagName x = x `Set.notMember` blockTags
928
920
929isBlockTag :: Tag String -> Bool
921isBlockTag :: Tag String -> Bool
930isBlockTag t = tagOpen isBlockTagName (const True) t ||
922isBlockTag t = tagOpen isBlockTagName (const True) t ||
@@ -976,8 +968,9 @@ t `closes` t2 |
976 t `elem` ["h1","h2","h3","h4","h5","h6","dl","ol","ul","table","div","p"] &&
968 t `elem` ["h1","h2","h3","h4","h5","h6","dl","ol","ul","table","div","p"] &&
977 t2 `elem` ["h1","h2","h3","h4","h5","h6","p" ] = True -- not "div"
969 t2 `elem` ["h1","h2","h3","h4","h5","h6","p" ] = True -- not "div"
978t1 `closes` t2 |
970t1 `closes` t2 |
979− t1 `elem` blockTags &&
971+ t1 `Set.member` blockTags &&
972+ t2 `Set.notMember` blockTags &&
980− t2 `notElem` (blockTags ++ eitherBlockOrInline) = True
973+ t2 `Set.notMember` eitherBlockOrInline = True
981_ `closes` _ = False
974_ `closes` _ = False
982
975
983--- parsers for use in markdown, textile readers
976--- parsers for use in markdown, textile readers