Home

Awesome

javascript_dom_parser

Bindings to the JavaScript DOMParser API.

Package Version Hex Docs

gleam add javascript_dom_parser
import javascript_dom_parser

pub fn main() {
  let html = "
<!doctype html>
<html lang=en>
<head>
  <title>Hi!</title>
</head>
<body>
  <p style='color: #ffaff3'>How are you?</p>
  <!-- Wooo coding! -->
</body>
</html>
"
  javascript_dom_parser.parse_to_records(html)
}

This function will return a data structure like so:

Element("HTML", [#("lang", "en")], [
  Element("HEAD", [], [
    Text("\n  "),
    Element("TITLE", [], [Text("Hi!")]),
    Text("\n"),
  ]),
  Text("\n"),
  Element("BODY", [], [
    Text("\n  "),
    Element("P", [#("style", "color: #ffaff3")], [Text("How are you?")]),
    Text("\n  "),
    Comment(" Wooo coding! "),
    Text("\n\n"),
  ]),
])

Further documentation can be found at https://hexdocs.pm/javascript_dom_parser.