An HTML AST, parser, and writer library written in TypeScript.
import * as html from "@lambdaurora/libhtml";
const div = html.parse(`<div>
<h1>Hello World!</h1>
<p>
This is a lovely HTML source.
</p>
</div>`) as html.Element;
div.get_element_by_tag_name("h1").text // Hello World!
const alert = html.create_element("div")
.with_child(html.create_element("h1")
.with_child("Alert: this is a lovely day!")
).with_child(html.create_element("p")
.with_child("Have a good day!")
);
const html_string = alert.html();
const dialog = html.dialog({
children: [
html.h1(["Hello world!"]),
html.p(["I hope you have a wonderful day!"]),
html.button(["Thank you"])
],
attributes: {
open: ""
}
});
const other_html_string = dialog.html();
Add the library from JSR:
deno add @lambdaurora/libhtml
Then import it:
import * as html from "@lambdaurora/libhtml";
Import the library using esm.sh:
import * as html from "https://esm.sh/jsr/@lambdaurora/libhtml@1.3.2";