module Cheapskate.Highlight
(
highlightDoc,
highlightDocWith,
highlightBlock,
highlightBlockWith,
FormatOptions(..),
defaultFormatOpts,
module Text.Highlighting.Kate.Styles,
styleToCss,
)
where
import qualified Data.Text as T
import Data.Text (Text)
import qualified Data.Text.Lazy as TL
import Cheapskate
import Text.Highlighting.Kate
import Text.Highlighting.Kate.Styles
import Text.Blaze.Html.Renderer.Text
highlightDoc :: Doc -> Doc
highlightDoc = highlightDocWith (\_ _ x -> x)
highlightDocWith
:: (Text -> Text -> FormatOptions -> FormatOptions) -> Doc -> Doc
highlightDocWith f doc = walk (highlightBlockWith f) doc
highlightBlock :: Block -> Block
highlightBlock = highlightBlockWith (\_ _ x -> x)
highlightBlockWith
:: (Text -> Text -> FormatOptions -> FormatOptions) -> Block -> Block
highlightBlockWith f (CodeBlock CodeAttr{..} code) =
HtmlBlock (TL.toStrict (renderHtml formatted))
where
lang = T.unpack codeLang
highlighted = highlightAs lang (T.unpack code)
opts = defaultFormatOpts {
containerClasses = words (T.unpack codeInfo) }
formatted = formatHtmlBlock (f codeLang codeInfo opts) highlighted
highlightBlockWith _ other = other