Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Add support for markdown in Callout. Fixes #91
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Harrington committed Jan 20, 2018
1 parent 08dffb5 commit d59da64
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
24 changes: 23 additions & 1 deletion packages/api-explorer/__tests__/block-types/CallOut.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,27 @@ test('should render body', () => {
};

const callout = shallow(<CallOut block={block} />);
expect(callout.find('div.callout-body').text()).toBe('body');
expect(
callout
.render()
.find('.callout-body')
.html(),
).toMatchSnapshot();
});

test('should render markdown in body', () => {
const block = {
data: {
type: 'info',
body: '# heading\n`test`',
},
};

const callout = shallow(<CallOut block={block} />);
expect(
callout
.render()
.find('.callout-body')
.html(),
).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`should render body 1`] = `
"<p>body</p>
"
`;

exports[`should render markdown in body 1`] = `
"<h1 class=\\"header-scroll\\"><div class=\\"anchor waypoint\\" id=\\"section-heading\\"></div>heading<a class=\\"fa fa-anchor\\" href=\\"#section-heading\\"></a></h1>
<p><code>test</code></p>
"
`;
17 changes: 14 additions & 3 deletions packages/api-explorer/src/block-types/CallOut.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const React = require('react');
const PropTypes = require('prop-types');
// import Marked from '../lib/marked';
const markdown = require('../lib/markdown');

function Icon({ type }) {
switch (type) {
Expand All @@ -17,7 +17,7 @@ function Icon({ type }) {
}
}

const CallOut = ({ block }) => {
const CallOut = ({ block, flags }) => {
return (
<div
className={`magic-block-callout type-${block.data.type} ${block.data.title
Expand All @@ -36,7 +36,15 @@ const CallOut = ({ block }) => {
<Icon type={block.data.type} />
</span>
)}
{block.data && block.data.body && <div className="callout-body">{block.data.body}</div>}
{/* eslint-disable react/no-danger */}
{block.data &&
block.data.body && (
<div
className="callout-body"
dangerouslySetInnerHTML={{ __html: markdown(block.data.body, flags) }}
/>
)}
{/* eslint-enable react/no-danger */}
</div>
);
};
Expand All @@ -49,8 +57,11 @@ CallOut.propTypes = {
body: PropTypes.string,
}),
}).isRequired,
flags: PropTypes.shape({}),
};

CallOut.defaultProps = { flags: {} };

Icon.propTypes = {
type: PropTypes.string.isRequired,
};
Expand Down

0 comments on commit d59da64

Please sign in to comment.