11 个版本
0.3.1 | 2024 年 6 月 28 日 |
---|---|
0.3.0 | 2024 年 6 月 28 日 |
0.2.2 | 2024 年 6 月 27 日 |
0.1.5 | 2024 年 6 月 22 日 |
#1973 在 网页编程
每月 70 次下载
34KB
642 代码行
htmlproc
HTML 处理器工具,每个函数作为一个单独的 功能
提供,因此依赖项保持较小。(omit_enclosure
作为文档大纲格式化器使用是例外。)
在 Rust 项目中安装
# install crate
cargo add htmlproc
# install crate with specific features
cargo add htmlproc --features path_to_url
# uninstall
# cargo remove htmlproc
函数(功能)
omit_attr
从 HTML 文本中移除特定的标签属性。
用法
首先,运行 cargo add htmlproc --features omit_attr
。然后指定要省略的属性。有三种格式可供选择
attr
:从所有标签中删除所有属性。*.attr
:与上面相同。tag.attr
:从特定的标签中删除所有属性。例如span.style
use htmlproc::omit_attr::manipulate;
let html = "<div id=\"preserved\"><span style=\"want: remove;\" class=\"also: wanted;\" z-index=\"1\">Content</span></div>";
let omit_attrs = &["style", "*.class", "span.z-index"];
let result: String = manipulate(html, omit_attrs);
omit_enclosure
从 HTML 文本中移除特定的标签封装。
用法
use htmlproc::omit_enclosure::manipulate;
let result: String = manipulate("<div>...<span>---</span>...</div>", &["span"]);
path_to_url
将路径转换为 URL。
用法
use htmlproc::path_to_url::{convert, ConvertOptions};
let result: String = convert("<a href=\"/some/path\">link</a>", ConvertOptions::new("target.domain"));
在这种情况下,href
的值 "/some/path
" 转换为 "https://target.domain/some/path
"。提供了选项,例如 HTTP 协议、端口号和当前目录。
依赖项
~1.5–7MB
~34K SLoC