Safe Haskell | None |
---|---|
Language | Haskell2010 |
type-of-html has three main goals:
- Type safety
- Modularity
- Performance
Let's check out the type safety in ghci:
>>>
td_ (tr_ "a")
<interactive>:1:1: error: • 'Tr is not a valid child of 'Td • In the expression: td_ (tr_ "a") In an equation for ‘it’: it = td_ (tr_ "a") <interactive>:1:6: error: • 'Tr can't contain a string • In the first argument of ‘td_’, namely ‘(tr_ "a")’ In the expression: td_ (tr_ "a") In an equation for ‘it’: it = td_ (tr_ "a")
>>>
tr_ (td_ "a")
<tr><td>a</tr>
For every child, it is checked if it could possibly be lawful.
The checking is a bit lenient at the moment:
- some elements can't contain itself as any descendant: at the moment we look only at direct children. This allows some (quite exotic) invalid html documents.
- some elements change their permitted content based on attributes: we don't know at compile time the attributes, therefore we always allow content as if all relevant attributes are set.
- some elements can't be brethren: we look only at parent child relations, therefore if you don't specify the parent, it'll compile
Never the less: these cases are seldom. In the vast majority of cases you're only allowed to construct valid html.
Let's talk about modularity:
Rosetrees of html are just ordinary haskell values which can be composed or abstracted over:
>>>
let table = table_ . map (tr_ . map td_)
>>>
:t table
table :: ('Td ?> a) => [[a]] -> 'Table > ['Tr > ['Td > a]]>>>
table [["A","B"],["C"]]
<table><tr><td>A<td>B<tr><td>C</table>>>>
import Data.Char
>>>
html_ . body_ . table $ map (\c -> [[c], show $ ord c]) ['a'..'d']
<html><body><table><tr><td>a<td>97<tr><td>b<td>98<tr><td>c<td>99<tr><td>d<td>100</table></body></html>
And here's an example module
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE DataKinds #-} module Main where import Html import qualified Html.Attribute as A main :: IO () main = print . page $ map td_ [1..(10::Int)] page :: 'Tr ?> a => a -> 'Div :> ( 'Div > [Char] # 'Div > [Char] # 'Table > 'Tr > a ) page tds = div_A [A.class_ "qux", A.id_ "baz"] ( div_ "foo" # div_ "bar" # table_ (tr_ tds) )
Please note that the type of page is inferable, so ask ghc-mod or whatever you use to write it for you. If you choose not to write the types, you don't need the language extensions.
All text will be automatically html escaped:
>>>
i_ "&"
<i>&</i>
>>>
div_A [A.id_ ">"] ()
<div id=">"></div>
If you want to opt out, wrap your types into the Raw
constructor. This will increase performance, but can be only used with
trusted input. You can use this e.g. to embed some blaze-html code
into type-of-html.
>>>
i_ (Raw "</i><script></script><i>")
<i></i><script></script><i></i>
Last and fast: performance!
Don't look any further, there is no option for faster html generation. type-of-html is up to 10 times faster than blaze-html, which was until now the fastest generation library and the foundation block of lucid and shakespeare.
Wait! 10 times faster? How is this possible? We supercompile lots of parts of the generation process. This is possible thanks to the new features of GHC 8.2: AppendSymbol. We represent tags as kinds and remove according to the html specification omittable closing tags with type families. Afterwards we map these tags to (a :: [Symbol]) and then fold all neighbouring Proxies with AppendSymbol. Afterwards we retrieve the Proxies with symbolVal which will be embedded in the executable as CString. All this happens at compile time. At runtime we do only generate the content and mconcat.
For example, if you write:
renderText $ tr_ (td_ "test")
The compiler does optimize it to the following (we don't know at compile time if we need to escape the string):
mconcat [ Data.Text.Lazy.unpackCString# "<tr><td>"# , escape (Data.Text.Lazy.unpackCString# "test"#) , Data.Text.Lazy.unpackCString# "</tr>"#) ]
If you write
renderText $ div_ (div_ ())
The compiler does optimize it to the following:
mconcat [ Data.Text.Lazy.unpackCString# "<div><div></div></div>"# ]
Note that optional ending tags were chopped off (tr, td). This sort of compiletime optimization isn't for free, it'll increase compilation times.
- renderString :: Document a String => a -> String
- renderText :: Document a Text => a -> Text
- renderByteString :: Document a ByteString => a -> ByteString
- data (a :: Element) > b where
- data (a :: Element) :> b where
- WithAttributes :: a ?> b => [Attribute] -> b -> a :> b
- addAttributes :: a ?> b => [Attribute] -> (a > b) -> a :> b
- data a # b = (:#:) a b
- (#) :: a -> b -> a # b
- type family (a :: Element) ?> b :: Constraint where ...
- newtype Raw a = Raw a
- class Convert a where
- data Converted a
- data Attribute
- data Element
- = DOCTYPE
- | A
- | Abbr
- | Acronym
- | Address
- | Applet
- | Area
- | Article
- | Aside
- | Audio
- | B
- | Base
- | Basefont
- | Bdi
- | Bdo
- | Bgsound
- | Big
- | Blink
- | Blockquote
- | Body
- | Br
- | Button
- | Canvas
- | Caption
- | Center
- | Cite
- | Code
- | Col
- | Colgroup
- | Command
- | Content
- | Data
- | Datalist
- | Dd
- | Del
- | Details
- | Dfn
- | Dialog
- | Dir
- | Div
- | Dl
- | Dt
- | Element
- | Em
- | Embed
- | Fieldset
- | Figcaption
- | Figure
- | Font
- | Footer
- | Form
- | Frame
- | Frameset
- | H1
- | H2
- | H3
- | H4
- | H5
- | H6
- | Head
- | Header
- | Hgroup
- | Hr
- | Html
- | I
- | Iframe
- | Image
- | Img
- | Input
- | Ins
- | Isindex
- | Kbd
- | Keygen
- | Label
- | Legend
- | Li
- | Link
- | Listing
- | Main
- | Map
- | Mark
- | Marquee
- | Math
- | Menu
- | Menuitem
- | Meta
- | Meter
- | Multicol
- | Nav
- | Nextid
- | Nobr
- | Noembed
- | Noframes
- | Noscript
- | Object
- | Ol
- | Optgroup
- | Option
- | Output
- | P
- | Param
- | Picture
- | Plaintext
- | Pre
- | Progress
- | Q
- | Rp
- | Rt
- | Rtc
- | Ruby
- | S
- | Samp
- | Script
- | Section
- | Select
- | Shadow
- | Slot
- | Small
- | Source
- | Spacer
- | Span
- | Strike
- | Strong
- | Style
- | Sub
- | Summary
- | Sup
- | Svg
- | Table
- | Tbody
- | Td
- | Template
- | Textarea
- | Tfoot
- | Th
- | Thead
- | Time
- | Title
- | Tr
- | Track
- | Tt
- | U
- | Ul
- | Var
- | Video
- | Wbr
- | Xmp
- doctype_ :: DOCTYPE > ()
- a_ :: A ?> a => a -> A > a
- a_A :: A ?> a => [Attribute] -> a -> A :> a
- abbr_ :: Abbr ?> a => a -> Abbr > a
- abbr_A :: Abbr ?> a => [Attribute] -> a -> Abbr :> a
- acronym_ :: Acronym ?> a => a -> Acronym > a
- acronym_A :: Acronym ?> a => [Attribute] -> a -> Acronym :> a
- address_ :: Address ?> a => a -> Address > a
- address_A :: Address ?> a => [Attribute] -> a -> Address :> a
- applet_ :: Applet ?> a => a -> Applet > a
- applet_A :: Applet ?> a => [Attribute] -> a -> Applet :> a
- area_ :: Area > ()
- area_A :: [Attribute] -> Area :> ()
- article_ :: Article ?> a => a -> Article > a
- article_A :: Article ?> a => [Attribute] -> a -> Article :> a
- aside_ :: Aside ?> a => a -> Aside > a
- aside_A :: Aside ?> a => [Attribute] -> a -> Aside :> a
- audio_ :: Audio ?> a => a -> Audio > a
- audio_A :: Audio ?> a => [Attribute] -> a -> Audio :> a
- b_ :: B ?> a => a -> B > a
- b_A :: B ?> a => [Attribute] -> a -> B :> a
- base_ :: Base > ()
- base_A :: [Attribute] -> Base :> ()
- basefont_ :: Basefont ?> a => a -> Basefont > a
- basefont_A :: Basefont ?> a => [Attribute] -> a -> Basefont :> a
- bdi_ :: Bdi ?> a => a -> Bdi > a
- bdi_A :: Bdi ?> a => [Attribute] -> a -> Bdi :> a
- bdo_ :: Bdo ?> a => a -> Bdo > a
- bdo_A :: Bdo ?> a => [Attribute] -> a -> Bdo :> a
- bgsound_ :: Bgsound ?> a => a -> Bgsound > a
- bgsound_A :: Bgsound ?> a => [Attribute] -> a -> Bgsound :> a
- big_ :: Big ?> a => a -> Big > a
- big_A :: Big ?> a => [Attribute] -> a -> Big :> a
- blink_ :: Blink ?> a => a -> Blink > a
- blink_A :: Blink ?> a => [Attribute] -> a -> Blink :> a
- blockquote_ :: Blockquote ?> a => a -> Blockquote > a
- blockquote_A :: Blockquote ?> a => [Attribute] -> a -> Blockquote :> a
- body_ :: Body ?> a => a -> Body > a
- body_A :: Body ?> a => [Attribute] -> a -> Body :> a
- br_ :: Br > ()
- br_A :: [Attribute] -> Br :> ()
- button_ :: Button ?> a => a -> Button > a
- button_A :: Button ?> a => [Attribute] -> a -> Button :> a
- canvas_ :: Canvas ?> a => a -> Canvas > a
- canvas_A :: Canvas ?> a => [Attribute] -> a -> Canvas :> a
- caption_ :: Caption ?> a => a -> Caption > a
- caption_A :: Caption ?> a => [Attribute] -> a -> Caption :> a
- center_ :: Center ?> a => a -> Center > a
- center_A :: Center ?> a => [Attribute] -> a -> Center :> a
- cite_ :: Cite ?> a => a -> Cite > a
- cite_A :: Cite ?> a => [Attribute] -> a -> Cite :> a
- code_ :: Code ?> a => a -> Code > a
- code_A :: Code ?> a => [Attribute] -> a -> Code :> a
- col_ :: Col > ()
- col_A :: [Attribute] -> Col :> ()
- colgroup_ :: Colgroup ?> a => a -> Colgroup > a
- colgroup_A :: Colgroup ?> a => [Attribute] -> a -> Colgroup :> a
- command_ :: Command ?> a => a -> Command > a
- command_A :: Command ?> a => [Attribute] -> a -> Command :> a
- content_ :: Content ?> a => a -> Content > a
- content_A :: Content ?> a => [Attribute] -> a -> Content :> a
- data_ :: Data ?> a => a -> Data > a
- data_A :: Data ?> a => [Attribute] -> a -> Data :> a
- datalist_ :: Datalist ?> a => a -> Datalist > a
- datalist_A :: Datalist ?> a => [Attribute] -> a -> Datalist :> a
- dd_ :: Dd ?> a => a -> Dd > a
- dd_A :: Dd ?> a => [Attribute] -> a -> Dd :> a
- del_ :: Del ?> a => a -> Del > a
- del_A :: Del ?> a => [Attribute] -> a -> Del :> a
- details_ :: Details ?> a => a -> Details > a
- details_A :: Details ?> a => [Attribute] -> a -> Details :> a
- dfn_ :: Dfn ?> a => a -> Dfn > a
- dfn_A :: Dfn ?> a => [Attribute] -> a -> Dfn :> a
- dialog_ :: Dialog ?> a => a -> Dialog > a
- dialog_A :: Dialog ?> a => [Attribute] -> a -> Dialog :> a
- dir_ :: Dir ?> a => a -> Dir > a
- dir_A :: Dir ?> a => [Attribute] -> a -> Dir :> a
- div_ :: Div ?> a => a -> Div > a
- div_A :: Div ?> a => [Attribute] -> a -> Div :> a
- dl_ :: Dl ?> a => a -> Dl > a
- dl_A :: Dl ?> a => [Attribute] -> a -> Dl :> a
- dt_ :: Dt ?> a => a -> Dt > a
- dt_A :: Dt ?> a => [Attribute] -> a -> Dt :> a
- element_ :: Element ?> a => a -> Element > a
- element_A :: Element ?> a => [Attribute] -> a -> Element :> a
- em_ :: Em ?> a => a -> Em > a
- em_A :: Em ?> a => [Attribute] -> a -> Em :> a
- embed_ :: Embed > ()
- embed_A :: [Attribute] -> Embed :> ()
- fieldset_ :: Fieldset ?> a => a -> Fieldset > a
- fieldset_A :: Fieldset ?> a => [Attribute] -> a -> Fieldset :> a
- figcaption_ :: Figcaption ?> a => a -> Figcaption > a
- figcaption_A :: Figcaption ?> a => [Attribute] -> a -> Figcaption :> a
- figure_ :: Figure ?> a => a -> Figure > a
- figure_A :: Figure ?> a => [Attribute] -> a -> Figure :> a
- font_ :: Font ?> a => a -> Font > a
- font_A :: Font ?> a => [Attribute] -> a -> Font :> a
- footer_ :: Footer ?> a => a -> Footer > a
- footer_A :: Footer ?> a => [Attribute] -> a -> Footer :> a
- form_ :: Form ?> a => a -> Form > a
- form_A :: Form ?> a => [Attribute] -> a -> Form :> a
- frame_ :: Frame ?> a => a -> Frame > a
- frame_A :: Frame ?> a => [Attribute] -> a -> Frame :> a
- frameset_ :: Frameset ?> a => a -> Frameset > a
- frameset_A :: Frameset ?> a => [Attribute] -> a -> Frameset :> a
- h1_ :: H1 ?> a => a -> H1 > a
- h1_A :: H1 ?> a => [Attribute] -> a -> H1 :> a
- h2_ :: H2 ?> a => a -> H2 > a
- h2_A :: H2 ?> a => [Attribute] -> a -> H2 :> a
- h3_ :: H3 ?> a => a -> H3 > a
- h3_A :: H3 ?> a => [Attribute] -> a -> H3 :> a
- h4_ :: H4 ?> a => a -> H4 > a
- h4_A :: H4 ?> a => [Attribute] -> a -> H4 :> a
- h5_ :: H5 ?> a => a -> H5 > a
- h5_A :: H5 ?> a => [Attribute] -> a -> H5 :> a
- h6_ :: H6 ?> a => a -> H6 > a
- h6_A :: H6 ?> a => [Attribute] -> a -> H6 :> a
- head_ :: Head ?> a => a -> Head > a
- head_A :: Head ?> a => [Attribute] -> a -> Head :> a
- header_ :: Header ?> a => a -> Header > a
- header_A :: Header ?> a => [Attribute] -> a -> Header :> a
- hgroup_ :: Hgroup ?> a => a -> Hgroup > a
- hgroup_A :: Hgroup ?> a => [Attribute] -> a -> Hgroup :> a
- hr_ :: Hr > ()
- hr_A :: [Attribute] -> Hr :> ()
- html_ :: Html ?> a => a -> Html > a
- html_A :: Html ?> a => [Attribute] -> a -> Html :> a
- i_ :: I ?> a => a -> I > a
- i_A :: I ?> a => [Attribute] -> a -> I :> a
- iframe_ :: Iframe > ()
- iframe_A :: [Attribute] -> Iframe :> ()
- image_ :: Image ?> a => a -> Image > a
- image_A :: Image ?> a => [Attribute] -> a -> Image :> a
- img_ :: Img > ()
- img_A :: [Attribute] -> Img :> ()
- input_ :: Input ?> a => a -> Input > a
- input_A :: Input ?> a => [Attribute] -> a -> Input :> a
- ins_ :: Ins ?> a => a -> Ins > a
- ins_A :: Ins ?> a => [Attribute] -> a -> Ins :> a
- isindex_ :: Isindex ?> a => a -> Isindex > a
- isindex_A :: Isindex ?> a => [Attribute] -> a -> Isindex :> a
- kbd_ :: Kbd ?> a => a -> Kbd > a
- kbd_A :: Kbd ?> a => [Attribute] -> a -> Kbd :> a
- keygen_ :: Keygen ?> a => a -> Keygen > a
- keygen_A :: Keygen ?> a => [Attribute] -> a -> Keygen :> a
- label_ :: Label ?> a => a -> Label > a
- label_A :: Label ?> a => [Attribute] -> a -> Label :> a
- legend_ :: Legend ?> a => a -> Legend > a
- legend_A :: Legend ?> a => [Attribute] -> a -> Legend :> a
- li_ :: Li ?> a => a -> Li > a
- li_A :: Li ?> a => [Attribute] -> a -> Li :> a
- link_ :: Link > ()
- link_A :: [Attribute] -> Link :> ()
- listing_ :: Listing ?> a => a -> Listing > a
- listing_A :: Listing ?> a => [Attribute] -> a -> Listing :> a
- main_ :: Main ?> a => a -> Main > a
- main_A :: Main ?> a => [Attribute] -> a -> Main :> a
- map_ :: Map ?> a => a -> Map > a
- map_A :: Map ?> a => [Attribute] -> a -> Map :> a
- mark_ :: Mark ?> a => a -> Mark > a
- mark_A :: Mark ?> a => [Attribute] -> a -> Mark :> a
- marquee_ :: Marquee ?> a => a -> Marquee > a
- marquee_A :: Marquee ?> a => [Attribute] -> a -> Marquee :> a
- math_ :: Math ?> a => a -> Math > a
- math_A :: Math ?> a => [Attribute] -> a -> Math :> a
- menu_ :: Menu ?> a => a -> Menu > a
- menu_A :: Menu ?> a => [Attribute] -> a -> Menu :> a
- menuitem_ :: Menuitem > ()
- menuitem_A :: [Attribute] -> Menuitem :> ()
- meta_ :: Meta > ()
- meta_A :: [Attribute] -> Meta :> ()
- meter_ :: Meter ?> a => a -> Meter > a
- meter_A :: Meter ?> a => [Attribute] -> a -> Meter :> a
- multicol_ :: Multicol ?> a => a -> Multicol > a
- multicol_A :: Multicol ?> a => [Attribute] -> a -> Multicol :> a
- nav_ :: Nav ?> a => a -> Nav > a
- nav_A :: Nav ?> a => [Attribute] -> a -> Nav :> a
- nextid_ :: Nextid ?> a => a -> Nextid > a
- nextid_A :: Nextid ?> a => [Attribute] -> a -> Nextid :> a
- nobr_ :: Nobr ?> a => a -> Nobr > a
- nobr_A :: Nobr ?> a => [Attribute] -> a -> Nobr :> a
- noembed_ :: Noembed ?> a => a -> Noembed > a
- noembed_A :: Noembed ?> a => [Attribute] -> a -> Noembed :> a
- noframes_ :: Noframes ?> a => a -> Noframes > a
- noframes_A :: Noframes ?> a => [Attribute] -> a -> Noframes :> a
- noscript_ :: Noscript ?> a => a -> Noscript > a
- noscript_A :: Noscript ?> a => [Attribute] -> a -> Noscript :> a
- object_ :: Object ?> a => a -> Object > a
- object_A :: Object ?> a => [Attribute] -> a -> Object :> a
- ol_ :: Ol ?> a => a -> Ol > a
- ol_A :: Ol ?> a => [Attribute] -> a -> Ol :> a
- optgroup_ :: Optgroup ?> a => a -> Optgroup > a
- optgroup_A :: Optgroup ?> a => [Attribute] -> a -> Optgroup :> a
- option_ :: Option ?> a => a -> Option > a
- option_A :: Option ?> a => [Attribute] -> a -> Option :> a
- output_ :: Output ?> a => a -> Output > a
- output_A :: Output ?> a => [Attribute] -> a -> Output :> a
- p_ :: P ?> a => a -> P > a
- p_A :: P ?> a => [Attribute] -> a -> P :> a
- param_ :: Param > ()
- param_A :: [Attribute] -> Param :> ()
- picture_ :: Picture ?> a => a -> Picture > a
- picture_A :: Picture ?> a => [Attribute] -> a -> Picture :> a
- plaintext_ :: Plaintext ?> a => a -> Plaintext > a
- plaintext_A :: Plaintext ?> a => [Attribute] -> a -> Plaintext :> a
- pre_ :: Pre ?> a => a -> Pre > a
- pre_A :: Pre ?> a => [Attribute] -> a -> Pre :> a
- progress_ :: Progress ?> a => a -> Progress > a
- progress_A :: Progress ?> a => [Attribute] -> a -> Progress :> a
- q_ :: Q ?> a => a -> Q > a
- q_A :: Q ?> a => [Attribute] -> a -> Q :> a
- rp_ :: Rp ?> a => a -> Rp > a
- rp_A :: Rp ?> a => [Attribute] -> a -> Rp :> a
- rt_ :: Rt ?> a => a -> Rt > a
- rt_A :: Rt ?> a => [Attribute] -> a -> Rt :> a
- rtc_ :: Rtc ?> a => a -> Rtc > a
- rtc_A :: Rtc ?> a => [Attribute] -> a -> Rtc :> a
- ruby_ :: Ruby ?> a => a -> Ruby > a
- ruby_A :: Ruby ?> a => [Attribute] -> a -> Ruby :> a
- s_ :: S ?> a => a -> S > a
- s_A :: S ?> a => [Attribute] -> a -> S :> a
- samp_ :: Samp ?> a => a -> Samp > a
- samp_A :: Samp ?> a => [Attribute] -> a -> Samp :> a
- script_ :: Script ?> a => a -> Script > a
- script_A :: Script ?> a => [Attribute] -> a -> Script :> a
- section_ :: Section ?> a => a -> Section > a
- section_A :: Section ?> a => [Attribute] -> a -> Section :> a
- select_ :: Select ?> a => a -> Select > a
- select_A :: Select ?> a => [Attribute] -> a -> Select :> a
- shadow_ :: Shadow ?> a => a -> Shadow > a
- shadow_A :: Shadow ?> a => [Attribute] -> a -> Shadow :> a
- slot_ :: Slot ?> a => a -> Slot > a
- slot_A :: Slot ?> a => [Attribute] -> a -> Slot :> a
- small_ :: Small ?> a => a -> Small > a
- small_A :: Small ?> a => [Attribute] -> a -> Small :> a
- source_ :: Source > ()
- source_A :: [Attribute] -> Source :> ()
- spacer_ :: Spacer ?> a => a -> Spacer > a
- spacer_A :: Spacer ?> a => [Attribute] -> a -> Spacer :> a
- span_ :: Span ?> a => a -> Span > a
- span_A :: Span ?> a => [Attribute] -> a -> Span :> a
- strike_ :: Strike ?> a => a -> Strike > a
- strike_A :: Strike ?> a => [Attribute] -> a -> Strike :> a
- strong_ :: Strong ?> a => a -> Strong > a
- strong_A :: Strong ?> a => [Attribute] -> a -> Strong :> a
- style_ :: Style ?> a => a -> Style > a
- style_A :: Style ?> a => [Attribute] -> a -> Style :> a
- sub_ :: Sub ?> a => a -> Sub > a
- sub_A :: Sub ?> a => [Attribute] -> a -> Sub :> a
- summary_ :: Summary ?> a => a -> Summary > a
- summary_A :: Summary ?> a => [Attribute] -> a -> Summary :> a
- sup_ :: Sup ?> a => a -> Sup > a
- sup_A :: Sup ?> a => [Attribute] -> a -> Sup :> a
- svg_ :: Svg ?> a => a -> Svg > a
- svg_A :: Svg ?> a => [Attribute] -> a -> Svg :> a
- table_ :: Table ?> a => a -> Table > a
- table_A :: Table ?> a => [Attribute] -> a -> Table :> a
- tbody_ :: Tbody ?> a => a -> Tbody > a
- tbody_A :: Tbody ?> a => [Attribute] -> a -> Tbody :> a
- td_ :: Td ?> a => a -> Td > a
- td_A :: Td ?> a => [Attribute] -> a -> Td :> a
- template_ :: Template ?> a => a -> Template > a
- template_A :: Template ?> a => [Attribute] -> a -> Template :> a
- textarea_ :: Textarea ?> a => a -> Textarea > a
- textarea_A :: Textarea ?> a => [Attribute] -> a -> Textarea :> a
- tfoot_ :: Tfoot ?> a => a -> Tfoot > a
- tfoot_A :: Tfoot ?> a => [Attribute] -> a -> Tfoot :> a
- th_ :: Th ?> a => a -> Th > a
- th_A :: Th ?> a => [Attribute] -> a -> Th :> a
- thead_ :: Thead ?> a => a -> Thead > a
- thead_A :: Thead ?> a => [Attribute] -> a -> Thead :> a
- time_ :: Time ?> a => a -> Time > a
- time_A :: Time ?> a => [Attribute] -> a -> Time :> a
- title_ :: Title ?> a => a -> Title > a
- title_A :: Title ?> a => [Attribute] -> a -> Title :> a
- tr_ :: Tr ?> a => a -> Tr > a
- tr_A :: Tr ?> a => [Attribute] -> a -> Tr :> a
- track_ :: Track > ()
- track_A :: [Attribute] -> Track :> ()
- tt_ :: Tt ?> a => a -> Tt > a
- tt_A :: Tt ?> a => [Attribute] -> a -> Tt :> a
- u_ :: U ?> a => a -> U > a
- u_A :: U ?> a => [Attribute] -> a -> U :> a
- ul_ :: Ul ?> a => a -> Ul > a
- ul_A :: Ul ?> a => [Attribute] -> a -> Ul :> a
- var_ :: Var ?> a => a -> Var > a
- var_A :: Var ?> a => [Attribute] -> a -> Var :> a
- video_ :: Video ?> a => a -> Video > a
- video_A :: Video ?> a => [Attribute] -> a -> Video :> a
- wbr_ :: Wbr > ()
- wbr_A :: [Attribute] -> Wbr :> ()
- xmp_ :: Xmp ?> a => a -> Xmp > a
- xmp_A :: Xmp ?> a => [Attribute] -> a -> Xmp :> a
Documentation
renderString :: Document a String => a -> String Source #
Render a html document to a String.
renderText :: Document a Text => a -> Text Source #
Render a html document to a lazy Text.
renderByteString :: Document a ByteString => a -> ByteString Source #
Render a html document to a lazy ByteString.
data (a :: Element) > b where infixr 8 Source #
Descend to a valid child of an element. It is recommended to use the predefined elements.
>>>
Child "a" :: 'Div > String
<div>a</div>
>>>
div_ "a"
<div>a</div>
data (a :: Element) :> b where infixr 8 Source #
Decorate an element with attributes and descend to a valid child.
>>>
WithAttributes [A.class_ "bar"] "a" :: 'Div :> String
<div class="bar">a</div>
WithAttributes :: a ?> b => [Attribute] -> b -> a :> b |
Combine two elements sequentially.
>>>
render (i_ () # div_ ()) :: String
"<i></i><div></div>"
(:#:) a b |
type family (a :: Element) ?> b :: Constraint where ... Source #
Check whether b
is a valid child of a
. You'll propably never
need to call this directly. Through a GADT, it is enforced that
every child is lawful.
The only way to circumvent this would be to use undefined
or
error
in combination with only type level values.
>>>
undefined :: 'Div > ('Html > ())
<div><html></html></div>
>>>
undefined :: 'Div > ('Html > Proxy "a")
<div><html>a</html></div>
>>>
undefined :: 'Div > ('Html > String)
<div><html>*** Exception: Prelude.undefined
a ?> (b # c) = (a ?> b, a ?> c) | |
a ?> (b > _) = MaybeTypeError a b (TestPaternity (SingleElement b) (GetInfo a) (GetInfo b)) | |
a ?> (b :> _) = MaybeTypeError a b (TestPaternity (SingleElement b) (GetInfo a) (GetInfo b)) | |
a ?> (Maybe b) = a ?> b | |
a ?> (Either b c) = (a ?> b, a ?> c) | |
a ?> (f (b > c)) = a ?> (b > c) | |
a ?> (f (b :> c)) = a ?> (b > c) | |
a ?> (f (b # c)) = a ?> (b # c) | |
a ?> () = () | |
a ?> (b -> c) = TypeError (Text "Html elements can't contain functions") | |
a ?> b = CheckString a |
Wrapper for types which won't be escaped.
Raw a |
class Convert a where Source #
Convert a type efficienctly to different string like types. Add instances if you want use custom types in your document.
{-# LANGUAGE RecordWildCards #-} module Main where import Html data Person = Person { name :: String , age :: Int , vegetarian :: Bool } -- | This is not efficient, but understandable. -- The call to convertText is needed for escaping. -- This is enforced by a newtype. Wrap it in Raw if you don't want to escape. instance Convert Person where convertText (Person{..}) = convertText $ name ++ " is " ++ show age ++ " years old and likes " ++ if vegetarian then "oranges." else "meat." john :: Person john = Person {name = John, age = 52, vegetarian = True} main :: IO () main = print (div_ john)
convertString :: a -> Converted String Source #
convertText :: a -> Converted Text Source #
convertByteString :: a -> Converted ByteString Source #
Convert Double Source # | |
Convert Float Source # | |
Convert Int Source # | |
Convert Integer Source # | |
Convert Word Source # | |
Convert String Source # | |
Convert Text Source # | |
Convert (Raw String) Source # | |
Convert (Raw ByteString) Source # | |
Convert (Raw Text) Source # | |
KnownSymbol a => Convert (Proxy Symbol a) Source # | |
The data type of all html elements and the kind of elements.
DOCTYPE | |
A | |
Abbr | |
Acronym | Deprecated: This is an obsolete html element and should not be used. |
Address | |
Applet | Deprecated: This is an obsolete html element and should not be used. |
Area | |
Article | |
Aside | |
Audio | |
B | |
Base | |
Basefont | Deprecated: This is an obsolete html element and should not be used. |
Bdi | |
Bdo | |
Bgsound | |
Big | Deprecated: This is an obsolete html element and should not be used. |
Blink | Deprecated: This is an obsolete html element and should not be used. |
Blockquote | |
Body | |
Br | |
Button | |
Canvas | |
Caption | |
Center | Deprecated: This is an obsolete html element and should not be used. |
Cite | |
Code | |
Col | |
Colgroup | |
Command | Deprecated: This is an obsolete html element and should not be used. |
Content | Deprecated: This is an obsolete html element and should not be used. |
Data | |
Datalist | |
Dd | |
Del | |
Details | |
Dfn | |
Dialog | |
Dir | Deprecated: This is an obsolete html element and should not be used. |
Div | |
Dl | |
Dt | |
Element | |
Em | |
Embed | |
Fieldset | |
Figcaption | |
Figure | |
Font | Deprecated: This is an obsolete html element and should not be used. |
Footer | |
Form | |
Frame | Deprecated: This is an obsolete html element and should not be used. |
Frameset | Deprecated: This is an obsolete html element and should not be used. |
H1 | |
H2 | |
H3 | |
H4 | |
H5 | |
H6 | |
Head | |
Header | |
Hgroup | |
Hr | |
Html | |
I | |
Iframe | |
Image | |
Img | |
Input | |
Ins | |
Isindex | Deprecated: This is an obsolete html element and should not be used. |
Kbd | |
Keygen | Deprecated: This is an obsolete html element and should not be used. |
Label | |
Legend | |
Li | |
Link | |
Listing | Deprecated: This is an obsolete html element and should not be used. |
Main | |
Map | |
Mark | |
Marquee | Deprecated: This is an obsolete html element and should not be used. |
Math | |
Menu | |
Menuitem | |
Meta | |
Meter | |
Multicol | Deprecated: This is an obsolete html element and should not be used. |
Nav | |
Nextid | Deprecated: This is an obsolete html element and should not be used. |
Nobr | |
Noembed | Deprecated: This is an obsolete html element and should not be used. |
Noframes | |
Noscript | |
Object | |
Ol | |
Optgroup | |
Option | |
Output | |
P | |
Param | |
Picture | |
Plaintext | Deprecated: This is an obsolete html element and should not be used. |
Pre | |
Progress | |
Q | |
Rp | |
Rt | |
Rtc | |
Ruby | |
S | |
Samp | |
Script | |
Section | |
Select | |
Shadow | Deprecated: This is an obsolete html element and should not be used. |
Slot | |
Small | |
Source | |
Spacer | Deprecated: This is an obsolete html element and should not be used. |
Span | |
Strike | Deprecated: This is an obsolete html element and should not be used. |
Strong | |
Style | |
Sub | |
Summary | |
Sup | |
Svg | |
Table | |
Tbody | |
Td | |
Template | |
Textarea | |
Tfoot | |
Th | |
Thead | |
Time | |
Title | |
Tr | |
Track | |
Tt | Deprecated: This is an obsolete html element and should not be used. |
U | |
Ul | |
Var | |
Video | |
Wbr | |
Xmp | Deprecated: This is an obsolete html element and should not be used. |
blockquote_ :: Blockquote ?> a => a -> Blockquote > a Source #
blockquote_A :: Blockquote ?> a => [Attribute] -> a -> Blockquote :> a Source #
figcaption_ :: Figcaption ?> a => a -> Figcaption > a Source #
figcaption_A :: Figcaption ?> a => [Attribute] -> a -> Figcaption :> a Source #
Orphan instances
Document ((:>) a b) String => Show [(:>) a b] Source # | |
Document ((>) a b) String => Show [(>) a b] Source # | |
Document ((#) a b) String => Show [(#) a b] Source # | |
Document ((:>) a b) String => Show ((:>) a b) Source # | |
Document ((>) a b) String => Show ((>) a b) Source # | Orphan show instances to faciliate ghci development. |
Document ((#) a b) String => Show ((#) a b) Source # | |