Skip to content

Commit c7193e0

Browse files
Add "raw" codeblock attribute to prevent removing lines or extra # characters
1 parent cf8d812 commit c7193e0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/librustdoc/html/markdown.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ 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.raw { Some(Cow::Borrowed(l)) } else { map_line(l).for_html() }
293+
});
292294
let text = lines.intersperse("\n".into()).collect::<String>();
293295

294296
compile_fail = parse_result.compile_fail;
@@ -879,6 +881,7 @@ pub(crate) struct LangString {
879881
pub(crate) edition: Option<Edition>,
880882
pub(crate) added_classes: Vec<String>,
881883
pub(crate) unknown: Vec<String>,
884+
pub(crate) raw: bool,
882885
}
883886

884887
#[derive(Eq, PartialEq, Clone, Debug)]
@@ -1213,6 +1216,7 @@ impl Default for LangString {
12131216
edition: None,
12141217
added_classes: Vec::new(),
12151218
unknown: Vec::new(),
1219+
raw: false,
12161220
}
12171221
}
12181222
}
@@ -1274,6 +1278,10 @@ impl LangString {
12741278
data.rust = true;
12751279
seen_rust_tags = true;
12761280
}
1281+
LangStringToken::LangToken("raw") => {
1282+
data.raw = true;
1283+
seen_rust_tags = !seen_other_tags;
1284+
}
12771285
LangStringToken::LangToken("custom") => {
12781286
if custom_code_classes_in_docs {
12791287
seen_custom_tag = true;

0 commit comments

Comments
 (0)