diff options
1 files changed, 30 insertions, 0 deletions
| -rw-r--r-- | homework/81248/cToHtml/src/Html.hs | 30 |
diff --git a/homework/81248/cToHtml/src/Html.hs b/homework/81248/cToHtml/src/Html.hs new file mode 100644 index 0000000..49c6eb1 --- /dev/null +++ b/homework/81248/cToHtml/src/Html.hs @@ -0,0 +1,30 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE ExtendedDefaultRules #-} + +module Html + ( cToHtml + ) where + +import qualified Data.Text as T + +import Lucid + +import Clex.Types + +cToHtml :: String -> [Token] -> Html () +cToHtml col toks = pre_ $ foldMap (colourize col) toks + +colourize :: String -> Token -> Html () +colourize _ (Whitespace bs) = toHtmlRaw bs +colourize _ (HexNumber bs) = toHtml bs +colourize _ (OctNumber bs) = toHtml bs +colourize _ (Number bs) = toHtml bs +colourize _ (CharLit bs) = toHtml bs +colourize _ (Scientific bs) = toHtml bs +colourize _ (DotFloat bs) = toHtml bs +colourize _ (LeadingDot bs) = toHtml bs +colourize _ (StringLit bs) = toHtml bs +colourize _ (Identifier bs) = toHtml bs +colourize col x = span_ [style_ $ "color:" <> col'] $ toHtml $ tokenToBS x + where col' = T.pack col |
