HTML rendering
This commit is contained in:
parent
a09f3b60df
commit
135b878233
4 changed files with 43 additions and 0 deletions
1
SSG.ipkg
1
SSG.ipkg
|
@ -29,6 +29,7 @@ modules = SSG.HTML
|
||||||
, SSG.Djot.Lines
|
, SSG.Djot.Lines
|
||||||
, SSG.Djot.Block
|
, SSG.Djot.Block
|
||||||
, SSG.Djot.Inline
|
, SSG.Djot.Inline
|
||||||
|
, SSG.Djot.Render
|
||||||
|
|
||||||
-- main file (i.e. file to load at REPL)
|
-- main file (i.e. file to load at REPL)
|
||||||
main = Main
|
main = Main
|
||||||
|
|
|
@ -1 +1,5 @@
|
||||||
module SSG.Djot
|
module SSG.Djot
|
||||||
|
|
||||||
|
import public SSG.Djot.Inline
|
||||||
|
import public SSG.Djot.Block
|
||||||
|
import public SSG.Djot.Render
|
||||||
|
|
37
src/SSG/Djot/Render.idr
Normal file
37
src/SSG/Djot/Render.idr
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
||| Render Djot to HTML
|
||||||
|
module SSG.Djot.Render
|
||||||
|
|
||||||
|
import SSG.HTML
|
||||||
|
import SSG.Djot.Inline
|
||||||
|
import SSG.Djot.Block
|
||||||
|
|
||||||
|
||| Render a single inline element as HTML
|
||||||
|
export
|
||||||
|
renderInline : Inline -> (t ** Html t)
|
||||||
|
-- FIXME: escape text
|
||||||
|
renderInline (Text text) = (_ ** Text text)
|
||||||
|
|
||||||
|
||| Render a list of inline elments to html
|
||||||
|
export
|
||||||
|
renderInlines : List Inline -> (types ** DList _ Html types)
|
||||||
|
renderInlines xs = fromList $ 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
|
||||||
|
renderDocument : {types : _} -> DList _ Block types -> Html "html"
|
||||||
|
renderDocument xs =
|
||||||
|
Normal "html" ["lang" =$ "en"] [
|
||||||
|
Normal "body" [] (snd (renderBlocks xs))
|
||||||
|
]
|
1
todo.org
1
todo.org
|
@ -3,6 +3,7 @@
|
||||||
** TODO Smart spec compliance for =attribute=
|
** TODO Smart spec compliance for =attribute=
|
||||||
Probably want to refine the attribute and value strings, and be smarter about how we choose to quote the value string.
|
Probably want to refine the attribute and value strings, and be smarter about how we choose to quote the value string.
|
||||||
** TODO Don't generate any further indent once we are already inside a =p=
|
** TODO Don't generate any further indent once we are already inside a =p=
|
||||||
|
** TODO Text escaping function
|
||||||
** NO Move =Raw= out of =Tag=
|
** NO Move =Raw= out of =Tag=
|
||||||
Decided to rename =Tag= to =Html=, and =Raw= to =Text=, which makes this make sense
|
Decided to rename =Tag= to =Html=, and =Raw= to =Text=, which makes this make sense
|
||||||
* Parser Core
|
* Parser Core
|
||||||
|
|
Loading…
Add table
Reference in a new issue