https://github.com/fefit/rphtml
A html parser written in RUST, parse html into node trees.
https://github.com/fefit/rphtml
html-minify html-parser html-parsing
Last synced: about 1 month ago
JSON representation
A html parser written in RUST, parse html into node trees.
- Host: GitHub
- URL: https://github.com/fefit/rphtml
- Owner: fefit
- License: mit
- Created: 2020-09-06T08:28:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-03-19T13:05:42.000Z (11 months ago)
- Last Synced: 2025-08-24T22:15:38.311Z (5 months ago)
- Topics: html-minify, html-parser, html-parsing
- Language: Rust
- Homepage:
- Size: 4.83 MB
- Stars: 11
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rphtml
一个用 rust 编写的 html 文档解析器,0.4.0 版本前通过 wasm-pack/wasm-bindgen 提供 npm 包。
[](https://badge.fury.io/js/rphtml)
[](https://github.com/fefit/rphtml/actions)
[](https://codecov.io/gh/fefit/rphtml)
## 如何使用
```rust
use rphtml::parser::{ Doc, ParseOptions, RenderOptions, HResult };
fn main()->HResult{
let doc = Doc::parse("
rpthml", ParseOptions{
case_sensitive_tagname: false, // 解析时标签区分大小写,`` 和 `` 将被视作不同标签,不建议开启
allow_self_closing: false, // 允许非替换元素使用自闭合的写法,如 ``
auto_fix_unclosed_tag: true, // 自动修复没有结束的标签,注意这里只是简单的将标签闭合
auto_fix_unexpected_endtag: true, // 自动修复不正确的结束标签,如 "" 会被修复为 ""
auto_fix_unescaped_lt: true, // 自动修复没有实体转译的左尖括号 '<', 比如`a`会被修复为`a<b`
allow_attr_key_starts_with_equal_sign: true, // 是否允许 "=" 符号出现在属性名的开头,如 `` 属性名为"=a",值为"c"
})?;
// 获取root根节点
let root = doc.get_root_node();
let render_html = doc.render(&RenderOptions{
..Default::default() // RenderOptions的参数定义可以在wiki中查看
});
}
```
## License
[MIT License](./LICENSE).