-
-
Notifications
You must be signed in to change notification settings - Fork 189
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
[Feature] QuickInsert Text of sub-note #174
Comments
Then absolutely YES! The link content and style are controlled by the template called "QuickInsert". Please update to the latest and replace it with the text below: ${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]
);
}
})} It is part of the plugin's code for embedding the linked note content. Be aware the APIs used in this template may change in future releases. |
Please check for updates on the plugin page and update plugin to 0.7.8. |
Awesome, works like a charme. Thank you very much. |
the provided code snippet does not work anymore. |
The API ${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.ZoteroEvents.addNotifyListener(
notifierName,
(event, type, ids, extraData) => {
if (
event === "modify" &&
type === "item" &&
ids.includes(noteItem.id)
) {
notifyFlag.resolve();
Zotero.Knowledge4Zotero.ZoteroEvents.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]
);
}
})} |
大佬,请问这段粘贴到哪里呢?我直接在【编辑】→【模板】那里改quickinsert的代码不行。 |
Notifier callback registration in As I stated before, this template uses on inner APIs and you should not rely on it. ${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.ZoteroNotifies.registerNotifyListener(
notifierName,
(event, type, ids, extraData) => {
if (
event === "modify" &&
type === "item" &&
ids.includes(noteItem.id)
) {
notifyFlag.resolve();
Zotero.Knowledge4Zotero.ZoteroNotifies.unregisterNotifyListener(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]
);
}
})} |
First of all, thank you very much for your fast bug-support🙏🏼
I wonder if there is a way to modify the QuickInsert button behavior. I would rather have the text of the sub-note inserted into the main note instead of a link to the sub-note. I know that I can click onto the link and insert the sub-note as a "linked Note" but that is plenty of work to do when having loads of sub-notes.
Perhaps creating a different button to really quick insert text of sub-note to main-note would do the thing.
It would also be nice if the text updates in main-note when changing the corresponding sub-note.
I may overlook something but is there any chance to realise this kind of behavior?
The text was updated successfully, but these errors were encountered: