[Move showTagHTML into Data.TagStr Neil Mitchell**20101026073223] { hunk ./src/Data/TagStr.hs 4 -module Data.TagStr where +module Data.TagStr(TagStr(..), showTagText, showTagConsole, showTagHTML, showTagHTMLWith) where hunk ./src/Data/TagStr.hs 10 +import Data.Maybe +import Numeric hunk ./src/Data/TagStr.hs 19 - | TagColor Int TagStr -- ^ Colored text. + | TagColor Int TagStr -- ^ Colored text. Index into a 0-based palette. hunk ./src/Data/TagStr.hs 57 + +-- | Show a 'TagStr' as HTML, using CSS classes for color styling. +showTagHTML :: TagStr -> String +showTagHTML = showTagHTMLWith (const Nothing) + + +-- | Show TagStr with an override for specific tags. +showTagHTMLWith :: (TagStr -> Maybe String) -> TagStr -> String +showTagHTMLWith f x = g x + where + g x | isJust (f x) = fromJust $ f x + g (Str x) = escapeHTML x + g (Tags xs) = concatMap g xs + g (TagBold x) = "" ++ showTagHTML x ++ "" + g (TagUnderline x) = "" ++ showTagHTML x ++ "" + g (TagHyperlink "" x) = g (TagHyperlink url x) + where str = showTagText x + url = if "http:" `isPrefixOf` str then str else "?hoogle=" +% str + g (TagHyperlink url x) = "" ++ showTagHTML x ++ "" + g (TagColor i x) = "" ++ showTagHTML x ++ "" + + +-- FIXME: Should not be here! +a +& b = a ++ escapeHTML b +a +% b = a ++ escapeCGI b +escapeHTML = concatMap f + where + f '\"' = """ + f '<' = "<" + f '>' = ">" + f '&' = "&" + f '\n' = "
" + f x = [x] +escapeCGI = concatMap f + where + f x | isAlphaNum x || x `elem` "-" = [x] + | x == ' ' = "+" + | otherwise = '%' : ['0'|length s == 1] ++ s + where s = showHex (ord x) "" + hunk ./src/Web/Text.hs 2 +-- | FIXME: Most of this module should be moved elsewhere hunk ./src/Web/Text.hs 6 -import Data.TagStr hunk ./src/Web/Text.hs 39 - --- FIXME: should be somewhere else -showTagHTML = showTagHTMLWith (const Nothing) - - -showTagHTMLWith :: (TagStr -> Maybe String) -> TagStr -> String -showTagHTMLWith f x = g x - where - g x | isJust (f x) = fromJust $ f x - g (Str x) = escapeHTML x - g (Tags xs) = concatMap g xs - g (TagBold x) = "" ++ showTagHTML x ++ "" - g (TagUnderline x) = "" ++ showTagHTML x ++ "" - g (TagHyperlink "" x) = g (TagHyperlink url x) - where str = showTagText x - url = if "http:" `isPrefixOf` str then str else "?hoogle=" +% str - g (TagHyperlink url x) = "" ++ showTagHTML x ++ "" - g (TagColor i x) = "" ++ showTagHTML x ++ "" - }