Rollup merge of #105539 - GuillaumeGomez:hashtag-prepended-lines-non-rust, r=notriddle

rustdoc: Only hide lines starting with `#` in rust code blocks

Fixes https://github.com/rust-lang/rust/issues/105527.

So before approving, this is a big question: in rust code blocks, in a line starts with a `#`, we hide it in the output. However, should we do the same for non-rust code blocks too? I think it's a bit problematic to do it because `#` can be used for many things but I prefer to check first with everyone (might also be worth updating documentation too).

cc ``@rust-lang/rustdoc``
r? ``@notriddle``
This commit is contained in:
Matthias Krüger 2022-12-11 09:51:57 +01:00 committed by GitHub
commit dd00582bc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 3 deletions

View File

@ -246,8 +246,6 @@ fn next(&mut self) -> Option<Self::Item> {
_ => {}
}
}
let lines = origtext.lines().filter_map(|l| map_line(l).for_html());
let text = lines.intersperse("\n".into()).collect::<String>();
let parse_result = match kind {
CodeBlockKind::Fenced(ref lang) => {
@ -260,7 +258,7 @@ fn next(&mut self) -> Option<Self::Item> {
<pre class=\"language-{}\"><code>{}</code></pre>\
</div>",
lang,
Escape(&text),
Escape(&origtext),
)
.into(),
));
@ -270,6 +268,9 @@ fn next(&mut self) -> Option<Self::Item> {
CodeBlockKind::Indented => Default::default(),
};
let lines = origtext.lines().filter_map(|l| map_line(l).for_html());
let text = lines.intersperse("\n".into()).collect::<String>();
compile_fail = parse_result.compile_fail;
should_panic = parse_result.should_panic;
ignore = parse_result.ignore;

View File

@ -309,3 +309,40 @@ fn add_test(&mut self, _test: String, _config: LangString, line: usize) {
t("```rust\n```\n```rust\n```", &[1, 3]);
t("```rust\n```\n ```rust\n```", &[1, 3]);
}
#[test]
fn test_ascii_with_prepending_hashtag() {
fn t(input: &str, expect: &str) {
let mut map = IdMap::new();
let output = Markdown {
content: input,
links: &[],
ids: &mut map,
error_codes: ErrorCodes::Yes,
edition: DEFAULT_EDITION,
playground: &None,
heading_offset: HeadingOffset::H2,
}
.into_string();
assert_eq!(output, expect, "original: {}", input);
}
t(
r#"```ascii
#..#.####.#....#.....##..
#..#.#....#....#....#..#.
####.###..#....#....#..#.
#..#.#....#....#....#..#.
#..#.#....#....#....#..#.
#..#.####.####.####..##..
```"#,
"<div class=\"example-wrap\"><pre class=\"language-ascii\"><code>\
#..#.####.#....#.....##..
#..#.#....#....#....#..#.
####.###..#....#....#..#.
#..#.#....#....#....#..#.
#..#.#....#....#....#..#.
#..#.####.####.####..##..
</code></pre></div>",
);
}