From 2589091f611417ebfbd4bdaa32c5735a68217f24 Mon Sep 17 00:00:00 2001 From: jiyee Date: Wed, 21 Jan 2026 18:43:29 +0800 Subject: [PATCH 1/2] feat(lark): show error message on lark document v1.0 --- .../src/scripts/copy-lark-docx-as-markdown.ts | 13 ++++++++++++- .../src/scripts/download-lark-docx-as-markdown.ts | 13 ++++++++++++- .../src/scripts/view-lark-docx-as-markdown.ts | 15 ++++++++++++++- packages/lark/src/docx.ts | 10 +++++++++- packages/lark/src/env.ts | 3 +++ packages/lark/src/lark-env.d.ts | 1 + 6 files changed, 51 insertions(+), 4 deletions(-) diff --git a/apps/chrome-extension/src/scripts/copy-lark-docx-as-markdown.ts b/apps/chrome-extension/src/scripts/copy-lark-docx-as-markdown.ts index 8a281a7..b73829f 100644 --- a/apps/chrome-extension/src/scripts/copy-lark-docx-as-markdown.ts +++ b/apps/chrome-extension/src/scripts/copy-lark-docx-as-markdown.ts @@ -17,6 +17,7 @@ const enum TranslationKey { UNKNOWN_ERROR = 'unknown_error', CONTENT_LOADING = 'content_loading', NOT_SUPPORT = 'not_support', + NOT_SUPPORT_DOC_1_0 = 'not_support_doc_1_0', } i18next @@ -31,6 +32,8 @@ i18next 'Part of the content is still loading and cannot be copied at the moment. Please wait for loading to complete and retry', [TranslationKey.NOT_SUPPORT]: 'This is not a lark document page and cannot be copied as Markdown', + [TranslationKey.NOT_SUPPORT_DOC_1_0]: + 'This is a old version lark document page and cannot be copied as Markdown', }, ...en, }, @@ -42,6 +45,8 @@ i18next '部分内容仍在加载中,暂时无法复制。请等待加载完成后重试', [TranslationKey.NOT_SUPPORT]: '这不是一个飞书文档页面,无法复制为 Markdown', + [TranslationKey.NOT_SUPPORT_DOC_1_0]: + '这是一个旧版飞书文档页面,无法复制为 Markdown', }, ...zh, }, @@ -50,7 +55,13 @@ i18next .catch(console.error) const main = async () => { - if (!docx.rootBlock) { + if (docx.isDoc) { + Toast.warning({ content: i18next.t(TranslationKey.NOT_SUPPORT_DOC_1_0) }) + + return + } + + if (!docx.isDocx) { Toast.warning({ content: i18next.t(TranslationKey.NOT_SUPPORT) }) return diff --git a/apps/chrome-extension/src/scripts/download-lark-docx-as-markdown.ts b/apps/chrome-extension/src/scripts/download-lark-docx-as-markdown.ts index 179ff96..a13e04a 100644 --- a/apps/chrome-extension/src/scripts/download-lark-docx-as-markdown.ts +++ b/apps/chrome-extension/src/scripts/download-lark-docx-as-markdown.ts @@ -25,6 +25,7 @@ const enum TranslationKey { CONTENT_LOADING = 'content_loading', UNKNOWN_ERROR = 'unknown_error', NOT_SUPPORT = 'not_support', + NOT_SUPPORT_DOC_1_0 = 'not_support_doc_1_0', DOWNLOADING_FILE = 'downloading_file', FAILED_TO_DOWNLOAD = 'failed_to_download', DOWNLOAD_PROGRESS = 'download_progress', @@ -52,6 +53,8 @@ i18next [TranslationKey.UNKNOWN_ERROR]: 'Unknown error during download', [TranslationKey.NOT_SUPPORT]: 'This is not a lark document page and cannot be downloaded as Markdown', + [TranslationKey.NOT_SUPPORT_DOC_1_0]: + 'This is a old version lark document page and cannot be downloaded as Markdown', [TranslationKey.DOWNLOADING_FILE]: 'Download {{name}} in: {{progress}}% (please do not refresh or close the page)', [TranslationKey.FAILED_TO_DOWNLOAD]: 'Failed to download {{name}}', @@ -74,6 +77,8 @@ i18next [TranslationKey.UNKNOWN_ERROR]: '下载过程中出现未知错误', [TranslationKey.NOT_SUPPORT]: '这不是一个飞书文档页面,无法下载为 Markdown', + [TranslationKey.NOT_SUPPORT_DOC_1_0]: + '这是一个旧版飞书文档页面,无法下载为 Markdown', [TranslationKey.DOWNLOADING_FILE]: '下载 {{name}} 中:{{progress}}%(请不要刷新或关闭页面)', [TranslationKey.FAILED_TO_DOWNLOAD]: '下载 {{name}} 失败', @@ -479,7 +484,13 @@ const prepare = async (): Promise => { const main = async (options: { signal?: AbortSignal } = {}) => { const { signal } = options - if (!docx.rootBlock) { + if (docx.isDoc) { + Toast.warning({ content: i18next.t(TranslationKey.NOT_SUPPORT_DOC_1_0) }) + + throw new Error(DOWNLOAD_ABORTED) + } + + if (!docx.isDocx) { Toast.warning({ content: i18next.t(TranslationKey.NOT_SUPPORT) }) throw new Error(DOWNLOAD_ABORTED) diff --git a/apps/chrome-extension/src/scripts/view-lark-docx-as-markdown.ts b/apps/chrome-extension/src/scripts/view-lark-docx-as-markdown.ts index 96d7fa9..cd136f0 100644 --- a/apps/chrome-extension/src/scripts/view-lark-docx-as-markdown.ts +++ b/apps/chrome-extension/src/scripts/view-lark-docx-as-markdown.ts @@ -17,6 +17,7 @@ const enum TranslationKey { UNKNOWN_ERROR = 'unknown_error', CONTENT_LOADING = 'content_loading', NOT_SUPPORT = 'not_support', + NOT_SUPPORT_DOC_1_0 = 'not_support_doc_1_0', FAILED_TO_OPEN_WINDOW = 'failed_to_open_window', } @@ -32,6 +33,8 @@ i18next 'Part of the content is still loading and cannot be copied at the moment. Please wait for loading to complete and retry', [TranslationKey.NOT_SUPPORT]: 'This is not a lark document page and cannot be copied as Markdown', + [TranslationKey.NOT_SUPPORT_DOC_1_0]: + 'This is a old version lark document page and cannot be copied as Markdown', [TranslationKey.FAILED_TO_OPEN_WINDOW]: 'Failed to Open a new window to display markdown.', }, @@ -45,6 +48,8 @@ i18next '部分内容仍在加载中,暂时无法复制。请等待加载完成后重试', [TranslationKey.NOT_SUPPORT]: '这不是一个飞书文档页面,无法复制为 Markdown', + [TranslationKey.NOT_SUPPORT_DOC_1_0]: + '这是一个旧版飞书文档页面,无法复制为 Markdown', [TranslationKey.FAILED_TO_OPEN_WINDOW]: '无法打开新窗口以显示 Markdown', }, @@ -55,8 +60,15 @@ i18next .catch(console.error) const main = async () => { - if (!docx.rootBlock) { + if (docx.isDoc) { + Toast.warning({ content: i18next.t(TranslationKey.NOT_SUPPORT_DOC_1_0) }) + + return + } + + if (!docx.isDocx) { Toast.warning({ content: i18next.t(TranslationKey.NOT_SUPPORT) }) + return } @@ -64,6 +76,7 @@ const main = async () => { Toast.warning({ content: i18next.t(TranslationKey.CONTENT_LOADING), }) + return } diff --git a/packages/lark/src/docx.ts b/packages/lark/src/docx.ts index c611e06..4e1d814 100644 --- a/packages/lark/src/docx.ts +++ b/packages/lark/src/docx.ts @@ -13,7 +13,7 @@ import { gfmStrikethroughToMarkdown } from 'mdast-util-gfm-strikethrough' import { gfmTaskListItemToMarkdown } from 'mdast-util-gfm-task-list-item' import { gfmTableToMarkdown } from 'mdast-util-gfm-table' import { mathToMarkdown, type InlineMath } from 'mdast-util-math' -import { PageMain, User } from './env' +import { PageMain, User, isDoc, isDocx } from './env' import { isBlockquoteContent, isParent, @@ -1292,6 +1292,14 @@ export class Docx { }) } + get isDocx(): boolean { + return isDocx() + } + + get isDoc(): boolean { + return !isDocx() && isDoc() + } + get rootBlock(): PageBlock | null { if (!PageMain) { return null diff --git a/packages/lark/src/env.ts b/packages/lark/src/env.ts index 498c69d..3fcc876 100644 --- a/packages/lark/src/env.ts +++ b/packages/lark/src/env.ts @@ -56,3 +56,6 @@ export interface PageMain { } export const PageMain: PageMain | undefined = window.PageMain + +export const isDoc = (): boolean => window.editor !== undefined +export const isDocx = (): boolean => window.PageMain !== undefined diff --git a/packages/lark/src/lark-env.d.ts b/packages/lark/src/lark-env.d.ts index ac2ee29..7658d25 100644 --- a/packages/lark/src/lark-env.d.ts +++ b/packages/lark/src/lark-env.d.ts @@ -1,4 +1,5 @@ interface Window { + editor?: Object PageMain?: import('./env').PageMain Toast?: import('./env').Toast User?: import('./env').User From 436f20e0dc6067589ca4c6027f461a54d4753159 Mon Sep 17 00:00:00 2001 From: Julian Lu Date: Thu, 22 Jan 2026 03:59:55 +0000 Subject: [PATCH 2/2] chore: format code --- packages/lark/src/docx.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/lark/src/docx.ts b/packages/lark/src/docx.ts index 5acb14c..216f505 100644 --- a/packages/lark/src/docx.ts +++ b/packages/lark/src/docx.ts @@ -1532,7 +1532,7 @@ export class Docx { ], }) } - + static async locateBlockWithRecordId(recordId: string): Promise { try { if (!PageMain) {