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

https://github.com/lambdaurora/lib.html

An HTML AST, parser, and writer library written in TypeScript.
https://github.com/lambdaurora/lib.html

ast deno html parser typescript

Last synced: about 1 month ago
JSON representation

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

Awesome Lists containing this project

README

          

# lib.html


Language: TypeScript
GitHub license
JSR badge

GitHub issues


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

## Example

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

const div = html.parse(`


Hello World!



This is a lovely HTML source.


`) 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](https://jsr.io/@lambdaurora/libhtml):

```shell
deno add @lambdaurora/libhtml
```

Then import it:

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

### Web

Import the library using [esm.sh](https://esm.sh):

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