Rollup merge of #77939 - GuillaumeGomez:fix-source-code-dos-backline, r=jyn514
Ensure that the source code display is working with DOS backline Fixes #76361. cc ````@lzutao```` r? ````@jyn514````
This commit is contained in:
commit
cf349567e4
3 changed files with 27 additions and 12 deletions
|
|
@ -46,7 +46,9 @@ fn write_header(out: &mut String, class: Option<&str>) {
|
|||
}
|
||||
|
||||
fn write_code(out: &mut String, src: &str) {
|
||||
Classifier::new(src).highlight(&mut |highlight| {
|
||||
// This replace allows to fix how the code source with DOS backline characters is displayed.
|
||||
let src = src.replace("\r\n", "\n");
|
||||
Classifier::new(&src).highlight(&mut |highlight| {
|
||||
match highlight {
|
||||
Highlight::Token { text, class } => string(out, Escape(text), class),
|
||||
Highlight::EnterSpan { class } => enter_span(out, class),
|
||||
|
|
|
|||
3
src/librustdoc/html/highlight/fixtures/dos_line.html
Normal file
3
src/librustdoc/html/highlight/fixtures/dos_line.html
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">foo</span>() {
|
||||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"foo"</span>);
|
||||
}
|
||||
|
|
@ -1,17 +1,6 @@
|
|||
use super::write_code;
|
||||
use expect_test::expect_file;
|
||||
|
||||
#[test]
|
||||
fn test_html_highlighting() {
|
||||
let src = include_str!("fixtures/sample.rs");
|
||||
let html = {
|
||||
let mut out = String::new();
|
||||
write_code(&mut out, src);
|
||||
format!("{}<pre><code>{}</code></pre>\n", STYLE, out)
|
||||
};
|
||||
expect_file!["fixtures/sample.html"].assert_eq(&html);
|
||||
}
|
||||
|
||||
const STYLE: &str = r#"
|
||||
<style>
|
||||
.kw { color: #8959A8; }
|
||||
|
|
@ -23,3 +12,24 @@ const STYLE: &str = r#"
|
|||
.question-mark { color: #ff9011; }
|
||||
</style>
|
||||
"#;
|
||||
|
||||
#[test]
|
||||
fn test_html_highlighting() {
|
||||
let src = include_str!("fixtures/sample.rs");
|
||||
let html = {
|
||||
let mut out = String::new();
|
||||
write_code(&mut out, src);
|
||||
format!("{}<pre><code>{}</code></pre>\n", STYLE, out)
|
||||
};
|
||||
expect_file!["fixtures/sample.html"].assert_eq(&html);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dos_backline() {
|
||||
let src = "pub fn foo() {\r\n\
|
||||
println!(\"foo\");\r\n\
|
||||
}\r\n";
|
||||
let mut html = String::new();
|
||||
write_code(&mut html, src);
|
||||
expect_file!["fixtures/dos_line.html"].assert_eq(&html);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue