Add arrow and improve display
This commit is contained in:
@@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
use html::escape::Escape;
|
use html::escape::Escape;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
@@ -36,7 +35,7 @@ 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>,
|
pub fn render_with_highlighting(src: &str, class: Option<&str>, id: Option<&str>,
|
||||||
extension: Option<&str>,
|
extension: Option<&str>,
|
||||||
extras: Option<HashMap<String, String>>) -> String {
|
tooltip: Option<(&str, &str)>) -> String {
|
||||||
debug!("highlighting: ================\n{}\n==============", src);
|
debug!("highlighting: ================\n{}\n==============", src);
|
||||||
let sess = parse::ParseSess::new(FilePathMapping::empty());
|
let sess = parse::ParseSess::new(FilePathMapping::empty());
|
||||||
let fm = sess.codemap().new_filemap("<stdin>".to_string(), src.to_string());
|
let fm = sess.codemap().new_filemap("<stdin>".to_string(), src.to_string());
|
||||||
@@ -396,18 +395,12 @@ impl Class {
|
|||||||
|
|
||||||
fn write_header(class: Option<&str>,
|
fn write_header(class: Option<&str>,
|
||||||
id: Option<&str>,
|
id: Option<&str>,
|
||||||
out: &mut Write,
|
out: &mut Write)
|
||||||
extras: Option<HashMap<String, String>>)
|
|
||||||
-> io::Result<()> {
|
-> io::Result<()> {
|
||||||
write!(out, "<pre ")?;
|
write!(out, "<pre ")?;
|
||||||
if let Some(id) = id {
|
if let Some(id) = id {
|
||||||
write!(out, "id='{}' ", id)?;
|
write!(out, "id='{}' ", id)?;
|
||||||
}
|
}
|
||||||
if let Some(extras) = extras {
|
|
||||||
for (key, value) in &extras {
|
|
||||||
write!(out, "{}=\"{}\" ", key, value)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
write!(out, "class=\"rust {}\">\n", class.unwrap_or(""))
|
write!(out, "class=\"rust {}\">\n", class.unwrap_or(""))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -225,16 +225,10 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'a, I> {
|
|||||||
url, test_escaped, channel
|
url, test_escaped, channel
|
||||||
))
|
))
|
||||||
});
|
});
|
||||||
let title = if ignore {
|
let tooltip = if ignore {
|
||||||
let mut tmp = HashMap::new();
|
Some(("Be careful when using this code, it's not being tested!", "ignore"))
|
||||||
tmp.insert("title".to_owned(),
|
|
||||||
"Be careful when using this code, it's not being tested!".to_owned());
|
|
||||||
Some(tmp)
|
|
||||||
} else if compile_fail {
|
} else if compile_fail {
|
||||||
let mut tmp = HashMap::new();
|
Some(("This code doesn't compile so be extra careful!", "compile_fail"))
|
||||||
tmp.insert("title".to_owned(),
|
|
||||||
"This code doesn't compile so be extra careful!".to_owned());
|
|
||||||
Some(tmp)
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
@@ -246,7 +240,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'a, I> {
|
|||||||
else { "" })),
|
else { "" })),
|
||||||
None,
|
None,
|
||||||
playground_button.as_ref().map(String::as_str),
|
playground_button.as_ref().map(String::as_str),
|
||||||
title));
|
tooltip));
|
||||||
Some(Event::Html(s.into()))
|
Some(Event::Html(s.into()))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -642,18 +636,10 @@ pub fn render(w: &mut fmt::Formatter,
|
|||||||
url, test_escaped, channel
|
url, test_escaped, channel
|
||||||
))
|
))
|
||||||
});
|
});
|
||||||
let title = if ignore {
|
let tooltip = if ignore {
|
||||||
let mut tmp = HashMap::new();
|
Some(("Be careful when using this code, it's not being tested!", "ignore"))
|
||||||
tmp.insert("title".to_owned(),
|
|
||||||
"Be careful when using this code, it's not being \
|
|
||||||
tested!".to_owned());
|
|
||||||
Some(tmp)
|
|
||||||
} else if compile_fail {
|
} else if compile_fail {
|
||||||
let mut tmp = HashMap::new();
|
Some(("This code doesn't compile so be extra careful!", "compile_fail"))
|
||||||
tmp.insert("title".to_owned(),
|
|
||||||
"This code doesn't compile so be extra \
|
|
||||||
careful!".to_owned());
|
|
||||||
Some(tmp)
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
@@ -665,7 +651,7 @@ pub fn render(w: &mut fmt::Formatter,
|
|||||||
else { "" })),
|
else { "" })),
|
||||||
None,
|
None,
|
||||||
playground_button.as_ref().map(String::as_str),
|
playground_button.as_ref().map(String::as_str),
|
||||||
title));
|
tooltip));
|
||||||
hoedown_buffer_put(ob, s.as_ptr(), s.len());
|
hoedown_buffer_put(ob, s.as_ptr(), s.len());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3679,7 +3679,8 @@ 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, None, None))?;
|
write!(fmt, "{}",
|
||||||
|
highlight::render_with_highlighting(s, None, None, None, None))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1296,6 +1296,24 @@
|
|||||||
collapseDocs(i_e.previousSibling.childNodes[0]);
|
collapseDocs(i_e.previousSibling.childNodes[0]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onEach(document.getElementsByClassName('rust-example-rendered'), function(e) {
|
||||||
|
if (hasClass(e, 'compile_fail')) {
|
||||||
|
e.addEventListener("mouseover", function(event) {
|
||||||
|
e.previousElementSibling.childNodes[0].style.color = '#f00';
|
||||||
|
});
|
||||||
|
e.addEventListener("mouseout", function(event) {
|
||||||
|
e.previousElementSibling.childNodes[0].style.color = '';
|
||||||
|
});
|
||||||
|
} else if (hasClass(e, 'ignore')) {
|
||||||
|
e.addEventListener("mouseover", function(event) {
|
||||||
|
e.previousElementSibling.childNodes[0].style.color = '#ff9200';
|
||||||
|
});
|
||||||
|
e.addEventListener("mouseout", function(event) {
|
||||||
|
e.previousElementSibling.childNodes[0].style.color = '';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
// Sets the focus on the search bar at the top of the page
|
// Sets the focus on the search bar at the top of the page
|
||||||
|
|||||||
@@ -612,7 +612,6 @@ pre.rust .question-mark {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre.rust { position: relative; }
|
|
||||||
a.test-arrow {
|
a.test-arrow {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@@ -813,3 +812,44 @@ span.since {
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.information {
|
||||||
|
position: absolute;
|
||||||
|
left: -1px;
|
||||||
|
margin-top: 7px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tooltip {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tooltip .tooltiptext {
|
||||||
|
width: 120px;
|
||||||
|
display: none;
|
||||||
|
background-color: black;
|
||||||
|
color: #fff;
|
||||||
|
text-align: center;
|
||||||
|
padding: 5px 3px;
|
||||||
|
border-radius: 6px;
|
||||||
|
margin-left: 5px;
|
||||||
|
top: -5px;
|
||||||
|
left: 105%;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tooltip:hover .tooltiptext {
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tooltip .tooltiptext::after {
|
||||||
|
content: " ";
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 11px;
|
||||||
|
margin-top: -5px;
|
||||||
|
border-width: 5px;
|
||||||
|
border-style: solid;
|
||||||
|
border-color: transparent black transparent transparent;
|
||||||
|
}
|
||||||
|
|||||||
@@ -205,9 +205,33 @@ a.test-arrow:hover{
|
|||||||
}
|
}
|
||||||
|
|
||||||
pre.compile_fail {
|
pre.compile_fail {
|
||||||
box-shadow: -6px 0 5px -3px #f00;
|
border-left: 2px solid rgba(255,0,0,.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
pre.compile_fail:hover, .information:hover + pre.compile_fail {
|
||||||
|
border-left: 2px solid #f00;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre.ignore {
|
pre.ignore {
|
||||||
box-shadow: -6px 0 5px -3px #ff9200;
|
border-left: 2px solid rgba(255,142,0,.4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pre.ignore:hover, .information:hover + pre.ignore {
|
||||||
|
border-left: 2px solid #ff9200;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tooltip.compile_fail {
|
||||||
|
color: rgba(255,0,0,.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.information > .compile_fail:hover {
|
||||||
|
color: #f00;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tooltip.ignore {
|
||||||
|
color: rgba(255,142,0,.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.information > .ignore:hover {
|
||||||
|
color: rgba(255,142,0,1);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user