rustdoc: Escape HTML special characters
This commit is contained in:
parent
29ac3c811d
commit
cf8f5b7606
24
src/rustdoc/html_escape_pass.rs
Normal file
24
src/rustdoc/html_escape_pass.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#[doc = "Escapes characters that are not valid in HTML"];
|
||||||
|
|
||||||
|
export mk_pass;
|
||||||
|
|
||||||
|
fn mk_pass() -> pass {
|
||||||
|
desc_pass::mk_pass("html_escape", escape)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn escape(s: str) -> str {
|
||||||
|
let s = str::replace(s, "&", "&");
|
||||||
|
let s = str::replace(s, "<", "<");
|
||||||
|
let s = str::replace(s, ">", ">");
|
||||||
|
let s = str::replace(s, "\"", """);
|
||||||
|
ret s;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test() {
|
||||||
|
assert escape("<") == "<";
|
||||||
|
assert escape(">") == ">";
|
||||||
|
assert escape("&") == "&";
|
||||||
|
assert escape("\"") == """;
|
||||||
|
assert escape("<>&\"") == "<>&"";
|
||||||
|
}
|
@ -39,3 +39,4 @@ mod sort_item_type_pass;
|
|||||||
mod reexport_pass;
|
mod reexport_pass;
|
||||||
mod par;
|
mod par;
|
||||||
mod page_pass;
|
mod page_pass;
|
||||||
|
mod html_escape_pass;
|
||||||
|
@ -149,6 +149,7 @@ fn run(config: config::config) {
|
|||||||
desc_to_brief_pass::mk_pass(),
|
desc_to_brief_pass::mk_pass(),
|
||||||
trim_pass::mk_pass(),
|
trim_pass::mk_pass(),
|
||||||
unindent_pass::mk_pass(),
|
unindent_pass::mk_pass(),
|
||||||
|
html_escape_pass::mk_pass(),
|
||||||
sort_item_name_pass::mk_pass(),
|
sort_item_name_pass::mk_pass(),
|
||||||
sort_item_type_pass::mk_pass(),
|
sort_item_type_pass::mk_pass(),
|
||||||
markdown_index_pass::mk_pass(config),
|
markdown_index_pass::mk_pass(config),
|
||||||
|
Loading…
Reference in New Issue
Block a user