jims / html-parser / Html.Parser

Parse HTML 5 in Elm. See https://www.w3.org/TR/html5/syntax.html

run : String -> Result (List Parser.DeadEnd) (List Node)

Run the parser!

run "<div><p>Hello, world!</p></div>"
-- => Ok [ Element "div" [] [ Element "p" [] [ Text "Hello, world!" ] ] ]


type Node
    = Text String
    | Element String (List Attribute) (List Node)
    | Comment String

An HTML node. It can either be:


type alias Attribute =
( String, String )

An HTML attribute. For instance:

( "href", "https://elm-lang.org" )

Internals

If you are building a parser of your own using elm/parser and you need to parse HTML... This section is for you!

node : Parser Node

Parse an HTML node.

You can use this in your own parser to add support for HTML 5.

nodeToString : Node -> String

Turn a parser node back into its HTML string.

For instance:

Element "a"
    [ ( "href", "https://elm-lang.org" ) ]
    [ Text "Elm" ]
    |> nodeToString

Produces <a href="https://elm-lang.org">Elm</a>.