Skip to content
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
13 changes: 12 additions & 1 deletion apps/chrome-extension/src/scripts/copy-lark-docx-as-markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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
Expand All @@ -34,6 +35,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,
},
Expand All @@ -45,6 +48,8 @@ i18next
'部分内容仍在加载中,暂时无法复制。请等待加载完成后重试',
[TranslationKey.NOT_SUPPORT]:
'这不是一个飞书文档页面,无法复制为 Markdown',
[TranslationKey.NOT_SUPPORT_DOC_1_0]:
'这是一个旧版飞书文档页面,无法复制为 Markdown',
},
...zh,
},
Expand All @@ -53,7 +58,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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',
Expand Down Expand Up @@ -53,6 +54,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}}',
Expand All @@ -75,6 +78,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}} 失败',
Expand Down Expand Up @@ -516,7 +521,13 @@ const prepare = async (): Promise<PrepareResult> => {
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)
Expand Down
15 changes: 14 additions & 1 deletion apps/chrome-extension/src/scripts/view-lark-docx-as-markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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',
}

Expand All @@ -35,6 +36,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.',
},
Expand All @@ -48,6 +51,8 @@ i18next
'部分内容仍在加载中,暂时无法复制。请等待加载完成后重试',
[TranslationKey.NOT_SUPPORT]:
'这不是一个飞书文档页面,无法复制为 Markdown',
[TranslationKey.NOT_SUPPORT_DOC_1_0]:
'这是一个旧版飞书文档页面,无法复制为 Markdown',
[TranslationKey.FAILED_TO_OPEN_WINDOW]:
'无法打开新窗口以显示 Markdown',
},
Expand All @@ -58,15 +63,23 @@ 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
}

if (!docx.isReady()) {
Toast.warning({
content: i18next.t(TranslationKey.CONTENT_LOADING),
})

return
}

Expand Down
10 changes: 9 additions & 1 deletion packages/lark/src/docx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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,
Expand Down Expand Up @@ -1547,6 +1547,14 @@ export class Docx {
return false
}

get isDocx(): boolean {
return isDocx()
}

get isDoc(): boolean {
return !isDocx() && isDoc()
}

get rootBlock(): PageBlock | null {
if (!PageMain) {
return null
Expand Down
3 changes: 3 additions & 0 deletions packages/lark/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions packages/lark/src/lark-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
interface Window {
editor?: Object
PageMain?: import('./env').PageMain
Toast?: import('./env').Toast
User?: import('./env').User
Expand Down