Rphtml
A html parser written in RUST, parse html into node trees.
Install / Use
/learn @fefit/RphtmlREADME
rphtml
一个用 rust 编写的 html 文档解析器,0.4.0 版本前通过 wasm-pack/wasm-bindgen 提供 npm 包。
如何使用
use rphtml::parser::{ Doc, ParseOptions, RenderOptions, HResult };
fn main()->HResult{
let doc = Doc::parse("<div id='content'>rpthml</div>", ParseOptions{
case_sensitive_tagname: false, // 解析时标签区分大小写,`<div>` 和 `<DIV>` 将被视作不同标签,不建议开启
allow_self_closing: false, // 允许非替换元素使用自闭合的写法,如 `<div class='' />`
auto_fix_unclosed_tag: true, // 自动修复没有结束的标签,注意这里只是简单的将标签闭合
auto_fix_unexpected_endtag: true, // 自动修复不正确的结束标签,如 "<div></p></div>" 会被修复为 "<div></div>"
auto_fix_unescaped_lt: true, // 自动修复没有实体转译的左尖括号 '<', 比如`<div>a<b</div>`会被修复为`<div>a<b</div>`
allow_attr_key_starts_with_equal_sign: true, // 是否允许 "=" 符号出现在属性名的开头,如 `<div =a="c" />` 属性名为"=a",值为"c"
})?;
// 获取root根节点
let root = doc.get_root_node();
let render_html = doc.render(&RenderOptions{
..Default::default() // RenderOptions的参数定义可以在wiki中查看
});
}
License
Related Skills
node-connect
352.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
352.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
352.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
