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.Html1011import qualified Text.Blaze.Html5 as H12import qualified Text.Blaze.Html5.Attributes as A1314-- | Format an S-expression in an 'Html' code block.15htmlSexp :: Sexp -> Html16htmlSexp = H.pre . H.code . toHtml . show1718-- | Format a component with the given type prefix and the given name.19component :: T.Text -> T.Text -> Html20component prefix name = do21 H.h3 $ do22 toHtml $ toMarkup (T.append prefix " ")23 H.a24 ! A.id (textValue name)25 ! A.href (textValue (T.cons '#' name))26 $ toHtml name2728-- | Convert from Markdown to Html.29fromMkd :: T.Text -> Html30fromMkd s = preEscapedToHtml $ commonmarkToHtml [optUnsafe] [] s3132-- | Returns a formatter pattern match function which is only executed33-- if the given S-expression constitutes an identifier.34onId :: (T.Text -> a) -> (Sexp -> Maybe a)35onId fn (Id i) = Just $ fn i36onId _ _ = Nothing