git.iko.soy/typeable/pandoc
on master help sign in
Remove TagSoup compat

We already lower-bound tagsoup at 0.13.7, which means we were always running the compatibility layer (it was conditional on min value 0.13). Better to just use `lookupEntity` from the library directly, and convert a string to a char if need be.

commit3f8d3d844fde31a27643254be69a17128a47d3fe authorJesse Rosenthal <jrosenthal@jhu.edu> dateFri 2 Sep 2016, 11:35 (10 years ago) parentc9a631e
6 files changed+10−26
pandoc.cabal−1 src/Text/Pandoc/Compat/TagSoupEntity.hs−15 src/Text/Pandoc/Parsing.hs+3−3 src/Text/Pandoc/Readers/DocBook.hs+3−3 src/Text/Pandoc/Readers/OPML.hs+2−2 src/Text/Pandoc/XML.hs+2−2
pandoc.cabal−1
@@ -415,7 +415,6 @@ Library
415415 Text.Pandoc.Slides,
416416 Text.Pandoc.Highlighting,
417417 Text.Pandoc.Compat.Time,
418− Text.Pandoc.Compat.TagSoupEntity,
419418 Paths_pandoc
420419
421420 Buildable: True
src/Text/Pandoc/Compat/TagSoupEntity.hsdeleted−15
@@ -1,15 +0,0 @@
1−{-# LANGUAGE CPP #-}
2−module Text.Pandoc.Compat.TagSoupEntity (lookupEntity
3− ) where
4−
5−import qualified Text.HTML.TagSoup.Entity as TE
6−
7−lookupEntity :: String -> Maybe Char
8−#if MIN_VERSION_tagsoup(0,13,0)
9−lookupEntity = str2chr . TE.lookupEntity
10− where str2chr :: Maybe String -> Maybe Char
11− str2chr (Just [c]) = Just c
12− str2chr _ = Nothing
13−#else
14−lookupEntity = TE.lookupEntity
15−#endif
src/Text/Pandoc/Parsing.hs+3−3
@@ -184,7 +184,7 @@ import Text.Pandoc.Shared
184184import qualified Data.Map as M
185185import Text.TeXMath.Readers.TeX.Macros (applyMacros, Macro,
186186 parseMacroDefinitions)
187−import Text.Pandoc.Compat.TagSoupEntity ( lookupEntity )
187+import Text.HTML.TagSoup.Entity ( lookupEntity )
188188import Text.Pandoc.Asciify (toAsciiChar)
189189import Data.Monoid ((<>))
190190import Data.Default
@@ -578,8 +578,8 @@ characterReference = try $ do
578578 '#':_ -> ent
579579 _ -> ent ++ ";"
580580 case lookupEntity ent' of
581− Just c -> return c
582− Nothing -> fail "entity not found"
581+ Just (c : _) -> return c
582+ _ -> fail "entity not found"
583583
584584-- | Parses an uppercase roman numeral and returns (UpperRoman, number).
585585upperRoman :: Stream s m Char => ParserT s st m (ListNumberStyle, Int)
src/Text/Pandoc/Readers/DocBook.hs+3−3
@@ -5,7 +5,7 @@ import Text.Pandoc.Options
55import Text.Pandoc.Definition
66import Text.Pandoc.Builder
77import Text.XML.Light
8−import Text.Pandoc.Compat.TagSoupEntity (lookupEntity)
8+import Text.HTML.TagSoup.Entity (lookupEntity)
99import Data.Either (rights)
1010import Data.Generics
1111import Data.Char (isSpace)
@@ -564,7 +564,7 @@ normalizeTree = everywhere (mkT go)
564564 go xs = xs
565565
566566convertEntity :: String -> String
567−convertEntity e = maybe (map toUpper e) (:[]) (lookupEntity e)
567+convertEntity e = maybe (map toUpper e) id (lookupEntity e)
568568
569569-- convenience function to get an attribute value, defaulting to ""
570570attrValue :: String -> Element -> String
@@ -916,7 +916,7 @@ elementToStr x = x
916916parseInline :: Content -> DB Inlines
917917parseInline (Text (CData _ s _)) = return $ text s
918918parseInline (CRef ref) =
919− return $ maybe (text $ map toUpper ref) (text . (:[])) $ lookupEntity ref
919+ return $ maybe (text $ map toUpper ref) (text) $ lookupEntity ref
920920parseInline (Elem e) =
921921 case qName (elName e) of
922922 "equation" -> equation displayMath
src/Text/Pandoc/Readers/OPML.hs+2−2
@@ -7,7 +7,7 @@ import Text.Pandoc.Builder
77import Text.Pandoc.Readers.HTML (readHtml)
88import Text.Pandoc.Readers.Markdown (readMarkdown)
99import Text.XML.Light
10−import Text.Pandoc.Compat.TagSoupEntity (lookupEntity)
10+import Text.HTML.TagSoup.Entity (lookupEntity)
1111import Data.Generics
1212import Control.Monad.State
1313import Data.Default
@@ -53,7 +53,7 @@ normalizeTree = everywhere (mkT go)
5353 go xs = xs
5454
5555convertEntity :: String -> String
56−convertEntity e = maybe (map toUpper e) (:[]) (lookupEntity e)
56+convertEntity e = maybe (map toUpper e) id (lookupEntity e)
5757
5858-- convenience function to get an attribute value, defaulting to ""
5959attrValue :: String -> Element -> String
src/Text/Pandoc/XML.hs+2−2
@@ -38,7 +38,7 @@ module Text.Pandoc.XML ( escapeCharForXML,
3838
3939import Text.Pandoc.Pretty
4040import Data.Char (ord, isAscii, isSpace)
41−import Text.Pandoc.Compat.TagSoupEntity (lookupEntity)
41+import Text.HTML.TagSoup.Entity (lookupEntity)
4242
4343-- | Escape one character as needed for XML.
4444escapeCharForXML :: Char -> String
@@ -101,7 +101,7 @@ toEntities (c:cs)
101101fromEntities :: String -> String
102102fromEntities ('&':xs) =
103103 case lookupEntity ent' of
104− Just c -> c : fromEntities rest
104+ Just c -> c ++ fromEntities rest
105105 Nothing -> '&' : fromEntities xs
106106 where (ent, rest) = case break (\c -> isSpace c || c == ';') xs of
107107 (zs,';':ys) -> (zs,ys)