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
16 changes: 16 additions & 0 deletions __tests__/migration/callouts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { migrate } from '../helpers';

describe('migrating callouts', () => {
it('retains HTML content that starts a callout body', () => {
const md = `> ⚠️ <div><b>hello</b></div>
`;

const mdx = migrate(md);
expect(mdx).toMatchInlineSnapshot(`
"<Callout icon="⚠️" theme="warn">
<div><b>hello</b></div>
</Callout>
"
`);
});
});
6 changes: 5 additions & 1 deletion processor/transform/migrate-callouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { wrapHeading } from './callouts';

const migrateCallouts: Plugin<[], Root> = (): Transformer<Root> => (tree: Root) => {
visit(tree, 'rdme-callout', callout => {
callout.children[0] = wrapHeading(callout);
const firstChild = callout.children?.[0];
// This will retain the value of the node if it is not a paragraph, e.g. an HTML node
if (firstChild && firstChild.type === 'paragraph') {
callout.children[0] = wrapHeading(callout);
}
});

return tree;
Expand Down