Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Provides utilities to manipulate HTML pages
Synopsis
- withTags :: (Tag String -> Tag String) -> String -> String
- withTagList :: ([Tag String] -> [Tag String]) -> String -> String
- withTagListM :: Monad m => ([Tag String] -> m [Tag String]) -> String -> m String
- demoteHeaders :: String -> String
- demoteHeadersBy :: Int -> String -> String
- getUrls :: [Tag String] -> [String]
- withUrls :: (String -> String) -> String -> String
- toUrl :: FilePath -> String
- toSiteRoot :: String -> String
- isExternal :: String -> Bool
- stripTags :: String -> String
- escapeHtml :: String -> String
Generic
withTags :: (Tag String -> Tag String) -> String -> String Source #
Map over all tags in the document
withTagList :: ([Tag String] -> [Tag String]) -> String -> String Source #
Map over all tags (as list) in the document
withTagListM :: Monad m => ([Tag String] -> m [Tag String]) -> String -> m String Source #
Map over all tags (as list) in the document, in a monad
Headers
demoteHeaders :: String -> String Source #
Map every h1
to an h2
, h2
to h3
, etc.
demoteHeadersBy :: Int -> String -> String Source #
Maps any hN
to an hN+amount
for any amount > 0 && 1 <= N+amount <= 6
.
Url manipulation
getUrls :: [Tag String] -> [String] Source #
Extract URLs from tags' attributes. Those would be the same URLs on which
withUrls
would act.
withUrls :: (String -> String) -> String -> String Source #
Apply a function to each URL on a webpage
toUrl :: FilePath -> String Source #
Convert a filepath to an URL starting from the site root
Example:
toUrl "foo/bar.html"
Result:
"/foo/bar.html"
This also sanitizes the URL, e.g. converting spaces into '%20'
toSiteRoot :: String -> String Source #
Get the relative url to the site root, for a given (absolute) url
isExternal :: String -> Bool Source #
Check if an URL links to an external HTTP(S) source
Stripping/escaping
stripTags :: String -> String Source #
Strip all HTML tags from a string
Example:
stripTags "<p>foo</p>"
Result:
"foo"
This also works for incomplete tags
Example:
stripTags "<p>foo</p"
Result:
"foo"
escapeHtml :: String -> String Source #
HTML-escape a string
Example:
escapeHtml "Me & Dean"
Result:
"Me & Dean"