Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(open-knowledge): open non-viewable file links in the asset preview (#1702)

Andrew Mikofalvy636be631c544
diff --git a/.changeset/asset-link-opens-preview.md b/.changeset/asset-link-opens-preview.md
new file mode 100644
index 000000000..0bebdec93
--- /dev/null
+++ b/.changeset/asset-link-opens-preview.md
@@ -0,0 +1,7 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+Clicking a link to a non-markdown file (HTML, archives, Office docs, and other non-viewable types) now opens the same in-app preview the sidebar shows when you select that file, instead of handing the file straight to the operating system.
+
+Previously, once these links resolved, a bare click immediately delegated to the OS (or, for HTML and other scripted types the desktop app refuses to open directly, revealed the file in Finder). A click now lands on the file's preview screen — for non-viewable types that screen offers "Open file" and "Open with built-in text editor" — so the behavior matches selecting the file in the sidebar. Cmd/Ctrl/middle-click still opens the file in the OS default app (desktop) or a new tab (web) as an escape hatch.
diff --git a/packages/app/src/editor/extensions/internal-link.ts b/packages/app/src/editor/extensions/internal-link.ts
index 61b6e77d0..24b37469d 100644
--- a/packages/app/src/editor/extensions/internal-link.ts
+++ b/packages/app/src/editor/extensions/internal-link.ts
@@ -8,8 +8,8 @@ import {
import { type Editor, mergeAttributes } from '@tiptap/core';
import { createElement } from 'react';
import { resolveLinkTargetIntent } from '../../components/link-target-intent';
-import { dispatchAssetClick } from '../asset-dispatch';
import {
+ activateAssetLink,
openHashHrefInNewTab,
openInternalHashHrefInNewTab,
toInternalHashHref,
@@ -85,12 +85,12 @@ export const InternalLink = LinkFidelity.extend<InternalLinkOptions>({
) {
return false;
}
- void dispatchAssetClick({
+ activateAssetLink({
url,
projectRelPath,
ext,
title: projectRelPath.split('/').pop() ?? url,
- forceOsDelegation: newTab,
+ newTab,
});
return true;
}
diff --git a/packages/app/src/editor/extensions/wiki-link-embed.ts b/packages/app/src/editor/extensions/wiki-link-embed.ts
index 6bd4be435..bed0a3ca4 100644
--- a/packages/app/src/editor/extensions/wiki-link-embed.ts
+++ b/packages/app/src/editor/extensions/wiki-link-embed.ts
@@ -5,8 +5,8 @@ import {
resolveAssetProjectPath,
toDesktopAssetHref,
} from '@inkeep/open-knowledge-core';
-import { dispatchAssetClick } from '../asset-dispatch';
import { getInteractionLayer } from '../interaction-layer-host';
+import { activateAssetLink } from '../internal-link-helpers';
let __wikiLinkEmbedNodeIdCounter = 0;
@@ -155,12 +155,12 @@ export const WikiLinkEmbed = BaseWikiLinkEmbed.extend({
if (ext === null) return false;
const projectRelPath = resolveAssetProjectPath(liveUrl, '');
const rel = projectRelPath ?? liveTarget;
- void dispatchAssetClick({
+ activateAssetLink({
url: liveUrl,
projectRelPath: rel,
ext,
title: rel.split('/').pop() ?? liveUrl,
- forceOsDelegation: newTab,
+ newTab,
});
return true;
},
diff --git a/packages/app/src/editor/internal-link-helpers.test.ts b/packages/app/src/editor/internal-link-helpers.test.ts
index bbc0f127f..1b9ac4d25 100644
--- a/packages/app/src/editor/internal-link-helpers.test.ts
+++ b/packages/app/src/editor/internal-link-helpers.test.ts
@@ -1,5 +1,11 @@
-import { describe, expect, it, mock } from 'bun:test';
-import { handleChipLinkClick, toInternalHashHref } from './internal-link-helpers';
+import { afterEach, describe, expect, it, mock } from 'bun:test';
+import {
+ activateAssetLink,
+ handleChipLinkClick,
+ toInternalHashHref,
+} from './internal-link-helpers';
+
+const originalWindow = globalThis.window;
describe('handleChipLinkClick', () => {
function makeEvent(overrides: Partial<{ metaKey: boolean; ctrlKey: boolean }> = {}) {
@@ -50,6 +56,65 @@ describe('handleChipLinkClick', () => {
});
});
+describe('activateAssetLink', () => {
+ const params = {
+ url: './report.html',
+ projectRelPath: 'docs/report.html',
+ ext: 'html',
+ title: 'report.html',
+ };
+
+ it('bare click navigates to the asset preview and does NOT OS-delegate', () => {
+ const navigate = mock((_assetPath: string) => {});
+ const dispatch = mock(async () => {});
+
+ activateAssetLink({ ...params, newTab: false }, { navigate, dispatch });
+
+ expect(navigate).toHaveBeenCalledTimes(1);
+ expect(navigate).toHaveBeenCalledWith('docs/report.html');
+ expect(dispatch).not.toHaveBeenCalled();
+ });
+
+ it('Cmd/Ctrl/middle-click OS-delegates (forceOsDelegation) and does NOT navigate', () => {
+ const navigate = mock((_assetPath: string) => {});
+ const dispatch = mock(async () => {});
+
+ activateAssetLink({ ...params, newTab: true }, { navigate, dispatch });
+
+ expect(dispatch).toHaveBeenCalledTimes(1);
+ expect(dispatch).toHaveBeenCalledWith({
+ url: './report.html',
+ projectRelPath: 'docs/report.html',
+ ext: 'html',
+ title: 'report.html',
+ forceOsDelegation: true,
+ });
+ expect(navigate).not.toHaveBeenCalled();
+ });
+
+ afterEach(() => {
+ Object.defineProperty(globalThis, 'window', {
+ configurable: true,
+ value: originalWindow,
+ writable: true,
+ });
+ });
+
+ it('bare click with no injected deps assigns the canonical asset hash via the default navigate', () => {
+ const assign = mock((_url: string) => {});
+ Object.defineProperty(globalThis, 'window', {
+ configurable: true,
+ value: { location: { assign } },
+ writable: true,
+ });
+
+ activateAssetLink({ ...params, newTab: false });
+
+ expect(assign).toHaveBeenCalledTimes(1);
+ expect(assign).toHaveBeenCalledWith('#/__asset__/docs/report.html');
+ });
+});
+
describe('toInternalHashHref', () => {
it('builds standard fragment anchors for document sections', () => {
expect(toInternalHashHref({ docName: 'docs/guide', anchor: 'install' })).toBe(
diff --git a/packages/app/src/editor/internal-link-helpers.ts b/packages/app/src/editor/internal-link-helpers.ts
index cd93d3763..8fbb32185 100644
--- a/packages/app/src/editor/internal-link-helpers.ts
+++ b/packages/app/src/editor/internal-link-helpers.ts
@@ -4,7 +4,8 @@ import {
classifyMarkdownHref,
type DocLinkTarget,
} from '@inkeep/open-knowledge-core';
-import { hashFromDocName } from '../lib/doc-hash';
+import { hashFromAssetPath, hashFromDocName } from '../lib/doc-hash';
+import { dispatchAssetClick } from './asset-dispatch';
import { isSafeNavigationUrl } from './safe-navigation-url';
export function getCurrentDocNameFromHash(locationHash = window.location.hash): string {
@@ -45,6 +46,36 @@ export function openInternalHashHrefInNewTab(
openHashHrefInNewTab(toInternalHashHref(resolved));
}
+function navigateToAssetPreview(assetPath: string): void {
+ window.location.assign(hashFromAssetPath(assetPath));
+}
+
+interface ActivateAssetLinkParams {
+ url: string;
+ projectRelPath: string;
+ ext: string;
+ title: string;
+ newTab: boolean;
+}
+
+interface ActivateAssetLinkDeps {
+ navigate?: (assetPath: string) => void;
+ dispatch?: typeof dispatchAssetClick;
+}
+
+export function activateAssetLink(
+ { url, projectRelPath, ext, title, newTab }: ActivateAssetLinkParams,
+ deps: ActivateAssetLinkDeps = {},
+): void {
+ const navigate = deps.navigate ?? navigateToAssetPreview;
+ const dispatch = deps.dispatch ?? dispatchAssetClick;
+ if (newTab) {
+ void dispatch({ url, projectRelPath, ext, title, forceOsDelegation: true });
+ return;
+ }
+ navigate(projectRelPath);
+}
+
export function shouldOpenInNewTab(event: { metaKey: boolean; ctrlKey: boolean }): boolean {
return event.metaKey || event.ctrlKey;
}
diff --git a/packages/app/tests/stress/asset-click-dispatch.e2e.ts b/packages/app/tests/stress/asset-click-dispatch.e2e.ts
index 546b727b7..1eca592ff 100644
--- a/packages/app/tests/stress/asset-click-dispatch.e2e.ts
+++ b/packages/app/tests/stress/asset-click-dispatch.e2e.ts
@@ -133,18 +133,48 @@ test.describe('asset-click dispatcher — P9 E2E scenarios (SPEC 2026-04-23)', (
expect(openedPage).toBeNull();
});
- test('P9.10: hand-authored [spec](./file.pdf) click → dispatcher fires → new tab', async ({
+ test('P9.10: hand-authored [guide](./file.html) bare click → in-app asset preview (no new tab)', async ({
page,
api,
context,
workerServer,
}) => {
- writeFileSync(join(workerServer.contentDir, 'reference.pdf'), new Uint8Array(TINY_PDF_BYTES));
+ writeFileSync(
+ join(workerServer.contentDir, 'guide.html'),
+ '<!doctype html><meta charset="utf-8"><title>Guide</title><p>hi</p>',
+ );
- await api.replaceDoc(
- docName,
- `# Markdown link test\n\nSee [the spec](./reference.pdf) for details.\n`,
+ await api.replaceDoc(docName, `# Markdown link test\n\nSee [the guide](./guide.html).\n`);
+
+ await page.goto(`/#/${docName}`);
+ await waitForProvider(page);
+ await page.waitForSelector('.ProseMirror');
+ await expect(page.locator('[data-resolution-state="asset"]').first()).toBeVisible({
+ timeout: 10_000,
+ });
+
+ await page.click('span[data-link]');
+
+ await expect
+ .poll(async () => page.evaluate(() => window.location.hash))
+ .toBe('#/__asset__/guide.html');
+ await expect(page.getByTestId('asset-preview-open-as-text')).toBeVisible({ timeout: 5_000 });
+
+ const openedPage = await context.waitForEvent('page', { timeout: 1_000 }).catch(() => null);
+ expect(openedPage).toBeNull();
+ });
+
+ test('P9.10b: Cmd/Ctrl+click on the same link is the OS-delegation escape hatch → new tab', async ({
+ page,
+ api,
+ context,
+ workerServer,
+ }) => {
+ writeFileSync(
+ join(workerServer.contentDir, 'guide.html'),
+ '<!doctype html><meta charset="utf-8"><title>Guide</title><p>hi</p>',
);
+ await api.replaceDoc(docName, `# Markdown link test\n\nSee [the guide](./guide.html).\n`);
await page.goto(`/#/${docName}`);
await waitForProvider(page);
@@ -164,7 +194,7 @@ test.describe('asset-click dispatcher — P9 E2E scenarios (SPEC 2026-04-23)', (
const [newPage] = await Promise.all([
context.waitForEvent('page', { timeout: 5_000 }),
- page.click('span[data-link]'),
+ page.click('span[data-link]', { modifiers: ['Meta'] }),
]);
await expect
.poll(async () =>
@@ -172,7 +202,7 @@ test.describe('asset-click dispatcher — P9 E2E scenarios (SPEC 2026-04-23)', (
return (window as typeof window & { __assetOpenCalls?: string[] }).__assetOpenCalls ?? [];
}),
)
- .toContain('./reference.pdf');
+ .toContain('./guide.html');
await newPage.close();
});