Skip to content

[rustdoc] Add no-hidden-lines codeblock attribute #118711

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Add no-hidden-lines codeblock attribute to prevent removing lines o…
…r extra `#` characters
  • Loading branch information
GuillaumeGomez committed Dec 8, 2023
commit 5920cb9f48bd494468406577eaf5775cc75cbf96
14 changes: 13 additions & 1 deletion src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,13 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
};

let added_classes = parse_result.added_classes;
let lines = original_text.lines().filter_map(|l| map_line(l).for_html());
let lines = original_text.lines().filter_map(|l| {
if parse_result.no_hidden_lines {
Some(Cow::Borrowed(l))
} else {
map_line(l).for_html()
}
});
let text = lines.intersperse("\n".into()).collect::<String>();

compile_fail = parse_result.compile_fail;
Expand Down Expand Up @@ -879,6 +885,7 @@ pub(crate) struct LangString {
pub(crate) edition: Option<Edition>,
pub(crate) added_classes: Vec<String>,
pub(crate) unknown: Vec<String>,
pub(crate) no_hidden_lines: bool,
}

#[derive(Eq, PartialEq, Clone, Debug)]
Expand Down Expand Up @@ -1213,6 +1220,7 @@ impl Default for LangString {
edition: None,
added_classes: Vec::new(),
unknown: Vec::new(),
no_hidden_lines: false,
}
}
}
Expand Down Expand Up @@ -1274,6 +1282,10 @@ impl LangString {
data.rust = true;
seen_rust_tags = true;
}
LangStringToken::LangToken("no_hidden_lines") => {
data.no_hidden_lines = true;
seen_rust_tags = !seen_other_tags;
}
LangStringToken::LangToken("custom") => {
if custom_code_classes_in_docs {
seen_custom_tag = true;
Expand Down