Skip to content

Commit

Permalink
Merge pull request #24 from whale4113/feat/lujunji/iframe
Browse files Browse the repository at this point in the history
feat: support iframe block
  • Loading branch information
whale4113 authored Dec 8, 2024
2 parents dfae5a8 + f024cc5 commit f0e685b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-parents-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@dolphin/lark': minor
---

feat: support iframe block
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Install Cloud Document Converter from [Chrome Web Store](https://chromewebstore.
| Bitable | To be determined | |
| Chat Card | To be determined | |
| File || Link (Download only) |
| Iframe | To be determined | |
| Iframe | ✔️ | HTML |
| ISV | To be determined | |
| Mind Note | To be determined | |
| Sheet | To be determined | |
Expand Down
2 changes: 1 addition & 1 deletion README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Cloud Document Converter 是一个浏览器扩展, 支持下载、复制飞书
| 多维表格 | 待定 | |
| 群名片 | 待定 | |
| 文件 || Link(仅下载支持) |
| 内嵌网页 | 待定 | |
| 内嵌网页 | ✔️ | HTML |
| 小组件 | 待定 | |
| 思维笔记 | 待定 | |
| 电子表格 | 待定 | |
Expand Down
38 changes: 36 additions & 2 deletions packages/lark/src/docx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ interface NotSupportedBlock extends Block {
| BlockType.BITABLE
| BlockType.CHAT_CARD
| BlockType.DIAGRAM
| BlockType.IFRAME
| BlockType.ISV
| BlockType.MINDNOTE
| BlockType.SHEET
Expand All @@ -308,8 +307,38 @@ type Blocks =
| Whiteboard
| View
| File
| IframeBlock
| NotSupportedBlock

interface IframeBlock extends Block {
type: BlockType.IFRAME
snapshot: {
type: BlockType.IFRAME
iframe: Partial<{
height: number
component: Partial<{
url: string
}>
}>
}
}

const iframeToHTML = (iframe: IframeBlock): mdast.Html | null => {
const { height = 400, component = {} } = iframe.snapshot.iframe
const { url } = component

if (!url) {
return null
}

const html = `<iframe src="${url}" sandbox="allow-scripts allow-same-origin allow-presentation allow-forms allow-popups allow-downloads" allowfullscreen allow="encrypted-media; fullscreen; autoplay" referrerpolicy="strict-origin-when-cross-origin" frameborder="0" style="width: 100%; min-height: ${height}px; border-radius: 8px;"></iframe>`

return {
type: 'html',
value: html,
}
}

/**
* @description Removes an enter from the end of this string if it exists.
*/
Expand Down Expand Up @@ -652,7 +681,9 @@ type Mutate<T extends Block> = T extends PageBlock
? mdast.Paragraph
: T extends File
? mdast.Link
: null
: T extends IframeBlock
? mdast.Html
: null

interface TransformerOptions {
/**
Expand Down Expand Up @@ -957,6 +988,9 @@ export class Transformer {

return link
}
case BlockType.IFRAME: {
return iframeToHTML(block)
}
default:
return null
}
Expand Down

0 comments on commit f0e685b

Please sign in to comment.