| Copyright | (C) 2016-2026 David M. Johnson |
|---|---|
| License | BSD3-style (see the file LICENSE) |
| Maintainer | David M. Johnson <code@dmj.io> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Miso.Html.Render
Contents
Description
Overview
Miso.Html.Render provides the ToHtml typeclass for serialising a
View tree to a lazy ByteString of
UTF-8 HTML. This is the foundation of miso's
server-side rendering (SSR)
support.
Instances are provided for both (a single node)
and View m a[ (a sequence of nodes).View m a]
Quick start
import Miso.Html.Render (ToHtml,toHtml) import qualified Data.ByteString.Lazy as L renderPage :: Model -> L.ByteString renderPage m =toHtml(view m)
With servant, use inside a toHtml
or ByteStringOctetStream response, or wire it into a ToHtml servant
MIME type.
Rendering rules
VNode— rendered as<tag attrs>children</tag>. Self-closing elements (<br/>,<img/>,<input/>, …) are rendered without a closing tag.VText— rendered as a raw text string (no escaping beyond what is already in theMisoString).VComp— recursively renders the sub-component's view using its initial (or hydrated) model.VFrag— renders all children inline, no wrapper tag.- Event handlers (
) — silently dropped; they have no meaning in a static HTML string.On - Boolean properties (
disabled,checked,required, …) — rendered as bare attribute names whenTrue, omitted entirely whenFalse. - Adjacent text nodes — collapsed into a single text node to match browser parsing behaviour during hydration.
SSR flag
When compiled with -fssr the renderer calls the component's optional
hydrateModel action to derive the initial model (e.g. by fetching from
a database), falling back to the static model if the action throws.
See also
- Miso.Hydrate — client-side hydration from server-rendered HTML
- Miso.Html.Element — element smart constructors
- Miso.Html — top-level HTML DSL re-export hub
Synopsis
- class ToHtml a where
- toHtml :: a -> ByteString
Classes
Class for rendering HTML
Methods
toHtml :: a -> ByteString Source #
Instances
| ToHtml [View m a] Source # | Render a |
Defined in Miso.Html.Render Methods toHtml :: [View m a] -> ByteString Source # | |
| ToHtml (View m a) Source # | Render a |
Defined in Miso.Html.Render Methods toHtml :: View m a -> ByteString Source # | |