@@ -11,17 +11,18 @@ import Data.List (isPrefixOf)
11import System.FilePath (splitPath, takeDirectory, joinPath)
11import System.FilePath (splitPath, takeDirectory, joinPath)
12import qualified Data.Set as S
12import qualified Data.Set as S
14−import Text.HTML.TagSoup (Tag (..), renderTags, parseTags)
14+import qualified Text.HTML.TagSoup as TS
16-- | Apply a function to each URL on a webpage
16-- | Apply a function to each URL on a webpage
18withUrls :: (String -> String) -> String -> String
18withUrls :: (String -> String) -> String -> String
19−withUrls f = renderTags . map tag . parseTags
19+withUrls f = TS.renderTagsOptions opts . map tag . TS.parseTags
21− tag (TagOpen s a) = TagOpen s $ map attr a
21+ tag (TS.TagOpen s a) = TS.TagOpen s $ map attr a
22− tag x = x
22+ tag x = x
23− attr (k, v) = (k, if k `S.member` refs then f v else v)
23+ attr (k, v) = (k, if k `S.member` refs then f v else v)
24− refs = S.fromList ["src", "href"]
24+ refs = S.fromList ["src", "href"]
25+ opts = TS.renderOptions {TS.optEscape = id}
26-- | Convert a filepath to an URL starting from the site root
27-- | Convert a filepath to an URL starting from the site root
@@ -43,12 +44,12 @@ toSiteRoot :: String -> String
43toSiteRoot = emptyException . joinPath . map parent
44toSiteRoot = emptyException . joinPath . map parent
44 . filter relevant . splitPath . takeDirectory
45 . filter relevant . splitPath . takeDirectory
46− parent = const ".."
47+ parent = const ".."
47 emptyException [] = "."
48 emptyException [] = "."
48 emptyException x = x
49 emptyException x = x
49− relevant "." = False
50+ relevant "." = False
50− relevant "/" = False
51+ relevant "/" = False
51− relevant _ = True
52+ relevant _ = True
53-- | Check if an URL links to an external HTTP(S) source
54-- | Check if an URL links to an external HTTP(S) source