diff --git a/IHP/ViewSupport.hs b/IHP/ViewSupport.hs index 93d9e9fde..7340b0c6e 100644 --- a/IHP/ViewSupport.hs +++ b/IHP/ViewSupport.hs @@ -27,6 +27,7 @@ module IHP.ViewSupport , query , isActiveController , renderFlashMessages +, nl2br ) where import IHP.Prelude @@ -47,6 +48,8 @@ import Text.Blaze.Html5.Attributes as A import qualified IHP.ControllerSupport as ControllerSupport import qualified IHP.Controller.Session as Session import IHP.HtmlSupport.QQ (hsx) +import IHP.HtmlSupport.ToHtml +import qualified Data.Sequences as Sequences type HtmlWithContext context = (?viewContext :: context) => Html5.Html @@ -310,4 +313,14 @@ renderFlashMessages = renderFlashMessage (Session.SuccessFlashMessage message) = [hsx|
{message}
|] renderFlashMessage (Session.ErrorFlashMessage message) = [hsx|
{message}
|] in - forEach flashMessages renderFlashMessage \ No newline at end of file + forEach flashMessages renderFlashMessage + +-- | Replaces all newline characters with a @
@ tag. Useful for displaying preformatted text. +-- +-- >>> nl2br "Hello\nWorld!" +-- [hsx|Hello
World!|] +nl2br :: (Sequences.Textual text, ToHtml text) => text -> Html5.Html +nl2br content = content + |> Sequences.lines + |> map (\line -> [hsx|{line}
|]) + |> mconcat \ No newline at end of file diff --git a/ihp.cabal b/ihp.cabal index a204acd71..0e262fa06 100644 --- a/ihp.cabal +++ b/ihp.cabal @@ -17,6 +17,7 @@ common shared-properties build-depends: base , classy-prelude + , mono-traversable , directory , string-conversions , warp