0
Fork 0
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:
Kevin Ansfield 2019-05-01 17:10:24 +02:00 committed by GitHub
parent d0970ad309
commit 990ecec873
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View file

@ -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;
}
}
});

View file

@ -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">&lt;p&gt;Test&lt;/p&gt;</code></pre><figcaption>Some <strong>HTML</strong></figcaption></figure><!--kg-card-end: code-->');
});
});