git.iko.soy/typeable/pandoc
on master help sign in
HTML reader: small efficiency improvements.
321343bJohn MacFarlane
src/Text/Pandoc/Readers/HTML.hs+18−25
@@ -19,7 +19,6 @@ module Text.Pandoc.Readers.HTML ( readHtml
19 , htmlInBalanced
19 , htmlInBalanced
20 , isInlineTag
20 , isInlineTag
21 , isBlockTag
21 , isBlockTag
22− , NamedTag(..)
23 , isTextTag
22 , isTextTag
24 , isCommentTag
23 , isCommentTag
25 ) where
24 ) where
@@ -579,9 +578,9 @@ tagToText (TagOpen "br" _) = "\n"
579tagToText _ = ""
578tagToText _ = ""
580
579
581inline :: PandocMonad m => TagParser m Inlines
580inline :: PandocMonad m => TagParser m Inlines
582−inline = do
581+inline = pTagText <|> do
582+ tag <- lookAhead (pSatisfy isInlineTag)
583 exts <- getOption readerExtensions
583 exts <- getOption readerExtensions
584− tag <- lookAhead pAny
585 case tag of
584 case tag of
586 TagOpen name attr ->
585 TagOpen name attr ->
587 case name of
586 case name of
@@ -935,27 +934,21 @@ pSpace = many1 (satisfy isSpace) >>= \xs ->
935 then return B.softbreak
934 then return B.softbreak
936 else return B.space
935 else return B.space
937
936
938−class NamedTag a where
939− getTagName :: a -> Maybe Text
937+getTagName :: Tag Text -> Maybe Text
940−
941−instance NamedTag (Tag Text) where
942− getTagName (TagOpen t _) = Just t
938+getTagName (TagOpen t _) = Just t
943− getTagName (TagClose t) = Just t
939+getTagName (TagClose t) = Just t
944− getTagName _ = Nothing
940+getTagName _ = Nothing
945
941
946−instance NamedTag (Tag String) where
947− getTagName (TagOpen t _) = Just (T.pack t)
948− getTagName (TagClose t) = Just (T.pack t)
949− getTagName _ = Nothing
950−
951−isInlineTag :: NamedTag (Tag a) => Tag a -> Bool
942+isInlineTag :: Tag Text -> Bool
952isInlineTag t =
943isInlineTag t =
944+ isCommentTag t ||
953− isCommentTag t || case getTagName t of
945+ case getTagName t of
954− Nothing -> False
946+ Nothing -> False
947+ Just "script" -> "math/tex" `T.isPrefixOf` fromAttrib "type" t
955− Just x -> x `Set.notMember` blockTags ||
948+ Just x -> x `Set.notMember` blockTags ||
956− T.take 1 x == "?" -- processing instr.
949+ T.take 1 x == "?" -- processing instr.
957−
950+
958−isBlockTag :: NamedTag (Tag a) => Tag a -> Bool
951+isBlockTag :: Tag Text -> Bool
959isBlockTag t = isBlockTagName || isTagComment t
952isBlockTag t = isBlockTagName || isTagComment t
960 where isBlockTagName =
953 where isBlockTagName =
961 case getTagName t of
954 case getTagName t of
@@ -966,10 +959,10 @@ isBlockTag t = isBlockTagName || isTagComment t
966 || x `Set.member` eitherBlockOrInline
959 || x `Set.member` eitherBlockOrInline
967 Nothing -> False
960 Nothing -> False
968
961
969−isTextTag :: Tag a -> Bool
962+isTextTag :: Tag Text -> Bool
970isTextTag = tagText (const True)
963isTextTag = tagText (const True)
971
964
972−isCommentTag :: Tag a -> Bool
965+isCommentTag :: Tag Text -> Bool
973isCommentTag = tagComment (const True)
966isCommentTag = tagComment (const True)
974
967
975--- parsers for use in markdown, textile readers
968--- parsers for use in markdown, textile readers
@@ -1018,7 +1011,7 @@ htmlInBalanced' tagname ts = fromMaybe [] $ go 0 ts
1018 go n (t:ts') = (t :) <$> go n ts'
1011 go n (t:ts') = (t :) <$> go n ts'
1019 go _ [] = mzero
1012 go _ [] = mzero
1020
1013
1021−hasTagWarning :: [Tag a] -> Bool
1014+hasTagWarning :: [Tag Text] -> Bool
1022hasTagWarning (TagWarning _:_) = True
1015hasTagWarning (TagWarning _:_) = True
1023hasTagWarning _ = False
1016hasTagWarning _ = False
1024
1017