Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lomirus/html_editor
Pure and simple HTML parser and editor.
https://github.com/lomirus/html_editor
html parser rust xml
Last synced: 5 days ago
JSON representation
Pure and simple HTML parser and editor.
- Host: GitHub
- URL: https://github.com/lomirus/html_editor
- Owner: lomirus
- License: mit
- Created: 2022-01-01T13:17:54.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-11-15T03:00:29.000Z (12 months ago)
- Last Synced: 2024-03-15T09:22:24.989Z (8 months ago)
- Topics: html, parser, rust, xml
- Language: HTML
- Homepage: https://crates.io/crates/html_editor
- Size: 85.9 KB
- Stars: 21
- Watchers: 1
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[![crate-badge]][crate-link]
[![downloads-badge]][crate-link]
![License](https://img.shields.io/crates/l/html_editor)
[![check-badge]][check-link][crate-badge]: https://img.shields.io/crates/v/html_editor
[crate-link]: https://crates.io/crates/html_editor
[check-badge]: https://github.com/lomirus/html-editor/workflows/check/badge.svg
[check-link]: https://github.com/lomirus/html-editor/actions/workflows/check.yaml
[downloads-badge]: https://img.shields.io/crates/d/html_editor# HTML Editor
Pure and simple HTML parser and editor.
## Examples
### Parse HTML segment/document
```rust
let document: Vec = parse("")?;
println!("{:#?}", document);
```Output:
```rust
[
Doctype(
Html,
),
Element {
name: "html",
attrs: {},
children: [
Element {
name: "head",
attrs: {},
children: [],
},
Element {
name: "body",
attrs: {},
children: [],
},
],
},
]
```You can also use `try_parse` to parse the html which contains tolerable errors
```rust
let document: Vec = try_parse("Ipsum");
```### Query an element / elements by selector
```rust
// let html = r#"..."#
let nodes: Vec = parse(html)?;
let selector: Selector = Selector::from(".box");let element: Option = nodes.query(&selector);
let elements: Vec = nodes.query_all(&selector);
```### Edit the HTML
```rust
// let html = r#"..."#
let a: String = parse(html)?.trim().html();
let b: String = parse(html)?.insert_to(&selector, node).html();
let c: String = parse(html)?.remove_by(&selector).html();
let d: String = parse(html)?.replace_with(&selector, |el| Node::Comment(el.html())).html();
```You can find more examples in the [documentation](https://docs.rs/html_editor/latest/html_editor/).
## Changelog
See in [CHANGELOG.md](CHANGELOG.md)