Skip to content

Commit

Permalink
🖼️ Read iframe options from html (#1725)
Browse files Browse the repository at this point in the history
Co-authored-by: Franklin Koch <franklinwkoch@gmail.com>
  • Loading branch information
rowanc1 and fwkoch authored Jan 6, 2025
1 parent 7d6dff2 commit 7101874
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-eels-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"myst-transforms": patch
---

Read iframe from html source
18 changes: 18 additions & 0 deletions packages/myst-transforms/src/html.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,4 +450,22 @@ describe('Test reconstructHtmlTransform', () => {
],
});
});
test('iframe tags in html', async () => {
const mdast = {
type: 'root',
children: [{ type: 'html', value: '<iframe class="my-iframe" src="https://example.com" />' }],
};
htmlTransform(mdast);
expect(mdast).toEqual({
type: 'root',
children: [
{
type: 'iframe',
src: 'https://example.com',
class: 'my-iframe',
width: '100%',
},
],
});
});
});
6 changes: 6 additions & 0 deletions packages/myst-transforms/src/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ const defaultHtmlToMdastOptions: Record<keyof HtmlTransformOptions, any> = {
if (node.properties.alt) attrs.alt = node.properties.alt;
return h(node, 'image', attrs);
},
iframe(h: H, node: any) {
const attrs = addClassAndIdentifier(node);
attrs.src = String(node.properties.src || '');
attrs.width = '100%';
return h(node, 'iframe', attrs);
},
figure(h: H, node: any) {
const attrs = addClassAndIdentifier(node);
return h(node, 'container', attrs, all(h, node));
Expand Down

0 comments on commit 7101874

Please sign in to comment.