Skip to content

Commit

Permalink
librustdoc/html: recognize slices not to nest A tags.
Browse files Browse the repository at this point in the history
1. A slice of parametrized type, say
   BorrowedRef { ... Vector(Generic(T)) }, is rendered as
   "<a href='primitive.slice.html'>&amp;[T]</a>"
2. A slice of other types, say
   BorrowedRef { ... Vector(int) }, is rendered as
   "<a href='primitive.slice.html'>&amp;[</a>
    <a href='primitive.int.html'>int</a>
    <a href='primitive.slice.html'>]</a>"
3. Other cases, say BorrowedRef { ... int }, are
   rendered as same as before:
   "&<a href='primitive.int.html'>int</a>"

Relevant W3C specs:
- http://www.w3.org/TR/html401/struct/links.html#h-12.2.2
  12.2.2 Nested links are illegal
- http://www.w3.org/TR/html5/text-level-semantics.html#the-a-element
  states A tag must not enclose any "interactive contents"
  which include A tags themselves.
  • Loading branch information
nodakai committed Oct 8, 2014
1 parent bc649ba commit f40b60b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/librustdoc/html/format.rs
Expand Up @@ -478,7 +478,25 @@ impl fmt::Show for clean::Type {
Some(ref l) => format!("{} ", *l),
_ => "".to_string(),
};
write!(f, "&amp;{}{}{}", lt, MutableSpace(mutability), **ty)
let m = MutableSpace(mutability);
match **ty {
clean::Vector(ref bt) => { // BorrowedRef{ ... Vector(T) } is &[T]
match **bt {
clean::Generic(_) =>
primitive_link(f, clean::Slice,
format!("&amp;{}{}[{}]", lt, m, **bt).as_slice()),
_ => {
try!(primitive_link(f, clean::Slice,
format!("&amp;{}{}[", lt, m).as_slice()));
try!(write!(f, "{}", **bt));
primitive_link(f, clean::Slice, "]")
}
}
}
_ => {
write!(f, "&amp;{}{}{}", lt, m, **ty)
}
}
}
clean::Unique(..) => {
fail!("should have been cleaned")
Expand Down

5 comments on commit f40b60b

@bors
Copy link
Contributor

@bors bors commented on f40b60b Oct 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at nodakai@f40b60b

@bors
Copy link
Contributor

@bors bors commented on f40b60b Oct 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging nodakai/rust/rustdoc-dont-nest-a = f40b60b into auto

@bors
Copy link
Contributor

@bors bors commented on f40b60b Oct 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nodakai/rust/rustdoc-dont-nest-a = f40b60b merged ok, testing candidate = 519e85b

@bors
Copy link
Contributor

@bors bors commented on f40b60b Oct 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on f40b60b Oct 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 519e85b

Please sign in to comment.