tagsoup 0.14.2 → 0.14.3
raw patch · 8 files changed
+107/−42 lines, 8 files
Files
- CHANGES.txt +32/−30
- LICENSE +1/−1
- README.md +11/−1
- src/Text/HTML/TagSoup/Specification.hs +3/−3
- tagsoup.cabal +4/−4
- test/Main.hs +2/−1
- test/TagSoup/Sample.hs +49/−0
- test/TagSoup/Test.hs +5/−2
CHANGES.txt view
@@ -1,86 +1,88 @@ Changelog for TagSoup -0.14.2+0.14.3, released 2018-01-21+ #70, fix up source positions on comments+0.14.2, released 2017-11-30 #66, make sure positions are correct for lone & characters-0.14.1+0.14.1, released 2017-02-25 #63, add maybeAttrib-0.14+0.14, released 2016-06-11 #14, eliminate Text.HTML.Download-0.13.10+0.13.10, released 2016-05-06 #51, improve the Haddock documentation #52, fix some > 16bit HTML entities-0.13.9+0.13.9, released 2016-03-15 #50, fix a space leak #36, fix the demo examples #35, make IsString a superclass of StringLike #33, make flattenTree O(n) instead of O(n^2)-0.13.8+0.13.8, released 2016-01-10 #30, add parse/render functions directly to the Tree module-0.13.7+0.13.7, released 2016-01-09 #32, make sure upper case &#X works in lookupEntity-0.13.6+0.13.6, released 2015-12-23 #28, some named entities require a trailing semicolon (e.g. mid)-0.13.5+0.13.5, released 2015-10-30 #26, rename the test program to test-tagsoup-0.13.4+0.13.4, released 2015-10-26 #24, add isTagComment function Update the copyright year-0.13.3+0.13.3, released 2014-10-01 Work on GHC 7.9-0.13.2+0.13.2, released 2014-08-08 Remove all package upper bounds Allow QuickCheck-2.6-0.13.1+0.13.1, released 2014-01-20 #562, treat <script> specially as per HTML5-0.13+0.13, released 2013-08-06 #616, extend to all HTML5 entities Optimise lookupNamedEntity Replace escapeXMLChar with escapeXML Change all Entity functions to return String, not Int or Char-0.12.7+0.12.7, released 2012-08-19 Allow deepseq-1.3 Allow QuickCheck-2.5 Support bytestring-0.10 (NFData instances added)-0.12.6+0.12.6, released 2011-12-11 #515, don't crash on malformed characters (use ? instead)-0.12.5+0.12.5, released 2011-11-17 Add optRawTag to Render, to ensure script's don't get escaped-0.12.4+0.12.4, released 2011-11-05 #487, fix the behaviour of ~== for TagComment and others-0.12.3+0.12.3, released 2011-08-12 GHC 7.2 compatibility-0.12.2+0.12.2, released 2011-06-12 Add StringLike instances for Text-0.12.1+0.12.1, released 2011-06-01 Add parseOptionsEntities and improve documentation-0.12+0.12, released 2010-12-12 Upgrade to QuickCheck 2.4.* Export toTagRep Make the -download flag off by default Eliminate HTTP dependency Eliminate mtl dependency-0.11.1+0.11.1, released 2010-10-04 Support --flags=-download to eliminate the network dependency-0.11+0.11, released 2010-09-12 #326, <a "foo"> is no longer treated as an attribute Add Eq/Ord instances to Tree Don't mark Text.HTML.TagSoup.Tree as preliminary #325, \r should be treated as whitespace-0.10.1+0.10.1, released 2010-07-22 #322, don't change ' to ' in render (do what the docs say)-0.10+0.10, released 2010-05-26 Improve the cabal file, make the test program off by default Expose Text.HTML.TagSoup.Match again (was hidden accidentally)-0.9+0.9, released 2010-05-09 #294, let optEntityData see if there was a ';' (CHANGES API) Numeric/hex entities in attributes were misparsed #149, add escapeHTML function-0.8+0.8, released 2010-01-07 Parser now based on HTML5 specification Tag is now parameterised by the string type-0.6+0.6, released 2008-04-23 Addition of Text.HTML.TagSoup.Tree and Text.HTML.TagSoup.Render Text.HTML.TagSoup.Parser.Options renamed to ParseOptions Text.HTML.TagSoup.Parser.options renamed to parseOptions-0.4+0.4, released 2008-01-14 Changelog started
LICENSE view
@@ -1,4 +1,4 @@-Copyright Neil Mitchell 2006-2017.+Copyright Neil Mitchell 2006-2018. All rights reserved. Redistribution and use in source and binary forms, with or without
README.md view
@@ -250,7 +250,17 @@ main :: IO () main = currentTime ```- ++## Other Examples+In [Sample.hs](https://github.com/ndmitchell/tagsoup/blob/master/TagSoup/Sample.hs)+the following additional examples are listed: ++- Google Tech News +- Package list form Hackage+- Print names of story contributors on sequence.complete.org+- Parse rows of a table++ ## Related Projects * [TagSoup for Java](http://tagsoup.info/) - an independently written malformed HTML parser for Java. Including [links to other](http://tagsoup.info/#other) HTML parsers.
src/Text/HTML/TagSoup/Specification.hs view
@@ -32,7 +32,7 @@ type Parser = S -> [Out] parse :: String -> [Out]-parse = dat . state +parse = dat . state -- 8.2.4.1 Data state dat :: Parser@@ -223,11 +223,11 @@ -- 8.2.4.17 Markup declaration open state-markupDeclOpen S{..} = pos $ case hd of+markupDeclOpen S{..} = case hd of _ | Just s <- next "--" -> Comment & commentStart s _ | isAlpha hd -> Tag & '!' & hd & tagName TypeDecl tl -- NEIL _ | Just s <- next "[CDATA[" -> cdataSection s- _ -> errWant "tag name" & bogusComment s+ _ -> pos $ errWant "tag name" & bogusComment s -- 8.2.4.18 Comment start state
tagsoup.cabal view
@@ -1,7 +1,7 @@ cabal-version: >= 1.18 name: tagsoup-version: 0.14.2-copyright: Neil Mitchell 2006-2017+version: 0.14.3+copyright: Neil Mitchell 2006-2018 author: Neil Mitchell <ndmitchell@gmail.com> maintainer: Neil Mitchell <ndmitchell@gmail.com> homepage: https://github.com/ndmitchell/tagsoup#readme@@ -11,7 +11,7 @@ license-file: LICENSE build-type: Simple synopsis: Parsing and extracting information from (possibly malformed) HTML/XML documents-tested-with: GHC==8.2.1, GHC==8.0.2, GHC==7.10.3, GHC==7.8.4, GHC==7.6.3, GHC==7.4.2+tested-with: GHC==8.2.2, GHC==8.0.2, GHC==7.10.3, GHC==7.8.4, GHC==7.6.3, GHC==7.4.2 description: TagSoup is a library for parsing HTML/XML. It supports the HTML 5 specification, and can be used to parse either well-formed XML, or unstructured and malformed HTML@@ -52,7 +52,7 @@ type: exitcode-stdio-1.0 default-language: Haskell2010 build-depends:- base == 4.*, containers, bytestring, text,+ base == 4.*, bytestring, QuickCheck >= 2.4, deepseq >= 1.1, tagsoup,
test/Main.hs view
@@ -25,8 +25,8 @@ g (nam,msg,Right _) = (nam ++ " <url>",msg) f (lhs,rhs) = " " ++ lhs ++ replicate (4 + width - length lhs) ' ' ++ rhs- + actions :: [(String, String, Either (IO ()) (String -> IO ()))] actions = [("test","Run the test suite",Left test) ,("grab","Grab a web page",Right grab)@@ -40,6 +40,7 @@ ,("time","Current time",Left currentTime) ,("google","Google Tech News",Left googleTechNews) ,("sequence","Creators on sequence.complete.org",Left rssCreators)+ ,("table","Parse a table",Left $ print parseTable) ,("help","This help message",Left helpMsg) ]
test/TagSoup/Sample.hs view
@@ -156,3 +156,52 @@ g xs = xs ++ [if n == 0 then "Success, no warnings" else "Failed, " ++ show n ++ " warning" ++ ['s'|n>1]] where n = length xs++-- | Parse a table+parseTable:: [[[String]]]+parseTable = do+ let tags = parseTags tableExample+ parseRow :: [Tag String] -> [String]+ parseRow = map (innerText . takeWhile (~/="</td>")) . sections (~== "<td>")+ dd = map (parseRow . takeWhile (~/= "</tr>")) . sections (~== "<tr>") $ tags+ return dd+ where+ -- | Example from https://www.w3schools.com/html/html_tables.asp+ tableExample =+ "<table> \n\+ \ <tr> \n\+ \ <th>Company</th> \n\+ \ <th>Contact</th> \n\+ \ <th>Country</th> \n\+ \ </tr> \n\+ \ <tr> \n\+ \ <td>Alfreds Futterkiste</td> \n\+ \ <td>Maria Anders</td> \n\+ \ <td>Germany</td> \n\+ \ </tr> \n\+ \ <tr> \n\+ \ <td>Centro comercial Moctezuma</td> \n\+ \ <td>Francisco Chang</td> \n\+ \ <td>Mexico</td> \n\+ \ </tr> \n\+ \ <tr> \n\+ \ <td>Ernst Handel</td> \n\+ \ <td>Roland Mendel</td> \n\+ \ <td>Austria</td> \n\+ \ </tr> \n\+ \ <tr> \n\+ \ <td>Island Trading</td> \n\+ \ <td>Helen Bennett</td> \n\+ \ <td>UK</td> \n\+ \ </tr> \n\+ \ <tr> \n\+ \ <td>Laughing Bacchus Winecellars</td> \n\+ \ <td>Yoshi Tannamuri</td> \n\+ \ <td>Canada</td> \n\+ \ </tr> \n\+ \ <tr> \n\+ \ <td>Magazzini Alimentari Riuniti</td> \n\+ \ <td>Giovanni Rovelli</td> \n\+ \ <td>Italy</td> \n\+ \ </tr> \n\+ \ </table>"
test/TagSoup/Test.hs view
@@ -147,7 +147,7 @@ parseTags "<a \r\n href=\"url\">" === [TagOpen "a" [("href","url")]] - parseTags "<a href='random.php'><img src='strips/130307.jpg' alt='nukular bish'' title='' /></a>" === + parseTags "<a href='random.php'><img src='strips/130307.jpg' alt='nukular bish'' title='' /></a>" === [TagOpen "a" [("href","random.php")],TagOpen "img" [("src","strips/130307.jpg"),("alt","nukular bish"),("'",""),("title","")],TagClose "img",TagClose "a"] parseTags "<p>some text</p\n<img alt='< &yyy; >' src=\"abc.gif\">" ===@@ -209,7 +209,7 @@ escapeHTML "this is a &\" <test> '" === "this is a &" <test> '" check $ \(HTML x) -> let y = rp x in rp y == (y :: String) - + entityTests :: Test () entityTests = do lookupNumericEntity "65" === Just "A"@@ -248,6 +248,9 @@ p "<a>&" === [TagPosition 1 1,TagOpen "a" [],TagPosition 1 4,TagText "&"] p "<a>&1" === [TagPosition 1 1,TagOpen "a" [],TagPosition 1 4,TagText "&1"] p "<a>&" === [TagPosition 1 1,TagOpen "a" [],TagPosition 1 4,TagText "&"]+ p "<div><!--foo-->bar</div>" === [TagPosition 1 1,TagOpen "div" [],TagPosition 1 6,TagComment "foo",TagPosition 1 16,TagText "bar",TagPosition 1 19,TagClose "div"]+ p "<![CDATA[x]]>" === [TagPosition 1 10,TagText "x"]+ p "<!html>" === [TagPosition 1 1,TagOpen "!html" []] warnTests :: Test ()