diff --git a/src/rustdoc/html_escape_pass.rs b/src/rustdoc/html_escape_pass.rs
new file mode 100644
index 00000000000..b3c1c5d5fc8
--- /dev/null
+++ b/src/rustdoc/html_escape_pass.rs
@@ -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("<>&\"") == "<>&"";
+}
diff --git a/src/rustdoc/rustdoc.rc b/src/rustdoc/rustdoc.rc
index c53b11fa021..489bbf29fcc 100644
--- a/src/rustdoc/rustdoc.rc
+++ b/src/rustdoc/rustdoc.rc
@@ -39,3 +39,4 @@ mod sort_item_type_pass;
mod reexport_pass;
mod par;
mod page_pass;
+mod html_escape_pass;
diff --git a/src/rustdoc/rustdoc.rs b/src/rustdoc/rustdoc.rs
index 3f480940e16..d165900df5d 100755
--- a/src/rustdoc/rustdoc.rs
+++ b/src/rustdoc/rustdoc.rs
@@ -149,6 +149,7 @@ fn run(config: config::config) {
desc_to_brief_pass::mk_pass(),
trim_pass::mk_pass(),
unindent_pass::mk_pass(),
+ html_escape_pass::mk_pass(),
sort_item_name_pass::mk_pass(),
sort_item_type_pass::mk_pass(),
markdown_index_pass::mk_pass(config),