diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs
index 9fff508165a..3b599e4997a 100644
--- a/src/librustdoc/html/markdown.rs
+++ b/src/librustdoc/html/markdown.rs
@@ -33,6 +33,7 @@ use std::str;
use crate::clean::RenderedLink;
use crate::doctest;
+use crate::html::escape::Escape;
use crate::html::highlight;
use crate::html::toc::TocBuilder;
@@ -207,26 +208,11 @@ impl<'a, I: Iterator- >> Iterator for CodeBlocks<'_, 'a, I> {
let should_panic;
let ignore;
let edition;
- if let Some(Event::Start(Tag::CodeBlock(kind))) = event {
- let parse_result = match kind {
- CodeBlockKind::Fenced(ref lang) => {
- LangString::parse_without_check(&lang, self.check_error_codes, false)
- }
- CodeBlockKind::Indented => Default::default(),
- };
- if !parse_result.rust {
- return Some(Event::Start(Tag::CodeBlock(kind)));
- }
- compile_fail = parse_result.compile_fail;
- should_panic = parse_result.should_panic;
- ignore = parse_result.ignore;
- edition = parse_result.edition;
+ let kind = if let Some(Event::Start(Tag::CodeBlock(kind))) = event {
+ kind
} else {
return event;
- }
-
- let explicit_edition = edition.is_some();
- let edition = edition.unwrap_or(self.edition);
+ };
let mut origtext = String::new();
for event in &mut self.inner {
@@ -241,6 +227,35 @@ impl<'a, I: Iterator
- >> Iterator for CodeBlocks<'_, 'a, I> {
let lines = origtext.lines().filter_map(|l| map_line(l).for_html());
let text = lines.collect::>>().join("\n");
+ let parse_result = match kind {
+ CodeBlockKind::Fenced(ref lang) => {
+ let parse_result =
+ LangString::parse_without_check(&lang, self.check_error_codes, false);
+ if !parse_result.rust {
+ return Some(Event::Html(
+ format!(
+ "",
+ format!(" class=\"language-{}\"", lang),
+ Escape(&text),
+ )
+ .into(),
+ ));
+ }
+ parse_result
+ }
+ CodeBlockKind::Indented => Default::default(),
+ };
+
+ compile_fail = parse_result.compile_fail;
+ should_panic = parse_result.should_panic;
+ ignore = parse_result.ignore;
+ edition = parse_result.edition;
+
+ let explicit_edition = edition.is_some();
+ let edition = edition.unwrap_or(self.edition);
+
let playground_button = self.playground.as_ref().and_then(|playground| {
let krate = &playground.crate_name;
let url = &playground.url;
diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index 66dfd2fac84..208e8f723f4 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -435,7 +435,7 @@ nav.sub {
border-bottom-left-radius: 5px;
}
-.rustdoc:not(.source) .example-wrap > pre.rust {
+.rustdoc:not(.source) .example-wrap > pre:not(.line-number) {
width: 100%;
overflow-x: auto;
}