mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Added caption support to code card renderer (#10719)
* Added caption support to code card renderer refs https://github.com/TryGhost/Ghost-Admin/pull/1181 - when a caption for a code card is provided, render the contents inside a `<figure>` element with a `<figcaption class="kg-card kg-code-card">` to match other caption-enabled cards
This commit is contained in:
parent
d0970ad309
commit
990ecec873
2 changed files with 28 additions and 1 deletions
|
@ -21,6 +21,18 @@ module.exports = createCard({
|
|||
code.appendChild(dom.createTextNode(payload.code));
|
||||
pre.appendChild(code);
|
||||
|
||||
return pre;
|
||||
if (payload.caption) {
|
||||
let figure = dom.createElement('figure');
|
||||
figure.setAttribute('class', 'kg-card kg-code-card');
|
||||
figure.appendChild(pre);
|
||||
|
||||
let figcaption = dom.createElement('figcaption');
|
||||
figcaption.appendChild(dom.createRawHTMLSection(payload.caption));
|
||||
figure.appendChild(figcaption);
|
||||
|
||||
return figure;
|
||||
} else {
|
||||
return pre;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -43,4 +43,19 @@ describe('Code card', function () {
|
|||
|
||||
serializer.serialize(card.render(opts)).should.match('');
|
||||
});
|
||||
|
||||
it('Renders a figure if a caption is provided', function () {
|
||||
let opts = {
|
||||
env: {
|
||||
dom: new SimpleDom.Document()
|
||||
},
|
||||
payload: {
|
||||
code: '<p>Test</p>',
|
||||
language: 'html',
|
||||
caption: 'Some <strong>HTML</strong>'
|
||||
}
|
||||
};
|
||||
|
||||
serializer.serialize(card.render(opts)).should.match('<!--kg-card-begin: code--><figure class="kg-card kg-code-card"><pre><code class="language-html"><p>Test</p></code></pre><figcaption>Some <strong>HTML</strong></figcaption></figure><!--kg-card-end: code-->');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue