├── .github
└── workflows
│ └── gh-pages.yml
├── .gitignore
├── LICENSE
├── README.md
├── babel.config.js
├── bower.json
├── example
├── .gitignore
├── LICENSE
├── README.md
├── bower.json
├── package.json
├── spago.dhall
├── src
│ ├── App.purs
│ ├── Main.purs
│ ├── index.html
│ └── index.js
└── webpack.config.js
├── jest.config.js
├── package.json
├── packages.dhall
├── spago.dhall
├── src
└── Html
│ ├── Parser.js
│ ├── Parser.purs
│ └── Renderer
│ └── Halogen.purs
└── test
├── Main.purs
└── main.test.js
/.github/workflows/gh-pages.yml:
--------------------------------------------------------------------------------
1 | name: Publish gh-pages
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 |
8 | jobs:
9 | build:
10 | runs-on: ubuntu-latest
11 | steps:
12 | - uses: actions/checkout@v2
13 | - name: Setup node
14 | uses: actions/setup-node@v1
15 | with:
16 | node-version: 14
17 | - name: Build
18 | run: |
19 | cd example
20 | yarn add purescript@0.15 spago
21 | yarn build
22 | - name: Publish
23 | run: |
24 | cp docs/* .
25 | git config user.email "remotenonsense@gmail.com"
26 | git config user.name "GHActions"
27 | git add . && git commit -am 'build gh-pages'
28 | git push -f origin HEAD:gh-pages
29 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | bower_components
2 | node_modules
3 | yarn.lock
4 |
5 | .psc-ide-port
6 | .psci_modules
7 | .purs-repl
8 | .spago
9 | output
10 | docs
11 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2018, Ping Chen
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | * Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # purescript-html-parser-halogen
2 |
3 | [](https://pursuit.purescript.org/packages/purescript-html-parser-halogen)
4 |
5 | A library to render raw HTML string into Halogen views. You might also be interested in [purescript-markdown-it-halogen](https://github.com/nonbili/purescript-markdown-it-halogen), a library to render Markdown into Halogen views.
6 |
7 | [Playground](https://rnons.github.io/purescript-html-parser-halogen/)
8 |
9 | ## How to use
10 |
11 | ```purescript
12 | import Html.Renderer.Halogen as RH
13 |
14 | rawHtml :: String
15 | rawHtml = """a link"""
16 |
17 | render =
18 | ...
19 | HH.div_ [ RH.render_ rawHtml ]
20 | ```
21 |
22 | It's as simple as this, in most cases you only need the `render` function from `Html.Renderer.Halogen` module.
23 |
24 | ## Be cautious
25 |
26 | This library doesn't support malformed HTML, and is prone to XSS attack. Use it only when you trust the HTML string.
27 |
28 | You can balance and sanitize the HTML on the backend, e.g. `sanitizeBalance` from [xss-sanitize](http://hackage.haskell.org/package/xss-sanitize/docs/Text-HTML-SanitizeXSS.html#v:sanitizeBalance).
29 |
30 | ## How it works
31 |
32 | `Html.Parser` parses HTML `String` as `HtmlNode`. `Html.Renderer.Halogen` converts `HtmlNode` to halogen `HTML`. You can also write adapters to convert `HtmlNode` to the `HTML` type of other view libraries.
33 |
34 | If you want to `Html.Parser` with other view libraries, I can release it as a separate package, let me know if you are interested.
35 |
36 | ## Other approaches to render raw HTML into halogen views
37 |
38 | - https://github.com/slamdata/purescript-halogen/issues/324
39 |
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = { presets: ["@babel/preset-env"] };
2 |
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "purescript-html-parser-halogen",
3 | "description": "A library to render HTML string into halogen views",
4 | "keywords": [
5 | "purescript",
6 | "halogen",
7 | "html"
8 | ],
9 | "repository": {
10 | "type": "git",
11 | "url": "git://github.com/rnons/purescript-html-parser-halogen.git"
12 | },
13 | "license": "BSD-3-Clause",
14 | "ignore": [
15 | "**/.*",
16 | "bower_components",
17 | "docs",
18 | "example",
19 | "node_modules",
20 | "output",
21 | "yarn.lock"
22 | ],
23 | "dependencies": {
24 | "purescript-string-parsers": "^6.0.0",
25 | "purescript-halogen": "^6.1.0"
26 | },
27 | "devDependencies": {
28 | "purescript-psci-support": "^5.0.0",
29 | "purescript-debug": "^5.0.0"
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | /bower_components/
2 | /node_modules/
3 | /.pulp-cache/
4 | /output/
5 | /generated-docs/
6 | /.psc-package/
7 | /.psc*
8 | /.purs*
9 | /.psa*
10 |
--------------------------------------------------------------------------------
/example/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2018, Ping Chen
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | * Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/example/README.md:
--------------------------------------------------------------------------------
1 | ```
2 | yarn
3 | spago build -w
4 | yarn start
5 | ```
6 |
--------------------------------------------------------------------------------
/example/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "private": true,
4 | "ignore": [
5 | "**/.*",
6 | "node_modules",
7 | "bower_components",
8 | "output"
9 | ],
10 | "dependencies": {
11 | "purescript-string-parsers": "^6.0.0",
12 | "purescript-jest": "^0.5.0",
13 | "purescript-halogen": "^6.1.0"
14 | },
15 | "devDependencies": {
16 | "purescript-psci-support": "^5.0.0"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "license": "BSD-3-Clause",
4 | "scripts": {
5 | "build": "spago build -u '+RTS -N2 -RTS' && webpack --mode production --progress",
6 | "start": "webpack-dev-server --mode development --progress"
7 | },
8 | "devDependencies": {
9 | "html-webpack-plugin": "^3.2.0",
10 | "webpack": "^4.30.0",
11 | "webpack-cli": "^3.3.1",
12 | "webpack-dev-server": "^3.3.1"
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/example/spago.dhall:
--------------------------------------------------------------------------------
1 | { name = "example"
2 | , dependencies =
3 | [ "aff"
4 | , "arrays"
5 | , "const"
6 | , "control"
7 | , "dom-indexed"
8 | , "maybe"
9 | , "prelude"
10 | , "transformers"
11 | , "effect"
12 | , "halogen"
13 | ]
14 | , packages = ../packages.dhall
15 | , sources = [ "../src/**/*.purs", "src/**/*.purs" ]
16 | }
17 |
--------------------------------------------------------------------------------
/example/src/App.purs:
--------------------------------------------------------------------------------
1 | module App where
2 |
3 | import Prelude
4 |
5 | import Control.Monad.State (class MonadState)
6 | import Data.Const (Const)
7 | import Effect.Aff.Class (class MonadAff)
8 | import Halogen as H
9 | import Halogen.HTML as HH
10 | import Halogen.HTML.Events as HE
11 | import Halogen.HTML.Properties as HP
12 | import Html.Renderer.Halogen as PH
13 |
14 | type Query :: forall k. k -> Type
15 | type Query = Const Void
16 |
17 | data Action = OnValueChange String
18 |
19 | type State = { value:: String }
20 |
21 |
22 | initValue :: String
23 | initValue = """
24 |
29 |
30 |