41 lines
1.1 KiB
Idris
41 lines
1.1 KiB
Idris
||| Render Djot to HTML
|
|
module SSG.Djot.Render
|
|
|
|
import SSG.HTML
|
|
import SSG.Djot.Inline
|
|
import SSG.Djot.Block
|
|
|
|
import Data.List
|
|
|
|
||| Render a single inline element as HTML
|
|
export
|
|
renderInline : Inline -> Maybe (t ** Html t)
|
|
-- FIXME: escape text
|
|
renderInline (Text text) = Just (_ ** Text text)
|
|
renderInline SoftLineBreak = Nothing
|
|
|
|
||| Render a list of inline elments to html
|
|
export
|
|
renderInlines : List Inline -> (types ** DList _ Html types)
|
|
renderInlines xs = fromList . catMaybes $ map renderInline xs
|
|
|
|
||| Render a single block element as HTML
|
|
export
|
|
renderBlock : Block t -> (t ** Html t)
|
|
|
|
||| Render a list of block level elements to html
|
|
export
|
|
renderBlocks : {types: _} -> DList _ Block types -> (types' ** DList _ Html types')
|
|
|
|
renderBlock (Paragraph content) =
|
|
(_ ** Normal "p" [] (snd (renderInlines content)))
|
|
|
|
renderBlocks xs = dMap' (\_, x => renderBlock x) xs
|
|
|
|
||| Render a complete html document from a list of block level elements
|
|
export
|
|
renderDocument : {types : _} -> DList _ Block types -> Html "html"
|
|
renderDocument xs =
|
|
Normal "html" ["lang" =$ "en"] [
|
|
Normal "body" [] (snd (renderBlocks xs))
|
|
]
|