@@ -620,45 +620,40 @@ class Knowledge extends AddonBase {
620620 saveNote : boolean = false ,
621621 saveCopy : boolean = false
622622 ) {
623+ if ( ! saveFile && ! saveNote && ! saveCopy ) {
624+ return ;
625+ }
623626 note = note || this . getWorkspaceNote ( ) ;
624- if ( convertNoteLinks ) {
625- const noteID = await ZoteroPane_Local . newNote ( ) ;
626- const item = Zotero . Items . get ( noteID ) ;
627- const rootNoteIds = [ note . id ] ;
628-
629- const newLines = await this . convertNoteLines (
630- note ,
631- rootNoteIds ,
632- convertNoteLinks ,
633- convertNoteImages
634- ) ;
627+ const noteID = await ZoteroPane_Local . newNote ( ) ;
628+ const item = Zotero . Items . get ( noteID ) ;
629+ const rootNoteIds = [ note . id ] ;
635630
636- this . setLinesToNote ( item , newLines ) ;
637- if ( saveFile ) {
638- const exporter = new Zotero_File_Exporter ( ) ;
639- exporter . items = [ item ] ;
640- await exporter . save ( ) ;
641- }
631+ const newLines = await this . convertNoteLines (
632+ note ,
633+ rootNoteIds ,
634+ convertNoteLinks ,
635+ convertNoteImages
636+ ) ;
637+
638+ this . setLinesToNote ( item , newLines ) ;
639+ if ( saveFile ) {
640+ const exporter = new Zotero_File_Exporter ( ) ;
641+ exporter . items = [ item ] ;
642+ await exporter . save ( ) ;
643+ }
644+ if ( saveCopy ) {
645+ Zotero_File_Interface . exportItemsToClipboard (
646+ [ item ] ,
647+ Zotero . Translators . TRANSLATOR_ID_MARKDOWN_AND_RICH_TEXT
648+ ) ;
649+ this . _Addon . views . showProgressWindow ( "Better Notes" , "Note Copied" ) ;
650+ }
651+ if ( ! saveNote ) {
642652 if ( saveCopy ) {
643- Zotero_File_Interface . exportItemsToClipboard (
644- [ item ] ,
645- Zotero . Translators . TRANSLATOR_ID_MARKDOWN_AND_RICH_TEXT
646- ) ;
647- this . _Addon . views . showProgressWindow ( "Better Notes" , "Note Copied" ) ;
648- }
649- if ( ! saveNote ) {
650- if ( saveCopy ) {
651- // Wait copy finish
652- await Zotero . Promise . delay ( 500 ) ;
653- }
654- await Zotero . Items . erase ( item . id ) ;
655- }
656- } else {
657- if ( saveFile ) {
658- const exporter = new Zotero_File_Exporter ( ) ;
659- exporter . items = [ note ] ;
660- exporter . save ( ) ;
653+ // Wait copy finish
654+ await Zotero . Promise . delay ( 500 ) ;
661655 }
656+ await Zotero . Items . erase ( item . id ) ;
662657 }
663658 }
664659
@@ -670,9 +665,7 @@ class Knowledge extends AddonBase {
670665 if ( imageIndex !== - 1 ) {
671666 const lineStart = line . slice ( 0 , imageIndex ) ;
672667 const imageLine = line . slice ( imageIndex ) ;
673- const lineEnd = line . slice (
674- imageLine . search ( imageBrReg ) + imageBrReg . source . length + 3
675- ) ;
668+ const lineEnd = imageLine . slice ( imageLine . search ( imageBrReg ) ) ;
676669 const attachmentKeyIndex = imageLine . search ( imageKeyReg ) ;
677670
678671 if ( attachmentKeyIndex !== - 1 ) {
@@ -690,6 +683,9 @@ class Knowledge extends AddonBase {
690683 // const imageData = await editorInstance._getDataURL(
691684 // attachmentItem
692685 // );
686+ Zotero . debug ( line ) ;
687+ Zotero . debug ( lineStart ) ;
688+ Zotero . debug ( lineEnd ) ;
693689 newLines . push ( `<p>!<a href="${ attachmentURL } ">image</a></p>` ) ;
694690 newLines . push ( `${ lineStart } ${ lineEnd } ` ) ;
695691 return true ;
@@ -725,32 +721,34 @@ class Knowledge extends AddonBase {
725721 }
726722 newLines . push ( noteLines [ i ] ) ;
727723 // Convert Link
728- let link = this . getLinkFromText ( noteLines [ i ] ) ;
729- while ( link ) {
730- Zotero . debug ( "convert link" ) ;
731- let res = await this . getNoteFromLink ( link ) ;
732- const subNote = res . item ;
733- if ( subNote && _rootNoteIds . indexOf ( subNote . id ) === - 1 ) {
734- Zotero . debug ( `Knowledge4Zotero: Exporting sub-note ${ link } ` ) ;
735- newLines . push ( "<blockquote>" ) ;
736- newLines . push ( `<p><strong>Linked Note:</strong></p>` ) ;
737- newLines = newLines . concat (
738- await this . convertNoteLines (
739- subNote ,
740- _rootNoteIds ,
741- convertNoteLinks ,
742- convertNoteImages
743- )
724+ if ( convertNoteLinks ) {
725+ let link = this . getLinkFromText ( noteLines [ i ] ) ;
726+ while ( link ) {
727+ Zotero . debug ( "convert link" ) ;
728+ let res = await this . getNoteFromLink ( link ) ;
729+ const subNote = res . item ;
730+ if ( subNote && _rootNoteIds . indexOf ( subNote . id ) === - 1 ) {
731+ Zotero . debug ( `Knowledge4Zotero: Exporting sub-note ${ link } ` ) ;
732+ newLines . push ( "<blockquote>" ) ;
733+ newLines . push ( `<p><strong>Linked Note:</strong></p>` ) ;
734+ newLines = newLines . concat (
735+ await this . convertNoteLines (
736+ subNote ,
737+ _rootNoteIds ,
738+ convertNoteLinks ,
739+ convertNoteImages
740+ )
741+ ) ;
742+ newLines . push ( "</blockquote>" ) ;
743+ }
744+ noteLines [ i ] = noteLines [ i ] . substring (
745+ noteLines [ i ] . search ( / z o t e r o : \/ \/ n o t e \/ / g)
746+ ) ;
747+ noteLines [ i ] = noteLines [ i ] . substring (
748+ noteLines [ i ] . search ( / < \/ a > / g) + "</a>" . length
744749 ) ;
745- newLines . push ( "</blockquote>" ) ;
750+ link = this . getLinkFromText ( noteLines [ i ] ) ;
746751 }
747- noteLines [ i ] = noteLines [ i ] . substring (
748- noteLines [ i ] . search ( / z o t e r o : \/ \/ n o t e \/ / g)
749- ) ;
750- noteLines [ i ] = noteLines [ i ] . substring (
751- noteLines [ i ] . search ( / < \/ a > / g) + "</a>" . length
752- ) ;
753- link = this . getLinkFromText ( noteLines [ i ] ) ;
754752 }
755753 }
756754 return newLines ;
0 commit comments