| 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 | Safe-Inferred |
| Language | Haskell2010 |
Miso.String.QQ
Description
Overview
Miso.String.QQ provides the misoString quasi-quoter, which lets you
write multiline MisoString literals with preserved
whitespace and indentation directly in Haskell source.
Enable the extension and import the quoter:
{-# LANGUAGE QuasiQuotes #-}
import Miso.String.QQ (misoString)
Quick start
{-# LANGUAGE QuasiQuotes #-}
import Miso.String.QQ
import Miso.String (MisoString)
-- Multiline literal — newlines and indentation are preserved as-is
myCSS :: MisoString
myCSS = [misoString|
body {
margin: 0;
font-family: sans-serif;
}
|]
-- Useful for injecting inline <style> or <script> content:
view :: Model -> View Model Action
view _ =
div_ []
[ style_ [] [ text myCSS ] ]
How it works
The quasi-quoter is expression-only (quoteExp). At compile time it
splices toMisoString <the-literal-string>, so the result is
identical to writing but without needing to
escape newlines or quotes inside the brackets.ms "…"
quotePat, quoteType, and quoteDec are not implemented and will
produce a compile error if attempted.
See also
- Miso.FFI.QQ —
[js| … |]quasi-quoter for inline JavaScript - Miso.String —
MisoString,ms,toMisoString
Synopsis
Documentation
misoString :: QuasiQuoter Source #
QuasiQuoter for specifying multiline MisoString
{-# LANGUAGE QuasiQuotes #-}
test :: MisoString
test = [misoString| foo
bar
baz
|]