on master help sign in
Do not escape contents within 'style' tags.
f96174bFavonia
src/Hakyll/Web/Urls.hs+9−1
@@ -8,6 +8,7 @@ module Hakyll.Web.Urls
8 ) where
8 ) where
9
9
10import Data.List (isPrefixOf)
10import Data.List (isPrefixOf)
11+import Data.Char (toLower)
11import System.FilePath (splitPath, takeDirectory, joinPath)
12import System.FilePath (splitPath, takeDirectory, joinPath)
12import qualified Data.Set as S
13import qualified Data.Set as S
13
14
@@ -16,13 +17,20 @@ import qualified Text.HTML.TagSoup as TS
16-- | Apply a function to each URL on a webpage
17-- | Apply a function to each URL on a webpage
17--
18--
18withUrls :: (String -> String) -> String -> String
19withUrls :: (String -> String) -> String -> String
19−withUrls f = TS.renderTags . map tag . TS.parseTags
20+withUrls f = renderTags' . map tag . TS.parseTags
20 where
21 where
21 tag (TS.TagOpen s a) = TS.TagOpen s $ map attr a
22 tag (TS.TagOpen s a) = TS.TagOpen s $ map attr a
22 tag x = x
23 tag x = x
23 attr (k, v) = (k, if k `S.member` refs then f v else v)
24 attr (k, v) = (k, if k `S.member` refs then f v else v)
24 refs = S.fromList ["src", "href"]
25 refs = S.fromList ["src", "href"]
25
26
27+-- | Customized TagSoup renderer.
28+-- (The default TagSoup renderer escape CSS within style tags.)
29+renderTags' :: [TS.Tag String] -> String
30+renderTags' = TS.renderTagsOptions TS.renderOptions
31+ { TS.optRawTag = (`elem` ["script", "style"]) . map toLower
32+ }
33+
26-- | Convert a filepath to an URL starting from the site root
34-- | Convert a filepath to an URL starting from the site root
27--
35--
28-- Example:
36-- Example: