项目作者: naglalakk

项目描述 :
Halogen 5 component for rendering Raw HTML from String
高级语言: Dhall
项目地址: git://github.com/naglalakk/purescript-halogen-rawhtml.git
创建时间: 2019-06-12T16:08:57Z
项目社区:https://github.com/naglalakk/purescript-halogen-rawhtml

开源协议:

下载


purescript-halogen-rawhtml

Dead simple component for rendering Raw HTML in Halogen views.

Warning

This component injects raw html into your view without any validation of the HTML being injected whatsoever. Use this only if you trust the source of HTML being used. For this reason this package is not published as an official library but is more a demonstration of how you can use raw html within your Halogen component.

Note

This component is written for Halogen 5.
For Halogen 4 see this snippet for a similar implementation in Halogen 4

How to use

  1. import Halogen.Component.RawHTML as RawHTML
  2. render :: State -> H.ComponentHTML Action ChildSlots m
  3. render state =
  4. HH.div
  5. []
  6. [ HH.h1
  7. []
  8. [ HH.text "Testing raw html" ]
  9. , HH.slot (SProxy :: _ "r") unit RawHTML.component { html: "<p> test </p>", elRef: "testDiv" } absurd
  10. ]

RawHTML Component takes an Input of type

  1. type Input =
  2. { html :: String
  3. , elRef :: String
  4. }

where html is a HTML string you want to render and elRef is a unique identifier of the element used to contain the HTML.

Example code

Run

  1. make example

Now navigate to localhost:8080/example/ in your browser.
The page should display the following HTML

  1. <h1> Testing raw html </h1>
  2. <p> This should be enclosed within a 'p' tag </p>