From 1ca41130fb6f381dacad55365d4c5a1c7237edce Mon Sep 17 00:00:00 2001 From: eagletrhost Date: Thu, 11 Dec 2025 19:49:55 +1100 Subject: [PATCH 1/2] feat: embed block fix --- __tests__/lib/mdxish/magic-blocks.test.ts | 25 +++++++++++++++++++ processor/plugin/mdxish-handlers.ts | 13 ++++++++++ .../transform/mdxish/mdxish-magic-blocks.ts | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/__tests__/lib/mdxish/magic-blocks.test.ts b/__tests__/lib/mdxish/magic-blocks.test.ts index 7943a6e68..5d127ca2c 100644 --- a/__tests__/lib/mdxish/magic-blocks.test.ts +++ b/__tests__/lib/mdxish/magic-blocks.test.ts @@ -67,4 +67,29 @@ ${JSON.stringify( expect((element.children[1] as Element).tagName).toBe('tbody'); }); }) + + describe('embed block', () => { + it('should restore embed block', () => { + const md = `[block:embed] +{ + "url": "https://www.youtube.com/watch?v=FVikHLyW500&list=RD3-9V38W00CM&index=4", + "provider": "youtube.com", + "href": "https://www.youtube.com/watch?v=FVikHLyW500&list=RD3-9V38W00CM&index=4", + "typeOfEmbed": "youtube" +} +[/block]`; + + const ast = mdxish(md); + + // Embed is wrapped in a paragraph, so we need to get the first child + const embedElement = (ast.children[0] as Element).children[0] as Element; + + expect(embedElement.type).toBe('element'); + expect(embedElement.tagName).toBe('embed'); + expect(embedElement.properties.url).toBe('https://www.youtube.com/watch?v=FVikHLyW500&list=RD3-9V38W00CM&index=4'); + expect(embedElement.properties.provider).toBe('youtube.com'); + expect(embedElement.properties.href).toBe('https://www.youtube.com/watch?v=FVikHLyW500&list=RD3-9V38W00CM&index=4'); + expect(embedElement.properties.typeOfEmbed).toBe('youtube'); + }); + }); }); diff --git a/processor/plugin/mdxish-handlers.ts b/processor/plugin/mdxish-handlers.ts index 3fff1c73c..841628ab8 100644 --- a/processor/plugin/mdxish-handlers.ts +++ b/processor/plugin/mdxish-handlers.ts @@ -49,7 +49,20 @@ const htmlBlockHandler: Handler = (_state, node) => { }; }; +// Convert embed magic blocks to Embed components +const embedHandler: Handler = (state, node) => { + const { data } = node as { data?: { hName?: string; hProperties?: Properties } }; + + return { + type: 'element', + tagName: data?.hName === NodeTypes.embedBlock ? 'Embed' : 'embed', + properties: (data?.hProperties || {}) as Properties, + children: state.all(node), + }; +}; + export const mdxComponentHandlers: Handlers = { + embed: embedHandler, mdxFlowExpression: mdxExpressionHandler, mdxJsxFlowElement: mdxJsxElementHandler, mdxJsxTextElement: mdxJsxElementHandler, diff --git a/processor/transform/mdxish/mdxish-magic-blocks.ts b/processor/transform/mdxish/mdxish-magic-blocks.ts index 2fd1c0bac..e7da08f3c 100644 --- a/processor/transform/mdxish/mdxish-magic-blocks.ts +++ b/processor/transform/mdxish/mdxish-magic-blocks.ts @@ -316,7 +316,7 @@ function parseMagicBlock(raw: string, options: ParseMagicBlockOptions = {}): Mda wrapPinnedBlocks( { children: [ - { children: [{ type: 'text', value: title || null }], title: embedJson.provider, type: 'link', url }, + { children: [{ type: 'text', value: title || '' }], title: embedJson.provider, type: 'link', url }, ], data: { hName: 'rdme-embed', hProperties: { ...embedJson, href: url, html, title, url } }, type: 'embed', From 1856c4881db4f5436b0e7d27515f0efda68d1654 Mon Sep 17 00:00:00 2001 From: eagletrhost Date: Fri, 2 Jan 2026 17:25:35 +1100 Subject: [PATCH 2/2] style: test lint & fix embed handler --- __tests__/lib/mdxish/magic-blocks.test.ts | 62 +++++++++---------- processor/plugin/mdxish-handlers.ts | 5 +- .../transform/mdxish/mdxish-magic-blocks.ts | 2 +- 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/__tests__/lib/mdxish/magic-blocks.test.ts b/__tests__/lib/mdxish/magic-blocks.test.ts index 9ca6f9d0e..782529f9d 100644 --- a/__tests__/lib/mdxish/magic-blocks.test.ts +++ b/__tests__/lib/mdxish/magic-blocks.test.ts @@ -68,23 +68,22 @@ ${JSON.stringify( }); it('should convert html content inside table cells as nodes in the ast', () => { - const md = ` - [block:parameters] - ${JSON.stringify( - { - data: { - 'h-0': 'Header 0', - 'h-1': 'Header 1', - '0-0': '

this should be a h1 element node

', - '0-1': 'this should be a strong element node', - }, - cols: 2, - rows: 1, + const md = `[block:parameters] +${JSON.stringify( + { + data: { + 'h-0': 'Header 0', + 'h-1': 'Header 1', + '0-0': '

this should be a h1 element node

', + '0-1': 'this should be a strong element node', }, - null, - 2, - )} - [/block]`; + cols: 2, + rows: 1, + }, + null, + 2, +)} +[/block]`; const ast = mdxish(md); // Some extra children are added to the AST by the mdxish wrapper @@ -107,23 +106,22 @@ ${JSON.stringify( }); it('should restore markdown content inside table cells', () => { - const md = ` - [block:parameters] - ${JSON.stringify( - { - data: { - 'h-0': 'Header 0', - 'h-1': 'Header 1', - '0-0': '**Bold**', - '0-1': '*Italic*', - }, - cols: 2, - rows: 1, + const md = `[block:parameters] +${JSON.stringify( + { + data: { + 'h-0': 'Header 0', + 'h-1': 'Header 1', + '0-0': '**Bold**', + '0-1': '*Italic*', }, - null, - 2, - )} - [/block]`; + cols: 2, + rows: 1, + }, + null, + 2, +)} +[/block]`; const ast = mdxish(md); // Some extra children are added to the AST by the mdxish wrapper diff --git a/processor/plugin/mdxish-handlers.ts b/processor/plugin/mdxish-handlers.ts index 841628ab8..fd21b8754 100644 --- a/processor/plugin/mdxish-handlers.ts +++ b/processor/plugin/mdxish-handlers.ts @@ -51,12 +51,15 @@ const htmlBlockHandler: Handler = (_state, node) => { // Convert embed magic blocks to Embed components const embedHandler: Handler = (state, node) => { + // Assert to get the minimum properties we need const { data } = node as { data?: { hName?: string; hProperties?: Properties } }; return { type: 'element', + // To differentiate between regular embeds and magic block embeds, + // magic block embeds have a certain hName tagName: data?.hName === NodeTypes.embedBlock ? 'Embed' : 'embed', - properties: (data?.hProperties || {}) as Properties, + properties: data?.hProperties, children: state.all(node), }; }; diff --git a/processor/transform/mdxish/mdxish-magic-blocks.ts b/processor/transform/mdxish/mdxish-magic-blocks.ts index bef34c0af..8d12786b4 100644 --- a/processor/transform/mdxish/mdxish-magic-blocks.ts +++ b/processor/transform/mdxish/mdxish-magic-blocks.ts @@ -334,7 +334,7 @@ function parseMagicBlock(raw: string, options: ParseMagicBlockOptions = {}): Mda children: [ { children: [{ type: 'text', value: title || '' }], title: embedJson.provider, type: 'link', url }, ], - data: { hName: 'rdme-embed', hProperties: { ...embedJson, href: url, html, title, url } }, + data: { hName: 'embed-block', hProperties: { ...embedJson, href: url, html, title, url } }, type: 'embed', }, json,