Skip to content

Commit 9ce6abe

Browse files
authored
feat(terminal): open .md file links in built-in markdown viewer (#45)
* feat(terminal): add clickable file path links File paths in terminal output are now highlighted and clickable. Supports absolute, relative, bare, and @Scoped paths with :line:col suffixes. Trailing punctuation is stripped. An onFileLink callback prop allows parent components to handle specific file types. * feat(terminal): open .md file links in built-in markdown viewer Clicking a .md file link in the terminal opens it in a resizable markdown viewer dialog with syntax highlighting. Cmd+click opens the file externally instead. Non-.md files always open externally. --------- Co-authored-by: maskar <Maskar@users.noreply.github.com>
1 parent 21701eb commit 9ce6abe

5 files changed

Lines changed: 317 additions & 133 deletions

File tree

electron/ipc/channels.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ export enum IPC {
9898
// System
9999
GetSystemFonts = 'get_system_fonts',
100100

101+
// File links
102+
OpenPath = 'open_path',
103+
ReadFileText = 'read_file_text',
104+
101105
// Notifications
102106
ShowNotification = 'show_notification',
103107
NotificationClicked = 'notification_clicked',

electron/ipc/register.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,17 @@ export function registerAllHandlers(win: BrowserWindow): void {
452452
cancelAskAboutCode(args.requestId);
453453
});
454454

455+
// --- File links ---
456+
ipcMain.handle(IPC.OpenPath, (_e, args) => {
457+
validatePath(args.filePath, 'filePath');
458+
return shell.openPath(args.filePath);
459+
});
460+
461+
ipcMain.handle(IPC.ReadFileText, (_e, args) => {
462+
validatePath(args.filePath, 'filePath');
463+
return fs.readFileSync(args.filePath, 'utf8');
464+
});
465+
455466
// --- System ---
456467
ipcMain.handle(IPC.GetSystemFonts, () => getSystemMonospaceFonts());
457468

electron/preload.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ const ALLOWED_CHANNELS = new Set([
9090
'cancel_ask_about_code',
9191
// System
9292
'get_system_fonts',
93+
// File links
94+
'open_path',
95+
'read_file_text',
9396
// Notifications
9497
'show_notification',
9598
'notification_clicked',

0 commit comments

Comments
 (0)