1
Fork 0

Rollup merge of #36334 - GuillaumeGomez:run_but, r=steveklabnik

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)
This commit is contained in:
Guillaume Gomez 2016-09-14 17:15:36 +02:00 committed by GitHub
commit d939cbeefe
5 changed files with 17 additions and 20 deletions

View file

@ -33,7 +33,8 @@ use syntax::parse;
use syntax_pos::Span; use syntax_pos::Span;
/// Highlights `src`, returning the HTML output. /// 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); debug!("highlighting: ================\n{}\n==============", src);
let sess = parse::ParseSess::new(); let sess = parse::ParseSess::new();
let fm = sess.codemap().new_filemap("<stdin>".to_string(), None, src.to_string()); 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); return format!("<pre>{}</pre>", src);
} }
if let Some(extension) = extension {
write!(out, "{}", extension).unwrap();
}
write_footer(&mut out).unwrap(); write_footer(&mut out).unwrap();
String::from_utf8_lossy(&out[..]).into_owned() String::from_utf8_lossy(&out[..]).into_owned()
} }

View file

@ -262,9 +262,11 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
&Default::default()); &Default::default());
s.push_str(&format!("<span class='rusttest'>{}</span>", Escape(&test))); 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(
Some("rust-example-rendered"), &text,
None)); Some("rust-example-rendered"),
None,
Some("<a class='test-arrow' target='_blank' href=''>Run</a>")));
let output = CString::new(s).unwrap(); let output = CString::new(s).unwrap();
hoedown_buffer_puts(ob, output.as_ptr()); hoedown_buffer_puts(ob, output.as_ptr());
}) })

View file

@ -2954,7 +2954,7 @@ impl<'a> fmt::Display for Source<'a> {
write!(fmt, "<span id=\"{0}\">{0:1$}</span>\n", i, cols)?; write!(fmt, "<span id=\"{0}\">{0:1$}</span>\n", i, cols)?;
} }
write!(fmt, "</pre>")?; write!(fmt, "</pre>")?;
write!(fmt, "{}", highlight::render_with_highlighting(s, None, None))?; write!(fmt, "{}", highlight::render_with_highlighting(s, None, None, None))?;
Ok(()) Ok(())
} }
} }
@ -2963,6 +2963,7 @@ fn item_macro(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
t: &clean::Macro) -> fmt::Result { t: &clean::Macro) -> fmt::Result {
w.write_str(&highlight::render_with_highlighting(&t.source, w.write_str(&highlight::render_with_highlighting(&t.source,
Some("macro"), Some("macro"),
None,
None))?; None))?;
render_stability_since_raw(w, it.stable_since(), None)?; render_stability_since_raw(w, it.stable_since(), None)?;
document(w, cx, it) document(w, cx, it)

View file

@ -27,9 +27,7 @@ document.addEventListener('DOMContentLoaded', function() {
return; return;
} }
var a = document.createElement('a'); var a = el.querySelectorAll('a.test-arrow')[0];
a.setAttribute('class', 'test-arrow');
a.textContent = 'Run';
var code = el.previousElementSibling.textContent; var code = el.previousElementSibling.textContent;
@ -40,17 +38,6 @@ document.addEventListener('DOMContentLoaded', function() {
a.setAttribute('href', window.playgroundUrl + '?code=' + a.setAttribute('href', window.playgroundUrl + '?code=' +
encodeURIComponent(code) + channel); 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]);
}; };
}); });
}); });

View file

@ -568,15 +568,18 @@ pre.rust .lifetime { color: #B76514; }
.rusttest { display: none; } .rusttest { display: none; }
pre.rust { position: relative; } pre.rust { position: relative; }
a.test-arrow { a.test-arrow {
background-color: rgba(78, 139, 202, 0.2);
display: inline-block; display: inline-block;
position: absolute; position: absolute;
background-color: #4e8bca;
padding: 5px 10px 5px 10px; padding: 5px 10px 5px 10px;
border-radius: 5px; border-radius: 5px;
font-size: 130%; font-size: 130%;
top: 5px; top: 5px;
right: 5px; right: 5px;
} }
a.test-arrow:hover{
background-color: #4e8bca;
}
.section-header:hover a:after { .section-header:hover a:after {
content: '\2002\00a7\2002'; content: '\2002\00a7\2002';