git.iko.soy/typeable/pandoc
on master help sign in
HTML reader: small efficiency improvements.

Also, remove exported class NamedTag(..) [API change]. This was just intended to smooth over the transition from String to Text and is no longer needed. The functions isInlineTag and isBlockTag are no longer polymorphic.

commit321343b2cf8a4a75abe1b6713aa40e278ca57997 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 20 Feb 2021, 22:49 (6 years ago) parentcec541e
1 file changed+18−25
src/Text/Pandoc/Readers/HTML.hs+18−25
src/Text/Pandoc/Readers/HTML.hs+18−25
@@ -19,7 +19,6 @@ module Text.Pandoc.Readers.HTML ( readHtml
1919 , htmlInBalanced
2020 , isInlineTag
2121 , isBlockTag
22− , NamedTag(..)
2322 , isTextTag
2423 , isCommentTag
2524 ) where
@@ -579,9 +578,9 @@ tagToText (TagOpen "br" _) = "\n"
579578tagToText _ = ""
580579
581580inline :: PandocMonad m => TagParser m Inlines
582−inline = do
581+inline = pTagText <|> do
582+ tag <- lookAhead (pSatisfy isInlineTag)
583583 exts <- getOption readerExtensions
584− tag <- lookAhead pAny
585584 case tag of
586585 TagOpen name attr ->
587586 case name of
@@ -935,27 +934,21 @@ pSpace = many1 (satisfy isSpace) >>= \xs ->
935934 then return B.softbreak
936935 else return B.space
937936
938−class NamedTag a where
939− getTagName :: a -> Maybe Text
940−
941−instance NamedTag (Tag Text) where
942− getTagName (TagOpen t _) = Just t
943− getTagName (TagClose t) = Just t
944− getTagName _ = Nothing
937+getTagName :: Tag Text -> Maybe Text
938+getTagName (TagOpen t _) = Just t
939+getTagName (TagClose t) = Just t
940+getTagName _ = Nothing
945941
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
952943isInlineTag t =
953− isCommentTag t || case getTagName t of
954− Nothing -> False
955− Just x -> x `Set.notMember` blockTags ||
956− T.take 1 x == "?" -- processing instr.
957−
958−isBlockTag :: NamedTag (Tag a) => Tag a -> Bool
944+ isCommentTag t ||
945+ case getTagName t of
946+ Nothing -> False
947+ Just "script" -> "math/tex" `T.isPrefixOf` fromAttrib "type" t
948+ Just x -> x `Set.notMember` blockTags ||
949+ T.take 1 x == "?" -- processing instr.
950+
951+isBlockTag :: Tag Text -> Bool
959952isBlockTag t = isBlockTagName || isTagComment t
960953 where isBlockTagName =
961954 case getTagName t of
@@ -966,10 +959,10 @@ isBlockTag t = isBlockTagName || isTagComment t
966959 || x `Set.member` eitherBlockOrInline
967960 Nothing -> False
968961
969−isTextTag :: Tag a -> Bool
962+isTextTag :: Tag Text -> Bool
970963isTextTag = tagText (const True)
971964
972−isCommentTag :: Tag a -> Bool
965+isCommentTag :: Tag Text -> Bool
973966isCommentTag = tagComment (const True)
974967
975968--- parsers for use in markdown, textile readers
@@ -1018,7 +1011,7 @@ htmlInBalanced' tagname ts = fromMaybe [] $ go 0 ts
10181011 go n (t:ts') = (t :) <$> go n ts'
10191012 go _ [] = mzero
10201013
1021−hasTagWarning :: [Tag a] -> Bool
1014+hasTagWarning :: [Tag Text] -> Bool
10221015hasTagWarning (TagWarning _:_) = True
10231016hasTagWarning _ = False
10241017