blob: 49c6eb11b99672f8ee6b4006277bf3c596e21805 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
|