diff --git a/.changeset/unlucky-bags-shake.md b/.changeset/unlucky-bags-shake.md new file mode 100644 index 000000000..622d47fdd --- /dev/null +++ b/.changeset/unlucky-bags-shake.md @@ -0,0 +1,5 @@ +--- +"myst-to-md": patch +--- + +Add iframes and directives to markdown export diff --git a/packages/myst-to-md/src/directives.ts b/packages/myst-to-md/src/directives.ts index abed4201b..624ffe1bc 100644 --- a/packages/myst-to-md/src/directives.ts +++ b/packages/myst-to-md/src/directives.ts @@ -361,12 +361,33 @@ function tabItem(node: any, _: Parent, state: NestedState, info: Info): string { return handler(node, _, state, info); } +function iframe(node: any, _: Parent, state: NestedState, info: Info): string { + const handler = writeStaticDirective('iframe', { argsKey: 'src', keys: IMAGE_DIRECTIVE_OPTS }); + return handler(node, _, state, info); +} + +function aside(node: any, _: Parent, state: NestedState, info: Info): string { + const name = node.kind ?? 'aside'; + const admonitionTitle = select('admonitionTitle', node); + const args = admonitionTitle ? state.containerPhrasing(admonitionTitle as any, info) : ''; + const nodeCopy = { + ...node, + children: node.children.filter((n: GenericNode) => n.type !== 'admonitionTitle'), + }; + const options = { + keys: ['class'], + }; + return writeFlowDirective(name, args, options)(nodeCopy, _, state, info); +} + export const directiveHandlers: Record = { code, image, container, admonition, details, + iframe, + aside, card, grid: writeFlowDirective('grid', undefined, { keys: ['columns'], diff --git a/packages/myst-to-md/tests/directives.yml b/packages/myst-to-md/tests/directives.yml index eb494005f..77fc8d44c 100644 --- a/packages/myst-to-md/tests/directives.yml +++ b/packages/myst-to-md/tests/directives.yml @@ -877,3 +877,46 @@ cases: Tab two ::: :::: + - title: iframe + mdast: + type: root + children: + - type: iframe + src: https://example.com + width: 10% + markdown: |- + ```{iframe} https://example.com + :width: 10% + ``` + - title: aside + mdast: + type: root + children: + - type: aside + class: my-class + children: + - type: paragraph + children: + - type: text + value: Aside content + markdown: |- + :::{aside} + :class: my-class + + Aside content + ::: + - title: topic + mdast: + type: root + children: + - type: aside + kind: topic + children: + - type: paragraph + children: + - type: text + value: Topic content + markdown: |- + :::{topic} + Topic content + :::