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

Fix magic block callout icons alignment. #664

Merged
merged 2 commits into from
May 1, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

exports[`Components Callout 1`] = `"<blockquote class=\\"callout callout_error\\" theme=\\"❗️\\"><h3 class=\\"callout-heading false\\"><span class=\\"callout-icon\\">❗️</span><p>Error Callout</p></h3><p>Lorem ipsum dolor.</p></blockquote>"`;

exports[`Components Callout 2`] = `"<blockquote class=\\"callout callout_default\\" theme=\\"🎟\\"><h3 class=\\"callout-heading empty\\"><span class=\\"callout-icon\\">🎟</span></h3><p>Callout with no title or theme.</p></blockquote>"`;

exports[`Components Embed 1`] = `"<div class=\\"embed\\"><a href=\\"https://gist.github.com/chaddy81/f852004d6d1510eec1f6\\" rel=\\"noopener noreferrer\\" style=\\"display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-decoration: none;\\" target=\\"_blank\\"><b style=\\"color: rgb(51, 51, 51);\\">View Embed:</b> <span style=\\"opacity: 0.75;\\">https://gist.github.com/chaddy81/f852004d6d1510eec1f6</span></a></div>"`;

exports[`Components Image 1`] = `"<p><img src=\\"https://files.readme.io/6f52e22-man-eating-pizza-and-making-an-ok-gesture.jpg\\" alt=\\"Bro eats pizza and makes an OK gesture.\\" title=\\"Pizza Face\\" align=\\"\\" caption=\\"\\" height=\\"auto\\" width=\\"auto\\" loading=\\"lazy\\"><span class=\\"lightbox\\" role=\\"dialog\\"><span class=\\"lightbox-inner\\"><img src=\\"https://files.readme.io/6f52e22-man-eating-pizza-and-making-an-ok-gesture.jpg\\" alt=\\"Bro eats pizza and makes an OK gesture.\\" title=\\"Click to close...\\" align=\\"\\" caption=\\"\\" height=\\"auto\\" width=\\"auto\\" loading=\\"lazy\\"></span></span></p>"`;
23 changes: 19 additions & 4 deletions packages/markdown/__tests__/components.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,30 @@ describe('Components', () => {
`,
`

> 🎟
> 🚧
>
> Callout with no title or theme.
> Callout with no title.

`,
`[block:callout]
{
"type": "warning",
"body": "Callout with no title."
}
[/block]`,
];
const wrap = [mount(markdown.react(callout[0])), mount(markdown.react(callout[1]))];
const wrap = [
mount(markdown.react(callout[0])),
mount(markdown.react(callout[1])),
mount(markdown.react(callout[2])),
];

expect(wrap[0].html()).toMatchSnapshot();
expect(wrap[1].html()).toMatchSnapshot();

const noTitleExpectation =
'<blockquote class="callout callout_warn" theme="🚧"><h3 class="callout-heading empty"><span class="callout-icon">🚧</span></h3><p>Callout with no title.</p></blockquote>';
expect(wrap[1].html()).toBe(noTitleExpectation);
expect(wrap[2].html()).toBe(noTitleExpectation);
});

it('Multi Code Block', () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/markdown/components/Callout/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const PropTypes = require('prop-types');
const Callout = props => {
let { children } = props;
const { attributes, theme, title, icon } = props;
if (!(title || children)) return '';

const content = title ? children.splice(1) : children;
children = title ? children : '';
return (
Expand All @@ -13,7 +15,7 @@ const Callout = props => {
<span className="callout-icon">{icon}</span>
{children}
</h3>
{(content.length && content) || (!title ? children : '')}
{(content && content.length && content) || (!title && children)}
rafegoldberg marked this conversation as resolved.
Show resolved Hide resolved
</blockquote>
);
};
Expand Down
8 changes: 1 addition & 7 deletions packages/markdown/processor/parse/magic-block-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,7 @@ function tokenize(eat, value) {
value: json.body,
},
},
children: [
{
type: 'paragraph',
children: [...this.tokenizeInline(json.title, eat.now())],
},
...this.tokenizeBlock(json.body, eat.now()),
],
children: [...this.tokenizeBlock(json.title, eat.now()), ...this.tokenizeBlock(json.body, eat.now())],
},
json
)
Expand Down