Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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: 2 months ago
JSON representation

Parse HTML in Elm!

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. `

  • ` does not need a closing tag). Also, it uses the official parser `elm/parser` which I was planning to use in the newer version. So I think contributing to `hecrj/html-parser` is the fastest path for everyone getting happy :)

    # elm-html-parser

    [![Build Status](https://travis-ci.org/jinjor/elm-html-parser.svg)](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