diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2006-12-20 06:50:14 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2006-12-20 06:50:14 +0000 |
commit | dc9c6450f3b16592d0ee865feafc17b670e4ad14 (patch) | |
tree | dc29955e1ea518d6652af3d12876863b19819f6d /src/Text/Pandoc/HtmlEntities.hs | |
parent | 42d29838960f9aed3a08a4d76fc7e9c3941680a8 (diff) | |
download | pandoc-dc9c6450f3b16592d0ee865feafc17b670e4ad14.tar.gz |
+ Added module data for haddock.
+ Reformatted code consistently.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@252 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/Text/Pandoc/HtmlEntities.hs')
-rw-r--r-- | src/Text/Pandoc/HtmlEntities.hs | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/Text/Pandoc/HtmlEntities.hs b/src/Text/Pandoc/HtmlEntities.hs index bbb438ef5..a03548388 100644 --- a/src/Text/Pandoc/HtmlEntities.hs +++ b/src/Text/Pandoc/HtmlEntities.hs @@ -1,12 +1,22 @@ --- | Functions for encoding unicode characters as HTML entity --- references, and vice versa. +{- | + Module : Text.Pandoc.HtmlEntities + Copyright : Copyright (C) 2006 John MacFarlane + License : GNU GPL, version 2 or above + + Maintainer : John MacFarlane <jgm at berkeley dot edu> + Stability : unstable + Portability : portable + +Functions for encoding unicode characters as HTML entity references, +and vice versa. +-} module Text.Pandoc.HtmlEntities ( htmlEntityToChar, charToHtmlEntity, decodeEntities, encodeEntities ) where -import Char ( chr, ord ) +import Data.Char ( chr, ord ) import Text.Regex ( mkRegex, matchRegexAll ) import Maybe ( fromMaybe ) @@ -19,13 +29,15 @@ characterEntity = mkRegex "&#[0-9]+;|&[A-Za-z0-9]+;" decodeEntities :: String -> String decodeEntities str = case (matchRegexAll characterEntity str) of - Nothing -> str - Just (before, match, rest, _) -> before ++ replacement ++ (decodeEntities rest) + Nothing -> str + Just (before, match, rest, _) -> before ++ replacement ++ + (decodeEntities rest) where replacement = case (htmlEntityToChar match) of Just ch -> [ch] Nothing -> match --- | Returns a string with characters replaced with entity references where possible. +-- | Returns a string with characters replaced with entity references where +-- possible. encodeEntities :: String -> String encodeEntities = concatMap (\c -> fromMaybe [c] (charToHtmlEntity c)) @@ -44,10 +56,9 @@ htmlEntityToChar entity = charToHtmlEntity :: Char -> Maybe String charToHtmlEntity char = let matches = filter (\(entity, character) -> (character == char)) htmlEntityTable in - if (length matches) == 0 then - Nothing - else - Just (fst (head matches)) + if (length matches) == 0 + then Nothing + else Just (fst (head matches)) htmlEntityTable :: [(String, Char)] htmlEntityTable = [ |