Skip to content

Commit

Permalink
Rollup merge of rust-lang#36334 - GuillaumeGomez:run_but, r=steveklabnik
Browse files Browse the repository at this point in the history
Set run button transparent instead of invisible

r? @steveklabnik

And of course a screenshot:

![screenshot from 2016-09-08 01-15-45](https://cloud.githubusercontent.com/assets/3050060/18331849/31fe1f8c-7562-11e6-9ae9-1dab44089ec6.png)
  • Loading branch information
GuillaumeGomez authored Sep 14, 2016
2 parents 739d571 + a2faf54 commit d939cbe
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
6 changes: 5 additions & 1 deletion src/librustdoc/html/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ use syntax::parse;
use syntax_pos::Span;

/// Highlights `src`, returning the HTML output.
pub fn render_with_highlighting(src: &str, class: Option<&str>, id: Option<&str>) -> String {
pub fn render_with_highlighting(src: &str, class: Option<&str>, id: Option<&str>,
extension: Option<&str>) -> String {
debug!("highlighting: ================\n{}\n==============", src);
let sess = parse::ParseSess::new();
let fm = sess.codemap().new_filemap("<stdin>".to_string(), None, src.to_string());
Expand All @@ -47,6 +48,9 @@ pub fn render_with_highlighting(src: &str, class: Option<&str>, id: Option<&str>
return format!("<pre>{}</pre>", src);
}

if let Some(extension) = extension {
write!(out, "{}", extension).unwrap();
}
write_footer(&mut out).unwrap();
String::from_utf8_lossy(&out[..]).into_owned()
}
Expand Down
8 changes: 5 additions & 3 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,11 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
&Default::default());
s.push_str(&format!("<span class='rusttest'>{}</span>", Escape(&test)));
});
s.push_str(&highlight::render_with_highlighting(&text,
Some("rust-example-rendered"),
None));
s.push_str(&highlight::render_with_highlighting(
&text,
Some("rust-example-rendered"),
None,
Some("<a class='test-arrow' target='_blank' href=''>Run</a>")));
let output = CString::new(s).unwrap();
hoedown_buffer_puts(ob, output.as_ptr());
})
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2954,7 +2954,7 @@ impl<'a> fmt::Display for Source<'a> {
write!(fmt, "<span id=\"{0}\">{0:1$}</span>\n", i, cols)?;
}
write!(fmt, "</pre>")?;
write!(fmt, "{}", highlight::render_with_highlighting(s, None, None))?;
write!(fmt, "{}", highlight::render_with_highlighting(s, None, None, None))?;
Ok(())
}
}
Expand All @@ -2963,6 +2963,7 @@ fn item_macro(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
t: &clean::Macro) -> fmt::Result {
w.write_str(&highlight::render_with_highlighting(&t.source,
Some("macro"),
None,
None))?;
render_stability_since_raw(w, it.stable_since(), None)?;
document(w, cx, it)
Expand Down
15 changes: 1 addition & 14 deletions src/librustdoc/html/static/playpen.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ document.addEventListener('DOMContentLoaded', function() {
return;
}

var a = document.createElement('a');
a.setAttribute('class', 'test-arrow');
a.textContent = 'Run';
var a = el.querySelectorAll('a.test-arrow')[0];

var code = el.previousElementSibling.textContent;

Expand All @@ -40,17 +38,6 @@ document.addEventListener('DOMContentLoaded', function() {

a.setAttribute('href', window.playgroundUrl + '?code=' +
encodeURIComponent(code) + channel);
a.setAttribute('target', '_blank');

el.appendChild(a);
};

el.onmouseout = function(e) {
if (el.contains(e.relatedTarget)) {
return;
}

el.removeChild(el.querySelectorAll('a.test-arrow')[0]);
};
});
});
5 changes: 4 additions & 1 deletion src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -568,15 +568,18 @@ pre.rust .lifetime { color: #B76514; }
.rusttest { display: none; }
pre.rust { position: relative; }
a.test-arrow {
background-color: rgba(78, 139, 202, 0.2);
display: inline-block;
position: absolute;
background-color: #4e8bca;
padding: 5px 10px 5px 10px;
border-radius: 5px;
font-size: 130%;
top: 5px;
right: 5px;
}
a.test-arrow:hover{
background-color: #4e8bca;
}

.section-header:hover a:after {
content: '\2002\00a7\2002';
Expand Down

0 comments on commit d939cbe

Please sign in to comment.