3 -- Extract any text that has been markup up with a given tag.
5 import Text
.HTML
.TagSoup
7 import System
.Environment
(getArgs)
8 import Data
.List
.HT
(breakAfter
)
10 checkArgs
:: [String] -> Bool
12 checkArgs x
= any (elem '-') x
14 helpstring
= "Bad Arguments!\n"
20 then hPutStr stderr helpstring
21 else interact (unlines . extractByTag args
)
23 extractByTag
:: [String] -> String -> [String]
24 extractByTag tags s
= map renderTags
(filterTags tags
(parseTags s
))
26 filterTags
:: [String] -> [Tag
String] -> [[Tag
String]]
28 filterTags tags
(t
:ts
)
30 let (good
, rest
) = breakAfter
(isStopTag
(tagStr t
)) (t
:ts
)
31 in good
:(filterTags tags rest
)
32 |
otherwise = filterTags tags ts
34 isStartTag
:: [String] -> Tag
String -> Bool
35 isStartTag tags
(TagOpen str _
) = elem str tags
36 isStartTag _ _
= False
38 tagStr
:: Tag
String -> String
39 tagStr
(TagOpen s _
) = s
40 tagStr
(TagClose s
) = s
43 isStopTag
:: String -> Tag
String -> Bool
44 isStopTag tag
(TagClose str
) = (tag
== str
)