Skip to content

Commit ab7750c

Browse files
Add no-hidden-lines codeblock attribute to prevent removing lines or extra # characters
1 parent cf8d812 commit ab7750c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/librustdoc/html/markdown.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,13 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
288288
};
289289

290290
let added_classes = parse_result.added_classes;
291-
let lines = original_text.lines().filter_map(|l| map_line(l).for_html());
291+
let lines = original_text.lines().filter_map(|l| {
292+
if parse_result.no_hidden_lines {
293+
Some(Cow::Borrowed(l))
294+
} else {
295+
map_line(l).for_html()
296+
}
297+
});
292298
let text = lines.intersperse("\n".into()).collect::<String>();
293299

294300
compile_fail = parse_result.compile_fail;
@@ -879,6 +885,7 @@ pub(crate) struct LangString {
879885
pub(crate) edition: Option<Edition>,
880886
pub(crate) added_classes: Vec<String>,
881887
pub(crate) unknown: Vec<String>,
888+
pub(crate) no_hidden_lines: bool,
882889
}
883890

884891
#[derive(Eq, PartialEq, Clone, Debug)]
@@ -1213,6 +1220,7 @@ impl Default for LangString {
12131220
edition: None,
12141221
added_classes: Vec::new(),
12151222
unknown: Vec::new(),
1223+
no_hidden_lines: false,
12161224
}
12171225
}
12181226
}
@@ -1274,6 +1282,10 @@ impl LangString {
12741282
data.rust = true;
12751283
seen_rust_tags = true;
12761284
}
1285+
LangStringToken::LangToken("no_hidden_lines") => {
1286+
data.no_hidden_lines = true;
1287+
seen_rust_tags = !seen_other_tags;
1288+
}
12771289
LangStringToken::LangToken("custom") => {
12781290
if custom_code_classes_in_docs {
12791291
seen_custom_tag = true;

0 commit comments

Comments
 (0)