diff --git a/src/renderer/plugins/editor-attachment.ts b/src/renderer/plugins/editor-attachment.ts index 784800d4..fbe12484 100644 --- a/src/renderer/plugins/editor-attachment.ts +++ b/src/renderer/plugins/editor-attachment.ts @@ -24,7 +24,7 @@ async function uploadFile (file: any, asImage: boolean) { if (asImage) { insert(`![Img](${encodeMarkdownLink(assetPath)})\n`) } else { - insert(`[${dayjs().format('YYYY-MM-DD HH:mm')}] [${file.name} (${(file.size / 1024).toFixed(2)}KiB)](${encodeMarkdownLink(assetPath)}){class=open target=_blank}\n`) + insert(`[${dayjs().format('YYYY-MM-DD HH:mm')}] [${file.name} (${(file.size / 1024).toFixed(2)}KiB)](${encodeMarkdownLink(assetPath)}){.open}\n`) } refreshTree() diff --git a/src/renderer/plugins/markdown-link.ts b/src/renderer/plugins/markdown-link.ts index 0d105e66..c91179f9 100644 --- a/src/renderer/plugins/markdown-link.ts +++ b/src/renderer/plugins/markdown-link.ts @@ -6,7 +6,7 @@ import { sleep } from '@fe/utils' import { isElectron } from '@fe/support/env' import { basename, dirname, join, resolve } from '@fe/utils/path' import { switchDoc } from '@fe/services/document' -import { openExternal, openPath } from '@fe/services/base' +import { getRepo, openExternal, openPath } from '@fe/services/base' const handleLink = (link: HTMLAnchorElement, view: HTMLElement) => { const { currentFile } = store.state @@ -17,11 +17,6 @@ const handleLink = (link: HTMLAnchorElement, view: HTMLElement) => { const { repo: fileRepo, path: filePath } = currentFile // open attachment in os - if (link.classList.contains('open')) { - fetch(link.href.replace('api/attachment', 'api/open')) - return true - } - const href = link.getAttribute('href') || '' if (/^(http:|https:|ftp:)\/\//i.test(href)) { // external link @@ -32,6 +27,10 @@ const handleLink = (link: HTMLAnchorElement, view: HTMLElement) => { } else if (/^file:\/\//i.test(href)) { openPath(decodeURI(href.replace(/^file:\/\//i, ''))) return true + } else if (link.classList.contains('open')) { + const path = link.getAttribute('origin-href') || decodeURI(href) + openPath(join(getRepo(fileRepo)?.path || '/', path)) + return true } else { // relative link // better scrollIntoView const scrollIntoView = (el: HTMLElement) => {