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:
commit
dd00582bc8
2 changed files with 41 additions and 3 deletions
|
@ -246,8 +246,6 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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 {
|
let parse_result = match kind {
|
||||||
CodeBlockKind::Fenced(ref lang) => {
|
CodeBlockKind::Fenced(ref lang) => {
|
||||||
|
@ -260,7 +258,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
|
||||||
<pre class=\"language-{}\"><code>{}</code></pre>\
|
<pre class=\"language-{}\"><code>{}</code></pre>\
|
||||||
</div>",
|
</div>",
|
||||||
lang,
|
lang,
|
||||||
Escape(&text),
|
Escape(&origtext),
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
));
|
));
|
||||||
|
@ -270,6 +268,9 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
|
||||||
CodeBlockKind::Indented => Default::default(),
|
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;
|
compile_fail = parse_result.compile_fail;
|
||||||
should_panic = parse_result.should_panic;
|
should_panic = parse_result.should_panic;
|
||||||
ignore = parse_result.ignore;
|
ignore = parse_result.ignore;
|
||||||
|
|
|
@ -309,3 +309,40 @@ fn test_find_testable_code_line() {
|
||||||
t("```rust\n```\n```rust\n```", &[1, 3]);
|
t("```rust\n```\n```rust\n```", &[1, 3]);
|
||||||
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>",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue