Skip to content

rustdoc: make icons more consistent #91735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions src/librustdoc/html/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,10 @@ crate fn render_with_highlighting(
decoration_info: Option<DecorationInfo>,
) {
debug!("highlighting: ================\n{}\n==============", src);
if let Some((edition_info, class)) = tooltip {
write!(
out,
"<div class='information'><div class='tooltip {}'{}>ⓘ</div></div>",
class,
if let Some(edition_info) = edition_info {
format!(" data-edition=\"{}\"", edition_info)
} else {
String::new()
},
);
}

write_header(out, class, extra_content);
write_code(out, src, edition, context_info, decoration_info);
write_footer(out, playground_button);
write_footer(out, tooltip, playground_button);
}

fn write_header(out: &mut Buffer, class: Option<&str>, extra_content: Option<Buffer>) {
Expand Down Expand Up @@ -114,8 +102,25 @@ fn write_code(
});
}

fn write_footer(out: &mut Buffer, playground_button: Option<&str>) {
writeln!(out, "</code></pre>{}</div>", playground_button.unwrap_or_default());
fn write_footer(
out: &mut Buffer,
tooltip: Option<(Option<Edition>, &str)>,
playground_button: Option<&str>,
) {
writeln!(out, "</code></pre>");
if let Some((edition_info, class)) = tooltip {
write!(
out,
"<div class='information'><div class='tooltip {}'{}><span class='icon'>ⓘ</span></div></div>",
class,
if let Some(edition_info) = edition_info {
format!(" data-edition=\"{}\"", edition_info)
} else {
String::new()
},
);
}
writeln!(out, "{}</div>", playground_button.unwrap_or_default());
}

/// How a span of text is classified. Mostly corresponds to token kinds.
Expand Down
24 changes: 9 additions & 15 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,15 @@ enum Setting {
}

impl Setting {
fn display(&self, root_path: &str, suffix: &str) -> String {
fn display(&self) -> String {
match *self {
Setting::Section { description, ref sub_settings } => format!(
"<div class=\"setting-line\">\
<div class=\"title\">{}</div>\
<div class=\"sub-settings\">{}</div>
</div>",
description,
sub_settings.iter().map(|s| s.display(root_path, suffix)).collect::<String>()
sub_settings.iter().map(|s| s.display()).collect::<String>()
),
Setting::Toggle { js_data_name, description, default_value } => format!(
"<div class=\"setting-line\">\
Expand All @@ -388,7 +388,7 @@ impl Setting {
<div>{}</div>\
<label class=\"select-wrapper\">\
<select id=\"{}\" autocomplete=\"off\">{}</select>\
<img src=\"{}down-arrow{}.svg\" alt=\"Select item\">\
<span class=\"icon\">⏷</span>\
</label>\
</div>",
description,
Expand All @@ -401,8 +401,6 @@ impl Setting {
name = opt,
))
.collect::<String>(),
root_path,
suffix,
),
}
}
Expand Down Expand Up @@ -462,7 +460,7 @@ fn settings(root_path: &str, suffix: &str, theme_names: Vec<String>) -> Result<S
<div class=\"settings\">{}</div>\
<link rel=\"stylesheet\" href=\"{root_path}settings{suffix}.css\">\
<script src=\"{root_path}settings{suffix}.js\"></script>",
settings.iter().map(|s| s.display(root_path, suffix)).collect::<String>(),
settings.iter().map(|s| s.display()).collect::<String>(),
root_path = root_path,
suffix = suffix
))
Expand Down Expand Up @@ -667,8 +665,7 @@ fn short_item_info(
message.push_str(&format!(": {}", html.into_string()));
}
extra_info.push(format!(
"<div class=\"stab deprecated\"><span class=\"emoji\">👎</span> {}</div>",
message,
"<div class=\"stab deprecated\"><span class=\"icon\">👎</span> {message}</div>"
));
}

Expand All @@ -680,9 +677,6 @@ fn short_item_info(
.filter(|stab| stab.feature != sym::rustc_private)
.map(|stab| (stab.level, stab.feature))
{
let mut message =
"<span class=\"emoji\">🔬</span> This is a nightly-only experimental API.".to_owned();

let mut feature = format!("<code>{}</code>", Escape(&feature.as_str()));
if let (Some(url), Some(issue)) = (&cx.shared.issue_tracker_base_url, issue) {
feature.push_str(&format!(
Expand All @@ -692,9 +686,9 @@ fn short_item_info(
));
}

message.push_str(&format!(" ({})", feature));

extra_info.push(format!("<div class=\"stab unstable\">{}</div>", message));
extra_info.push(format!(
"<div class=\"stab unstable\"><span class=\"icon\">🔬</span> This is a nightly-only experimental API. ({feature})</div>"
));
}

if let Some(portability) = portability(item, parent) {
Expand Down Expand Up @@ -1292,7 +1286,7 @@ fn notable_traits_decl(decl: &clean::FnDecl, cx: &Context<'_>) -> String {
if !out.is_empty() {
out.insert_str(
0,
"<span class=\"notable-traits\"><span class=\"notable-traits-tooltip\">\
"<span class=\"notable-traits\"><span class=\"notable-traits-tooltip\"><span class=\"icon\">ⓘ</span>\
<div class=\"notable-traits-tooltiptext\"><span class=\"docblock\">",
);
out.push_str("</code></span></div></span></span>");
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
clean::FunctionItem(ref func) | clean::ForeignFunctionItem(ref func)
if func.header.unsafety == hir::Unsafety::Unsafe =>
{
"<a title=\"unsafe function\" href=\"#\"><sup>⚠</sup></a>"
"<a title=\"unsafe function\" href=\"#\"><sup class=\"icon\">⚠</sup></a>"
}
_ => "",
};
Expand Down
20 changes: 9 additions & 11 deletions src/librustdoc/html/render/write_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ pub(super) fn write_shared(
write_minify(
"rustdoc.css",
static_files::RUSTDOC_CSS
.replace("/* AUTOREPLACE: */url('icons.woff2')", &ver_url(cx, "icons.woff2"))
.replace("/* AUTOREPLACE: */url('icons.woff')", &ver_url(cx, "icons.woff"))
.replace(
"/* AUTOREPLACE: */url(\"toggle-minus.svg\")",
&ver_url(cx, "toggle-minus.svg"),
)
.replace("/* AUTOREPLACE: */url(\"toggle-plus.svg\")", &ver_url(cx, "toggle-plus.svg"))
.replace("/* AUTOREPLACE: */url(\"down-arrow.svg\")", &ver_url(cx, "down-arrow.svg")),
"AUTOREPLACE: icons-FontAwesome-LICENSE.txt",
&ver_url(cx, "icons-FontAwesome-LICENSE.txt"),
),
cx,
options,
)?;
Expand Down Expand Up @@ -247,12 +247,10 @@ pub(super) fn write_shared(
write_toolchain("favicon-16x16.png", static_files::RUST_FAVICON_PNG_16)?;
write_toolchain("favicon-32x32.png", static_files::RUST_FAVICON_PNG_32)?;
}
write_toolchain("brush.svg", static_files::BRUSH_SVG)?;
write_toolchain("wheel.svg", static_files::WHEEL_SVG)?;
write_toolchain("clipboard.svg", static_files::CLIPBOARD_SVG)?;
write_toolchain("down-arrow.svg", static_files::DOWN_ARROW_SVG)?;
write_toolchain("toggle-minus.svg", static_files::TOGGLE_MINUS_PNG)?;
write_toolchain("toggle-plus.svg", static_files::TOGGLE_PLUS_PNG)?;

write_toolchain("icons.woff", static_files::icons::WOFF)?;
write_toolchain("icons.woff2", static_files::icons::WOFF2)?;
write_toolchain("icons-FontAwesome-LICENSE.txt", static_files::icons::LICENSE)?;

let mut themes: Vec<&String> = themes.iter().collect();
themes.sort();
Expand Down
Loading