Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added caption support to code card renderer #10719

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion core/server/lib/mobiledoc/cards/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
});
15 changes: 15 additions & 0 deletions core/test/unit/lib/mobiledoc/cards/code_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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-->');
});
});