Skip to content
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
8 changes: 7 additions & 1 deletion __tests__/compilers/callout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ describe('callouts compiler', () => {
expect(mdx(mdast(markdown))).toBe(markdown);
});

it('compiles callouts with no heading or body!?', () => {
it('compiles callouts with no heading or body', () => {
const markdown = `> 🚧
`;

expect(mdx(mdast(markdown))).toBe(markdown);
});

it('compiles callouts with no heading or body and no new line at the end', () => {
const markdown = '> ℹ️';

expect(mdx(mdast(markdown))).toBe(`${markdown}\n`);
});

it('compiles callouts with markdown in the heading', () => {
const markdown = `> 🚧 It **works**!
>
Expand Down
9 changes: 9 additions & 0 deletions __tests__/migration/callouts.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { migrate } from '../helpers';

describe('migrating callouts', () => {
it('does not error on callouts with no heading', () => {
const md = '> ℹ️';
const mdx = migrate(md);
expect(mdx).toMatchInlineSnapshot(`
"<Callout icon="ℹ️" theme="info" />
"
`);
});

it('retains HTML content that starts a callout body', () => {
const md = `> ⚠️ <div><b>hello</b></div>
`;
Expand Down
2 changes: 1 addition & 1 deletion processor/transform/readme-to-mdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const readmeToMdx = (): Transform => tree => {

visit(tree, 'rdme-callout', (node, index, parent) => {
const isEmpty = node.data.hProperties?.empty;
const isH3 = node.children[0].type === 'heading' && node.children[0].depth === 3;
const isH3 = node.children?.[0] && 'type' in node.children[0] && node.children[0].type === 'heading' && node.children[0].depth === 3;
let { icon, theme } = node.data.hProperties;
if (!icon) icon = defaultIcons[theme];
if (!theme) theme = themes[icon] || 'default';
Expand Down