Skip to content

Commit

Permalink
Check the title before rendering <figcaption>
Browse files Browse the repository at this point in the history
Signed-off-by: JmPotato <[email protected]>
  • Loading branch information
JmPotato committed Aug 23, 2024
1 parent a022167 commit b11a4e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,9 +881,12 @@ impl<'o, 'c: 'o> HtmlFormatter<'o, 'c> {
}
self.output.write_all(b"\" />")?;
if self.options.render.figure_with_caption {
self.output.write_all(b"<figcaption>")?;
self.escape(nl.title.as_bytes())?;
self.output.write_all(b"</figcaption></figure>")?;
if !nl.title.is_empty() {
self.output.write_all(b"<figcaption>")?;
self.escape(nl.title.as_bytes())?;
self.output.write_all(b"</figcaption>")?;
}
self.output.write_all(b"</figure>")?;
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion src/tests/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,25 @@ fn ignore_setext_heading() {
}

#[test]
fn figure_with_caption() {
fn figure_with_caption_with_title() {
html_opts!(
[render.figure_with_caption],
concat!("![image](https://example.com/image.png \"this is an image\")\n"),
concat!("<p><figure><img src=\"https://example.com/image.png\" alt=\"image\" title=\"this is an image\" /><figcaption>this is an image</figcaption></figure></p>\n"),
);
}

#[test]
fn figure_with_caption_without_title() {
html_opts!(
[render.figure_with_caption],
concat!("![image](https://example.com/image.png)\n"),
concat!(
"<p><figure><img src=\"https://example.com/image.png\" alt=\"image\" /></figure></p>\n"
),
);
}

#[test]
fn html_block_1() {
html_opts!(
Expand Down

0 comments on commit b11a4e9

Please sign in to comment.