Modules 28
Prettyprinter.Render.Tutorials.TreeRenderingTutorial
This module shows how to write a custom prettyprinter backend, based on a
tree representation of a SimpleDocStream. For a stack machine approach, which
may be more suitable for certain output formats, see
Prettyprinter.Render.Tutorials.StackMachineTutorial.
Rendering to HTML, particularly using libraries such as blaze-html or lucid, is one important use case of tree-based rendering.
The module is written to be readable top-to-bottom in both Haddock and raw source form.
The type of available markup
data Color
Red :: Color
Green :: Color
Blue :: Color
Convenience definitions
bold :: Doc SimpleHtml -> Doc SimpleHtml
italics :: Doc SimpleHtml -> Doc SimpleHtml
paragraph :: Doc SimpleHtml -> Doc SimpleHtml
headline :: Doc SimpleHtml -> Doc SimpleHtml
color :: Color -> Doc SimpleHtml -> Doc SimpleHtml
The rendering algorithm
render :: SimpleDocStream SimpleHtml -> TL.Text
To render the HTML, we first convert the SimpleDocStream to the
SimpleDocTree format, which makes enveloping sub-documents in markup
easier.
This function is the entry main API function of the renderer; as such, it is
only glue for the internal functions. This is similar to
render from
the stack machine tutorial in its purpose.
renderTree :: SimpleDocTree SimpleHtml -> TLB.Builder
Render a SimpleDocTree to a Builder; this is the workhorse of the
tree-based rendering approach, and equivalent to
renderStackMachine
in the stack machine rendering tutorial.
encloseInTagFor :: SimpleHtml -> TLB.Builder -> TLB.Builder
Convert a SimpleHtml to a function that encloses a Builder in HTML
tags. This is where the translation of style to raw output happens.
Example invocation
Build record and source files
Community contribution. The service has not verified this documentation. The generator reported 21 diagnostics.
Target: Linux on x86-64. Some inferred types and resolved links are not available.
Generator: aihc-haddock-858b1951-web-1
Metadata snapshot: 19f659e0fd2a9606431ae6a3ec65f9ace725052e19ca6a9f9e9f2759e30fd129
Open the dependency plan · Download the documentation model
- aihc-base-4.21.2.0 · Core library · Cabal file
- aihc-internal-9.1204.0 · Core library · Cabal file
- aihc-prim-0.13.0 · Core library · Cabal file
- aihc-rts-1.0.2 · Core library · Cabal file
- aihc-template-haskell-2.23.0.0 · Core library · Cabal file
- array-0.5.8.0 · Cabal revision 2 · Cabal file · Source archive
- binary-0.8.9.3 · Cabal revision 0 · Cabal file · Source archive
- bytestring-0.12.2.0 · Cabal revision 1 · Cabal file · Source archive
- containers-0.8.1 · Cabal revision 0 · Cabal file · Source archive
- deepseq-1.5.2.0 · Cabal revision 0 · Cabal file · Source archive
- prettyprinter-1.7.2 · Cabal revision 0 · Cabal file · Source archive
- system-cxx-std-lib-1.0 · Core library · Cabal file
- text-2.1.4 · Cabal revision 0 · Cabal file · Source archive