diff --git a/packages/basic-modules/src/modules/link/helper.ts b/packages/basic-modules/src/modules/link/helper.ts index 75fc9cf2c..844a82f68 100644 --- a/packages/basic-modules/src/modules/link/helper.ts +++ b/packages/basic-modules/src/modules/link/helper.ts @@ -88,6 +88,10 @@ function genLinkNode(url: string, text?: string): LinkElement { * @param url url */ export async function insertLink(editor: IDomEditor, text: string, url: string) { + // 校验 + const checkRes = await check('insertLink', editor, text, url) + if (!checkRes) return // 校验未通过 + if (!url) return if (!text) text = url // 无 text 则用 url 代替 @@ -96,10 +100,6 @@ export async function insertLink(editor: IDomEditor, text: string, url: string) if (isMenuDisabled(editor)) return - // 校验 - const checkRes = await check('insertLink', editor, text, url) - if (!checkRes) return // 校验未通过 - // 转换 url const parsedUrl = await parse('insertLink', editor, url) @@ -142,12 +142,12 @@ export async function insertLink(editor: IDomEditor, text: string, url: string) * @param url link url */ export async function updateLink(editor: IDomEditor, text: string, url: string) { - if (!url) return - // 校验 const checkRes = await check('editLink', editor, text, url) if (!checkRes) return // 校验未通过 + if (!url) return + // 转换 url const parsedUrl = await parse('editLink', editor, url)