packages feed

tagsoup 0.13.10 → 0.14

raw patch · 6 files changed

+22/−87 lines, 6 filesdep −network

Dependencies removed: network

Files

CHANGES.txt view
@@ -1,5 +1,7 @@ Changelog for TagSoup +0.14+    #14, eliminate Text.HTML.Download 0.13.10     #51, improve the Haddock documentation     #52, fix some > 16bit HTML entities
− Text/HTML/Download.hs
@@ -1,76 +0,0 @@-{-|-    /DEPRECATED/: Use the HTTP package instead:--    > import Network.HTTP-    > openURL x = getResponseBody =<< simpleHTTP (getRequest x)--    This module simply downloads a page off the internet. It is very restricted,-    and it not intended for proper use.-    -    The original version was by Alistair Bayley, with additional help from-    Daniel McAllansmith. It is taken from the Haskell-Cafe mailing list-    \"Simple HTTP lib for Windows?\", 18 Jan 2007.-    <http://thread.gmane.org/gmane.comp.lang.haskell.cafe/18443/>--}--module Text.HTML.Download(openURL, openItem) where--import System.IO-import System.IO.Unsafe-import Network-import Data.List (isPrefixOf)--{-# DEPRECATED openItem, openURL "Use package HTTP, module Network.HTTP, getResponseBody =<< simpleHTTP (getRequest url)" #-}----- | This function opens a URL on the internet.---   Any @http:\/\/@ prefix is ignored.------ > openURL "www.haskell.org/haskellwiki/Haskell"------ Known Limitations:------ * Only HTTP on port 80------ * Outputs the HTTP Headers as well------ * Does not work with all servers------ It is hoped that a more reliable version of this function will be--- placed in a new HTTP library at some point!-openURL :: String -> IO String-openURL url | "http://" `isPrefixOf` url = openURL (drop 7 url)-openURL url = client server 80 (if null path then "/" else path)-    where (server,path) = break (== '/') url---client :: [Char] -> PortNumber -> [Char] -> IO String-client server port page = withSocketsDo $ do-    hndl <- connectTo server (PortNumber port)-    let out x = hPutStrLn hndl (x ++ "\r")-    hSetBuffering hndl NoBuffering--    out $ "GET " ++ page ++ " HTTP/1.1"-    out $ "Host: " ++ server ++ ""-    out $ "Connection: close"-    out ""-    out ""-    readResponse hndl---readResponse :: Handle -> IO String-readResponse hndl = do-    closed <- hIsClosed hndl-    eof <- hIsEOF hndl-    if closed || eof-        then return []-        else do-            c <- hGetChar hndl-            cs <- unsafeInterleaveIO $ readResponse hndl-            return (c:cs)----- | Open a URL (if it starts with @http:\/\/@) or a file otherwise-openItem :: String -> IO String-openItem x | "http://" `isPrefixOf` x = openURL x-           | otherwise = readFile x
Text/HTML/TagSoup.hs view
@@ -62,6 +62,7 @@  -- | Define a class to allow String's or Tag str's to be used as matches class TagRep a where+    -- | Convert a value into a 'Tag'.     toTagRep :: StringLike str => a -> Tag str  instance StringLike str => TagRep (Tag str) where toTagRep = fmap castString
Text/HTML/TagSoup/Match.hs view
@@ -163,27 +163,34 @@  -- * Matching attributes +-- | Does any attribute name/value match the predicate. anyAttr :: ((str,str) -> Bool) -> [Attribute str] -> Bool anyAttr = any +-- | Does any attribute name match the predicate. anyAttrName :: (str -> Bool) -> [Attribute str] -> Bool anyAttrName p = any (p . fst) +-- | Does any attribute value match the predicate. anyAttrValue :: (str -> Bool) -> [Attribute str] -> Bool anyAttrValue p = any (p . snd)  +-- | Does any attribute name/value match. anyAttrLit :: Eq str => (str,str) -> [Attribute str] -> Bool anyAttrLit attr = anyAttr (attr==) +-- | Does any attribute name match. anyAttrNameLit :: Eq str => str -> [Attribute str] -> Bool anyAttrNameLit name = anyAttrName (name==) +-- | Does any attribute value match. anyAttrValueLit :: Eq str => str -> [Attribute str] -> Bool anyAttrValueLit value = anyAttrValue (value==)   +-- | Get the tags under tags with a given name where the attributes match some predicate. getTagContent :: Eq str => str -> ([Attribute str] -> Bool) -> [Tag str] -> [Tag str] getTagContent name pAttrs =    takeWhile (not . tagCloseLit name) . drop 1 .
Text/HTML/TagSoup/Tree.hs view
@@ -17,8 +17,12 @@ import GHC.Exts (build)  -data TagTree str = TagBranch str [Attribute str] [TagTree str]-                 | TagLeaf (Tag str)+-- | A tree of 'Tag' values.+data TagTree str+    = -- | A 'TagOpen'/'TagClose' pair with the 'Tag' values in between.+      TagBranch str [Attribute str] [TagTree str]+    | -- | Any leaf node+      TagLeaf (Tag str)                    deriving (Eq,Ord,Show)  instance Functor TagTree where@@ -51,12 +55,15 @@             where (a,b) = f xs         f [] = ([], []) +-- | Build a 'TagTree' from a string. parseTree :: StringLike str => str -> [TagTree str] parseTree = tagTree . parseTags +-- | Build a 'TagTree' from a string, specifying the 'ParseOptions'. parseTreeOptions :: StringLike str => ParseOptions str -> str -> [TagTree str] parseTreeOptions opts str = tagTree $ parseTagsOptions opts str +-- | Flatten a 'TagTree' back to a list of 'Tag'. flattenTree :: [TagTree str] -> [Tag str] flattenTree xs = build $ flattenTreeFB xs @@ -68,9 +75,11 @@             TagOpen name atts `cons` flattenTreeOnto inner (TagClose name `cons` flattenTreeOnto trs tags)         flattenTreeOnto (TagLeaf x:trs) tags = x `cons` flattenTreeOnto trs tags +-- | Render a 'TagTree'. renderTree :: StringLike str => [TagTree str] -> str renderTree = renderTags . flattenTree +-- | Render a 'TagTree' with some 'RenderOptions'. renderTreeOptions :: StringLike str => RenderOptions str -> [TagTree str] -> str renderTreeOptions opts trees = renderTagsOptions opts $ flattenTree trees 
tagsoup.cabal view
@@ -1,6 +1,6 @@ cabal-version:  >= 1.6 name:           tagsoup-version:        0.13.10+version:        0.14 copyright:      Neil Mitchell 2006-2016 author:         Neil Mitchell <ndmitchell@gmail.com> maintainer:     Neil Mitchell <ndmitchell@gmail.com>@@ -31,16 +31,8 @@     default: False     description: Build the test program -flag download-    default: False-    description: Build with Download module- library     build-depends: base == 4.*, containers, bytestring, text--    if flag(download)-        build-depends: network-        exposed-modules: Text.HTML.Download      exposed-modules:         Text.HTML.TagSoup