rustdoc: Escape HTML special characters

This commit is contained in:
Brian Anderson 2012-03-06 17:46:52 -08:00
parent 29ac3c811d
commit cf8f5b7606
3 changed files with 26 additions and 0 deletions

View 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, "<", "&lt;");
let s = str::replace(s, ">", "&gt;");
let s = str::replace(s, "\"", "&quot;");
ret s;
}
#[test]
fn test() {
assert escape("<") == "&lt;";
assert escape(">") == "&gt;";
assert escape("&") == "&amp;";
assert escape("\"") == "&quot;";
assert escape("<>&\"") == "&lt;&gt;&amp;&quot;";
}

View File

@ -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;

View File

@ -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),