https://github.com/jinjor/elm-html-parser
  
  
    Parse HTML in Elm! 
    https://github.com/jinjor/elm-html-parser
  
elm elm-html-parser parse parser
        Last synced: about 2 months ago 
        JSON representation
    
Parse HTML in Elm!
- Host: GitHub
- URL: https://github.com/jinjor/elm-html-parser
- Owner: jinjor
- License: bsd-3-clause
- Created: 2016-08-30T17:00:32.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-09-15T18:01:35.000Z (about 7 years ago)
- Last Synced: 2025-07-18T06:24:51.940Z (3 months ago)
- Topics: elm, elm-html-parser, parse, parser
- Language: Elm
- Homepage: http://package.elm-lang.org/packages/jinjor/elm-html-parser/latest
- Size: 198 KB
- Stars: 44
- Watchers: 1
- Forks: 7
- Open Issues: 4
- 
            Metadata Files:
            - Readme: README.md
- License: LICENSE
 
Awesome Lists containing this project
README
          ## Note
For anyone who is using Elm 0.19 and blocked by this library, consider using [hecrj/html-parser](https://package.elm-lang.org/packages/hecrj/html-parser/latest/) for now. It seems still WIP but passed the same test cases. I think that means the most difficult part of the HTML spec should be already covered (e.g. `
# elm-html-parser
[](https://travis-ci.org/jinjor/elm-html-parser)
Parse HTML in Elm! ([DEMO](https://jinjor.github.io/elm-html-parser/))
## Parse
```elm
import HtmlParser as HtmlParser exposing (..)
parse "text" == [ Text "text" ]
parse "
Hello
World
"
== [ Element "h1" [] [ Text "Hello", Element "br" [] [], Text "World" ] ]
parse """Example"""
  == [ Element "a" [("href", "http://example.com")] [ Text "Example" ] ]
```
## Query
```elm
import HtmlParser exposing (..)
import HtmlParser.Util exposing (..)
table = """
  
  
   
   
    1
    2
    3
   
   
    2
    3
    4
   
  
  
"""
( parse table
  |> getElementsByTagName "tr"
  |> mapElements
    (\_ _ innerTr ->
      innerTr
        |> mapElements (\_ _ innerTd -> textContent innerTd)
        |> String.join "\t"
        |> String.trim
    )
  |> String.join "\n"
) == "1\t2\t3\n2\t3\t4"
```
## LICENSE
BSD3