Skip to content

Commit 71267c0

Browse files
authored
Merge pull request #3925 from rust-lang/fix-trpl-note-rendering
infra: fix rendering bug in mdbook-trpl-note
2 parents 7e2a00d + e28a6b0 commit 71267c0

File tree

1 file changed

+33
-8
lines changed
  • packages/mdbook-trpl-note/src

1 file changed

+33
-8
lines changed

packages/mdbook-trpl-note/src/lib.rs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ impl Preprocessor for TrplNote {
3434
"simple-note-preprocessor"
3535
}
3636

37-
fn run(&self, _ctx: &PreprocessorContext, mut book: Book) -> Result<mdbook::book::Book> {
37+
fn run(
38+
&self,
39+
_ctx: &PreprocessorContext,
40+
mut book: Book,
41+
) -> Result<mdbook::book::Book> {
3842
book.for_each_mut(|item| {
3943
if let BookItem::Chapter(ref mut chapter) = item {
4044
chapter.content = rewrite(&chapter.content);
@@ -75,7 +79,9 @@ pub fn rewrite(text: &str) -> String {
7579
events.extend([
7680
SoftBreak,
7781
SoftBreak,
78-
Html(r#"<section class="note" aria-role="note">"#.into()),
82+
Html(
83+
r#"<section class="note" aria-role="note">"#.into(),
84+
),
7985
SoftBreak,
8086
SoftBreak,
8187
Start(Tag::Paragraph),
@@ -89,7 +95,10 @@ pub fn rewrite(text: &str) -> String {
8995
}
9096
}
9197

92-
(StartingBlockquote(_blockquote_events), heading @ Start(Tag::Heading { .. })) => {
98+
(
99+
StartingBlockquote(_blockquote_events),
100+
heading @ Start(Tag::Heading { .. }),
101+
) => {
93102
events.extend([
94103
SoftBreak,
95104
SoftBreak,
@@ -101,14 +110,18 @@ pub fn rewrite(text: &str) -> String {
101110
state = InNote;
102111
}
103112

104-
(StartingBlockquote(ref mut events), Start(Tag::Paragraph)) => {
105-
events.push(Start(Tag::Paragraph));
113+
(StartingBlockquote(ref mut events), Start(tag)) => {
114+
events.push(Start(tag));
106115
}
107116

108117
(InNote, End(TagEnd::BlockQuote)) => {
109118
// As with the start of the block HTML, the closing HTML must be
110119
// separated from the Markdown text by two newlines.
111-
events.extend([SoftBreak, SoftBreak, Html("</section>".into())]);
120+
events.extend([
121+
SoftBreak,
122+
SoftBreak,
123+
Html("</section>".into()),
124+
]);
112125
state = Default;
113126
}
114127

@@ -258,7 +271,8 @@ mod tests {
258271

259272
#[test]
260273
fn h1_then_blockquote() {
261-
let text = "> # Header\n > And then some note content.\n\n> This is quoted.";
274+
let text =
275+
"> # Header\n > And then some note content.\n\n> This is quoted.";
262276
let processed = rewrite(text);
263277
assert_eq!(
264278
render_markdown(&processed),
@@ -268,14 +282,25 @@ mod tests {
268282

269283
#[test]
270284
fn blockquote_then_h1_note() {
271-
let text = "> This is quoted.\n\n> # Header\n > And then some note content.";
285+
let text =
286+
"> This is quoted.\n\n> # Header\n > And then some note content.";
272287
let processed = rewrite(text);
273288
assert_eq!(
274289
render_markdown(&processed),
275290
"<blockquote>\n<p>This is quoted.</p>\n</blockquote>\n<section class=\"note\" aria-role=\"note\">\n<h1>Header</h1>\n<p>And then some note content.</p>\n</section>"
276291
);
277292
}
278293

294+
#[test]
295+
fn blockquote_with_strong() {
296+
let text = "> **Bold text in a paragraph.**";
297+
let processed = rewrite(text);
298+
assert_eq!(
299+
render_markdown(&processed),
300+
"<blockquote>\n<p><strong>Bold text in a paragraph.</strong></p>\n</blockquote>\n"
301+
);
302+
}
303+
279304
fn render_markdown(text: &str) -> String {
280305
let parser = Parser::new(text);
281306
let mut buf = String::new();

0 commit comments

Comments
 (0)