Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🖼️ Export iframe/aside for markdown writing #1719

Merged
merged 2 commits into from
Jan 6, 2025
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
5 changes: 5 additions & 0 deletions .changeset/unlucky-bags-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"myst-to-md": patch
---

Add iframes and directives to markdown export
21 changes: 21 additions & 0 deletions packages/myst-to-md/src/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Handle> = {
code,
image,
container,
admonition,
details,
iframe,
aside,
card,
grid: writeFlowDirective('grid', undefined, {
keys: ['columns'],
Expand Down
43 changes: 43 additions & 0 deletions packages/myst-to-md/tests/directives.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
:::
Loading