Rollup merge of #36334 - GuillaumeGomez:run_but, r=steveklabnik
Set run button transparent instead of invisible r? @steveklabnik And of course a screenshot: 
This commit is contained in:
commit
d939cbeefe
5 changed files with 17 additions and 20 deletions
|
@ -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());
|
||||
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
s.push_str(&highlight::render_with_highlighting(
|
||||
&text,
|
||||
Some("rust-example-rendered"),
|
||||
None));
|
||||
None,
|
||||
Some("<a class='test-arrow' target='_blank' href=''>Run</a>")));
|
||||
let output = CString::new(s).unwrap();
|
||||
hoedown_buffer_puts(ob, output.as_ptr());
|
||||
})
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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]);
|
||||
};
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue