scmdoc

Automatically generate documentation from comments in R7RS Scheme code

git clone https://git.8pit.net/scmdoc.git

 1{-# LANGUAGE OverloadedStrings #-}
 2
 3-- | Utility functions for creating custom 'SchemeDoc.Format.Types.Formatter's.
 4module SchemeDoc.Format.Util where
 5
 6import CMarkGFM
 7import qualified Data.Text as T
 8import SchemeDoc.Types
 9import Text.Blaze.Html
10
11import qualified Text.Blaze.Html5 as H
12import qualified Text.Blaze.Html5.Attributes as A
13
14-- | Format an S-expression in an 'Html' code block.
15htmlSexp :: Sexp -> Html
16htmlSexp = H.pre . H.code . toHtml . show
17
18-- | Format a component with the given type prefix and the given name.
19component :: T.Text -> T.Text -> Html
20component prefix name = do
21    H.h3 $ do
22        toHtml $ toMarkup (T.append prefix " ")
23        H.a
24            ! A.id (textValue name)
25            ! A.href (textValue (T.cons '#' name))
26            $ toHtml name
27
28-- | Convert from Markdown to Html.
29fromMkd :: T.Text -> Html
30fromMkd s = preEscapedToHtml $ commonmarkToHtml [optUnsafe] [] s
31
32-- | Returns a formatter pattern match function which is only executed
33-- if the given S-expression constitutes an identifier.
34onId :: (T.Text -> a) -> (Sexp -> Maybe a)
35onId fn (Id i) = Just $ fn i
36onId _ _ = Nothing