Skip to content

Commit

Permalink
fix: figcaption only works within figure (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang authored Apr 2, 2024
1 parent 16b1fb0 commit 369db18
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ class Renderer extends MarkedRenderer {
if (lazyload) out += ' loading="lazy"';

out += '>';
if (figcaption) {
if (text) out += `<figcaption aria-hidden="true">${text}</figcaption>`;
if (figcaption && text) {
return `<figure>${out}<figcaption aria-hidden="true">${text}</figcaption></figure>`;
}
return out;
}
Expand Down
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -806,8 +806,8 @@ describe('Marked renderer', () => {

result.should.eql([
'<p><img src="/bar/baz.jpg" title="bar">',
'<img src="/bar/baz.jpg" alt="foo" title="bar"><figcaption aria-hidden="true">foo</figcaption>',
'<img src="/aaa/bbb.jpg" alt="foo"><figcaption aria-hidden="true">foo</figcaption></p>\n'
'<figure><img src="/bar/baz.jpg" alt="foo" title="bar"><figcaption aria-hidden="true">foo</figcaption></figure>',
'<figure><img src="/aaa/bbb.jpg" alt="foo"><figcaption aria-hidden="true">foo</figcaption></figure></p>\n'
].join('\n'));
});

Expand Down

0 comments on commit 369db18

Please sign in to comment.