about summary refs log tree commit diff
path: root/src/librustdoc/markdown_index_pass.rs
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2013-03-25 12:39:41 -0700
committerBrian Anderson <banderson@mozilla.com>2013-03-26 09:20:37 -0700
commit043150b9ab29e46d0dbee36e53737915a09163b7 (patch)
tree3ab836336848ad54c5457508ce1ee2abd53310de /src/librustdoc/markdown_index_pass.rs
parentdf171e4b6898db92610bcccb22d996d361e16902 (diff)
downloadrust-043150b9ab29e46d0dbee36e53737915a09163b7.tar.gz
rust-043150b9ab29e46d0dbee36e53737915a09163b7.zip
rustdoc: Sanitize links harder
Diffstat (limited to 'src/librustdoc/markdown_index_pass.rs')
-rw-r--r--src/librustdoc/markdown_index_pass.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/librustdoc/markdown_index_pass.rs b/src/librustdoc/markdown_index_pass.rs
index 12d875945d9..4feeed84aa2 100644
--- a/src/librustdoc/markdown_index_pass.rs
+++ b/src/librustdoc/markdown_index_pass.rs
@@ -143,12 +143,16 @@ fn pandoc_header_id(header: &str) -> ~str {
         let s = str::replace(s, ~":", ~"");
         let s = str::replace(s, ~"&", ~"");
         let s = str::replace(s, ~"^", ~"");
+        let s = str::replace(s, ~",", ~"");
+        let s = str::replace(s, ~"'", ~"");
+        let s = str::replace(s, ~"+", ~"");
         return s;
     }
     fn replace_with_hyphens(s: &str) -> ~str {
         // Collapse sequences of whitespace to a single dash
         // XXX: Hacky implementation here that only covers
         // one or two spaces.
+        let s = str::trim(s);
         let s = str::replace(s, ~"  ", ~"-");
         let s = str::replace(s, ~" ", ~"-");
         return s;
@@ -170,6 +174,17 @@ fn should_remove_punctuation_from_headers() {
         == ~"impl-of-numnum-for-int");
     fail_unless!(pandoc_header_id(~"impl for & condvar")
         == ~"impl-for-condvar");
+    fail_unless!(pandoc_header_id(~"impl of Select<T, U> for (Left, Right)")
+                 == ~"impl-of-selectt-u-for-left-right");
+    fail_unless!(pandoc_header_id(~"impl of Condition<'self, T, U>")
+                 == ~"impl-of-conditionself-t-u");
+    fail_unless!(pandoc_header_id(~"impl of Condition<T: Copy + Clone>")
+                 == ~"impl-of-conditiont-copy-clone");
+}
+
+#[test]
+fn should_trim_whitespace_after_removing_punctuation() {
+    fail_unless!(pandoc_header_id("impl foo for ()") == ~"impl-foo-for");
 }
 
 #[test]