@@ -701,6 +701,72 @@ ipcMain.handle('bookmark-update', async (_, bookmark: Bookmark) => {
701701 return { success : false , error : 'Bookmark not found' } ;
702702} ) ;
703703
704+ // Export bookmarks to file
705+ ipcMain . handle ( 'export-bookmarks' , async ( ) => {
706+ if ( ! currentFilePath || bookmarks . size === 0 ) {
707+ return { success : false , error : 'No bookmarks to export' } ;
708+ }
709+
710+ try {
711+ const handler = getFileHandler ( ) ;
712+ const fileInfo = handler ?. getFileInfo ( ) ;
713+ if ( ! fileInfo ) {
714+ return { success : false , error : 'No file info available' } ;
715+ }
716+
717+ // Generate export filename
718+ const currentDir = path . dirname ( fileInfo . path ) ;
719+ const baseName = path . basename ( fileInfo . path , path . extname ( fileInfo . path ) ) ;
720+ const timestamp = new Date ( ) . toISOString ( ) . substring ( 0 , 10 ) . replace ( / - / g, '' ) ;
721+ const exportPath = path . join ( currentDir , `${ baseName } _bookmarks_${ timestamp } .md` ) ;
722+
723+ // Build markdown content with clickable links
724+ const lines : string [ ] = [
725+ `# Bookmarks` ,
726+ `` ,
727+ `**Source:** \`${ fileInfo . path } \`` ,
728+ `**Exported:** ${ new Date ( ) . toISOString ( ) . replace ( 'T' , ' ' ) . substring ( 0 , 19 ) } ` ,
729+ `**Total Bookmarks:** ${ bookmarks . size } ` ,
730+ `` ,
731+ `---` ,
732+ `` ,
733+ ] ;
734+
735+ // Sort bookmarks by line number
736+ const sortedBookmarks = Array . from ( bookmarks . values ( ) )
737+ . sort ( ( a , b ) => a . lineNumber - b . lineNumber ) ;
738+
739+ for ( const bookmark of sortedBookmarks ) {
740+ // Get the line text
741+ const [ lineData ] = handler ?. getLines ( bookmark . lineNumber , 1 ) || [ ] ;
742+ const lineText = lineData ?. text || '' ;
743+ const truncatedText = lineText . length > 100 ? lineText . substring ( 0 , 100 ) + '...' : lineText ;
744+
745+ lines . push ( `## Line ${ bookmark . lineNumber + 1 } ` ) ;
746+ lines . push ( `` ) ;
747+ if ( bookmark . label ) {
748+ lines . push ( `**Note:** ${ bookmark . label } ` ) ;
749+ lines . push ( `` ) ;
750+ }
751+ // File link in format that some editors/tools can open (VSCode, etc)
752+ lines . push ( `**Link:** \`${ fileInfo . path } :${ bookmark . lineNumber + 1 } \`` ) ;
753+ lines . push ( `` ) ;
754+ lines . push ( `\`\`\`` ) ;
755+ lines . push ( truncatedText ) ;
756+ lines . push ( `\`\`\`` ) ;
757+ lines . push ( `` ) ;
758+ lines . push ( `---` ) ;
759+ lines . push ( `` ) ;
760+ }
761+
762+ fs . writeFileSync ( exportPath , lines . join ( '\n' ) , 'utf-8' ) ;
763+
764+ return { success : true , filePath : exportPath } ;
765+ } catch ( error ) {
766+ return { success : false , error : String ( error ) } ;
767+ }
768+ } ) ;
769+
704770// === Highlights ===
705771
706772ipcMain . handle ( 'highlight-add' , async ( _ , highlight : Highlight ) => {
0 commit comments