Skip to content

Latest commit

 

History

History
74 lines (55 loc) · 1.89 KB

README.md

File metadata and controls

74 lines (55 loc) · 1.89 KB

lib.html

Language: TypeScript GitHub license JSR badge GitHub issues

An HTML AST, parser, and writer library written in TypeScript.

Example

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();

Usage

Deno

Add the library from JSR:

deno add @lambdaurora/libhtml

Then import it:

import * as html from "@lambdaurora/libhtml";

Web

Import the library using esm.sh:

import * as html from "https://esm.sh/jsr/@lambdaurora/libhtml@1.3.2";