Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

快速插入(quickinsert):能否直接插入子笔记的正文到主笔记,而不是子笔记的链接? #365

Closed
SYH0323 opened this issue Feb 17, 2023 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@SYH0323
Copy link

SYH0323 commented Feb 17, 2023

是这样的,我记笔记不习惯链接,习惯直接看到正文。
所以现在快速插入很不适应,所以我把quickinsert的代码改成了:
<p><a>${subNoteItem.getNote().trim() }</a></p>
如下图所示。
image
但是这样的结果是,虽然能直接插入笔记正文了,但是却只有文字,没有图片。并且引用信息也丢了(不过有时引用信息是正常的)
image
#174 这个issue里面讲到了更改代码,但是我目测issue里的代码应该不是直接粘贴到quickinsert里面,那应该是怎么操作呢?

@SYH0323 SYH0323 added the help wanted Extra attention is needed label Feb 17, 2023
@windingwind
Copy link
Owner

就是直接粘贴

@SYH0323
Copy link
Author

SYH0323 commented Feb 18, 2023

就是直接粘贴

但是直接复制粘贴到主笔记的话,需要在文献窗口、主笔记窗口之间来回点,并且backlink也没有了,还是希望点better note的那个图标,点击后直接插入子笔记的正文到主笔记中。

@windingwind
Copy link
Owner

你都找到那个模板了,我意思这个模板直接粘贴进入对应的模板位置就行了呀

@SYH0323
Copy link
Author

SYH0323 commented Feb 18, 2023

我把那段代码粘贴到模板编辑器里之后,点插入笔记没反应,难道是放在源码里吗?
这是大佬您在那个帖子里写的代码,我把这个直接粘贴到quickinsert里,点插入笔记没反应。
${await new Promise(async (r) => { let newLines = []; const convertResult = await Zotero.Knowledge4Zotero.NoteUtils.convertNoteLines( subNoteItem, [], true ); const subNoteLines = convertResult.lines; // Prevent note to be too long if (subNoteLines.join("\n").length > 100000) { Zotero.Knowledge4Zotero.ZoteroViews.showProgressWindow( "Better Notes", "The linked note is too long. Import ignored." ); return; } const templateText = await Zotero.Knowledge4Zotero.TemplateController.renderTemplateAsync( "[QuickImport]", "subNoteLines, subNoteItem, noteItem", [subNoteLines, subNoteItem, noteItem] ); newLines.push(templateText); const newLineString = newLines.join("\n"); const notifyFlag = Zotero.Promise.defer(); const notifierName = "insertLinkWait"; Zotero.Knowledge4Zotero.events.addNotifyListener( notifierName, (event, type, ids, extraData) => { if ( event === "modify" && type === "item" && ids.includes(noteItem.id) ) { notifyFlag.resolve(); Zotero.Knowledge4Zotero.events.removeNotifyListener(notifierName); } } ); await Zotero.Knowledge4Zotero.NoteUtils.modifyLineInNote( noteItem, (oldLine) => { Zotero.debug(oldLine); const params = Zotero.Knowledge4Zotero.NoteParse.parseParamsFromLink(link); const newLink = !params.ignore ? link + (link.includes("?") ? "&ignore=1" : "?ignore=1") : link; const linkIndex = Zotero.Knowledge4Zotero.NoteParse.parseLinkIndexInText(oldLine); Zotero.debug(linkIndex); return ${oldLine.slice(0, linkIndex[0])}${newLink}${oldLine.slice(
linkIndex[1]
)}\n${newLineString}; }, lineIndex, true ); // wait the first modify finish await notifyFlag.promise; let hasAttachemnts = false; for (const _n of [subNoteItem, ...convertResult.subNotes]) { if (Zotero.Items.get(_n.getAttachments()).length) { hasAttachemnts = true; break; } } if (hasAttachemnts) { await Zotero.DB.executeTransaction(async () => { await Zotero.Notes.copyEmbeddedImages(subNoteItem, noteItem); for (const subNote of convertResult.subNotes) { await Zotero.Notes.copyEmbeddedImages(subNote, noteItem); } }); await Zotero.Knowledge4Zotero.NoteUtils.scrollWithRefresh( Zotero.Knowledge4Zotero.NoteUtils.currentLine[noteItem.id] ); } })}

@windingwind
Copy link
Owner

原贴更新了模板代码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants