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.
- Host: GitHub
- URL: https://github.com/lambdaurora/lib.html
- Owner: LambdAurora
- License: mpl-2.0
- Created: 2024-05-20T12:55:27.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-21T20:48:46.000Z (about 2 years ago)
- Last Synced: 2024-05-22T16:34:38.132Z (about 2 years ago)
- Topics: ast, deno, html, parser, typescript
- Language: TypeScript
- Homepage: https://jsr.io/@lambdaurora/libhtml
- Size: 74.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# lib.html
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";
```