抓取文献关键信息+按颜色抓取注释和标记 #1358
Replies: 8 comments 5 replies
-
|
你好,我使用这个模板的过程中有新的标注了,但是笔记无法更新怎么办,可能是哪里出了问题? |
Beta Was this translation helpful? Give feedback.
-
|
你好,使用时出现错误:topItem is not defined,我的是zotero7,这个如何解决? |
Beta Was this translation helpful? Give feedback.
-
|
您好,这个问题怎么解决:getAttachments() cannot be called on attachment items |
Beta Was this translation helpful? Give feedback.
-
|
您好,如果条目类型是会议的话,可以把元数据那里的期刊换成会议吗 |
Beta Was this translation helpful? Give feedback.
-
|
请问,如果文献新做了标签和标记,该如何更新到该篇笔记中? |
Beta Was this translation helpful? Give feedback.
-
|
抱歉,没怎么看邮箱以至于现在才回复。这个我也没弄明白,后面用了功能类似的其他模板,如有需要,我可以在下个工作日分享给你。
Hellokittyboy ***@***.***> 于 2026年4月1日周三 23:03写道:
… 请问,如果文献新做了标签和标记,该如何更新到该篇笔记中?
—
Reply to this email directly, view it on GitHub
<#1358?email_source=notifications&email_token=BXLOBDCJSXWTFFIW3PI7AML4TUVVJA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNRUGEYDKMBQUZZGKYLTN5XKOY3PNVWWK3TUUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#discussioncomment-16410500>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BXLOBDA5NQYXOW5B2RKROOD4TUVVJAVCNFSM6AAAAACWSNW5T6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTMNBRGA2TAMA>
.
You are receiving this because you commented.Message ID:
<windingwind/zotero-better-notes/repo-discussions/1358/comments/16410500@
github.com>
|
Beta Was this translation helpful? Give feedback.
-
|
你好,可以将颜色对应横线(下划线)也导出吗? |
Beta Was this translation helpful? Give feedback.
-
|
你好,如果你是指如下图图1所示的功能的话是可以的。我分别用黄色的下划线和绿色的阴影进行标注,
笔记模板按颜色抓取后按二级标题分类生成在了右侧笔记区域。此外,此模板可以通过点击笔记区域“更新
模板生成内容”来自动更新笔记。
模板内容详见附件。使用方法:分别创建主笔记模板(Generate note from annotations)和子笔记模板
(by color)。在阅读文献创建笔记时使用子笔记模板来创建笔记即可。
[image: image.png]
本模板是在zhikaiyici大佬分享的模板基础上稍作调整得来的。原模板及作者见下图图2,该回答里有
更丰富的内容,比如除按颜色分外还有按标签分的模板,以及诸如模板如何使用,如何按照自己的需要修
改或增减二级标题及其对应的颜色等等,请支持原作,谢谢。
[image: image.png]
tingz071005-svg ***@***.***> 于2026年4月19日周日 17:27写道:
你好,可以将颜色对应横线(下划线)也导出吗?
—
Reply to this email directly, view it on GitHub
<#1358?email_source=notifications&email_token=BXLOBDGPUG5A72E4ON4MGRL4WSLW7A5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNRWGIYTMMBZUZZGKYLTN5XKOY3PNVWWK3TUUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#discussioncomment-16621609>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BXLOBDC7XUKI5EBMY3SWGDT4WSLW7AVCNFSM6AAAAACWSNW5T6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTMNRSGE3DAOI>
.
You are receiving this because you commented.Message ID:
<windingwind/zotero-better-notes/repo-discussions/1358/comments/16621609@
github.com>
// @author zhikaiyici
// @link [PUBLISH PAGE URL](#1129)
// @beforeloop-begin
${await(async() => {
// 辅助函数:检测字符串是否包含中文字符
const containsChinese = (text) => /[\u4e00-\u9fa5]/.test(text);
// 检查标题是否为中文
let isChineseTitle = containsChinese(items[0].getField("title"));
// 获取作者显示内容
let creators = items[0].getCreators();
let authorDisplay = ["", ""];
if (isChineseTitle) {
// 中文标题:显示第一作者全名,格式为“姓名”
if (creators.length > 0) {
let firstAuthor = creators[0];
let fullName = firstAuthor.lastName + firstAuthor.firstName;
if (creators.length > 1) {
authorDisplay[0] = fullName + "等";
}
else {
authorDisplay[0] = fullName;
}
// 正文中显示前10位作者,多于10位加等
if (creators.length > 10) {
authorDisplay[1] = creators.splice(0, 10).map((v) => v.firstName + v.lastName).join("; ");
authorDisplay[1] = authorDisplay[1] + "等";
}
else {
authorDisplay[1] = creators.map((v) => v.firstName + v.lastName).join("; ");
}
}
}
else {
// 非中文标题:显示第一作者姓氏并附加“et al.”
if (creators.length > 0) {
let firstAuthorLastName = creators[0].lastName;
if (creators.length > 1) {
authorDisplay[0] = `${firstAuthorLastName} et al.`;
}
else {
authorDisplay[0] = creators[0].lastName + " " + creators[0].firstName;
}
// 正文中显示前10位作者,多于10位加et al.
if (creators.length > 10) {
authorDisplay[1] = creators.splice(0, 10).map((v) => v.firstName + " " + v.lastName).join("; ");
authorDisplay[1] = authorDisplay[1] + "; et al.";
}
else {
authorDisplay[1] = creators.map((v) => v.firstName + " " + v.lastName).join("; ");
}
}
}
// 非期刊条目显示论文集、大学、出版社、仓库...
let otherName = items[0].getField("proceedingsTitle")
+ items[0].getField("university") + items[0].getField("publisher")
+ items[0].getField("repository") + items[0].getField("institution")
+ items[0].getField("meetingName");
let publicationName = items[0].getField("publicationTitle") + otherName;
let sourceName = items[0].getField("journalAbbreviation") + otherName;
let res = `
<h1> ${items[0].getField('title')} (${items[0].getField("year")}, ${sourceName ? sourceName + ", " : ""} ${authorDisplay[0]})</h1>
<hr/>
<table>
<!-- 第一行:作者 -->
<tr><td style="padding: 5px;">
<b><span style="color: #3c5acc">Author: </span></b> ${authorDisplay[1]}
</td></tr>
<!-- 第二行:来源 -->
<tr><td style="padding: 5px;"><b><span style="color: #3c5acc">Source: </span></b>
${(items[0].getField("volume") + items[0].getField("issue") + items[0].getField("pages")) ?
(publicationName + " (" +
(items[0].getField("volume") ? "Volume: " + items[0].getField("volume") + ", " : '') +
(items[0].getField("issue") ? "Issue: " + items[0].getField("issue") + ", " : '') +
(items[0].getField("pages") ? "Pages: " + items[0].getField("pages") : '') + ")") : publicationName}
${(() => {
if (Zotero.ZoteroStyle) {
let space = " ";
return Array.prototype.map.call(
Zotero.ZoteroStyle.api.renderCell(items[0], "publicationTags").childNodes,
e => {
e.innerText = space + e.innerText + space;
return e.outerHTML
}
).join(space);
}
})()}
</td></tr>
<!-- 第三行:DOI/URL -->
<tr><td style="padding: 5px;">
${(() => {
const doi = items[0].getField("DOI");
if (doi) {
return `<b><span style="color: #3c5acc">DOI: </span></strong></b>
<a href="https://doi.org/${items[0].getField('DOI')}">${items[0].getField('DOI')}</a>`;
} else {
return `<b><span style="color: #3c5acc">URL: </span></strong> </b>
<a href="${items[0].getField('url')}">${items[0].getField('url')}</a>`;
}
})()}
</td></tr>
<!-- 第四行:日期 -->
<tr><td style="padding: 5px;">
<b><span style="color: #3c5acc">Date: </span></b> ${items[0].getField('date')}
</td></tr>
<!-- 第五行:本地链接 -->
<tr><td style="padding: 5px;">
${(() => {
const attachments = Zotero.Items.get(items[0].getAttachments());
if (attachments && attachments.length > 1) {
return `<b><span style="color: #3c5acc">Full Text: </span></b>
<a href=zotero://open-pdf/0_${Zotero.Items.get(items[0].getAttachments()).filter((i) => i.isPDFAttachment())[0].key}>
${Zotero.Items.get(items[0].getAttachments()).filter((i) => i.isPDFAttachment())[0].getFilename()}</a>`;
} else {
if (attachments && attachments.length > 0) {
return `<b><span style="color: #3c5acc">Full Text: </span> </b>
<a href="zotero://open-pdf/0_${attachments[0].key}">${attachments[0].getFilename()}</a>`;
}
else {
return `<b><span style="color: #3c5acc">Full Text: </span></b>`;
}
}
})()}
</td></tr>
<!-- 第六行:摘要 -->
<tr><td style="padding: 5px;">
<b><span style="color: #3c5acc">Abstract: </span></b> <i>${items[0].getField('abstractNote')}</i>
</td></tr>
</table>
`;
return res;
})()}
${await Zotero.BetterNotes.api.template.runItemTemplate("[item]by color", {
itemIds: items.map(item=>item.id),
targetNoteId: targetNoteItem?.id,
dryRun: _env.dryRun
})}
// @beforeloop-end
// @default-begin
// @default-end
#黄色"Background"、红色"Method"、绿色"Conclusion"、蓝色"Innovation"、紫色"Content"、洋红色"Problem"、橙色"Attention"、灰色"Others"
// @use-refresh
${ await(async() => {
// 无法提取ink(涂鸦)注释
const getAnnotationsByColor = async (_item, _color, _annotated) => {
const annots = _item.getAnnotations().filter((i) => i.annotationColor === _color);
const processAnnotation = async (_annoItem) => {
const isNoteType = ["note", "text"].includes(_annoItem.annotationType);
const htmlContent = await Zotero.BetterNotes.api.convert.annotations2html(
[_annoItem],
{
noteItem: targetNoteItem,
ignoreComment: !isNoteType
}
);
const parseComment = (_comment = "") => {
const parsed = _comment.match(/^(.*?)🔤(.*?)🔤(.*?)$/s);
return parsed ? {comment: parsed[1].trim() + parsed[3].trim(), translation: `🔤${parsed[2].trim()}🔤`} : { comment: _comment.trim(), translation: "" };
};
if (!isNoteType) {
const parsedComment = parseComment(_annoItem.annotationComment || "");
// 不将标注格式化为引用块,标注和评论不分段,并加粗评论,评论在标注后
return htmlContent.replace("</p>", parsedComment ? `${parsedComment.translation ? "<br>" + parsedComment.translation: ""}${parsedComment.comment ? "<br><b>" + parsedComment.comment + "</b>" : ""}</p>` : "</p>");
// 不将标注格式化为引用块,标注和评论不分段,并加粗评论,评论在标注前
// return htmlContent.replace("<p>", parsedComment ? `<p>${parsedComment.comment ? "<b>" + parsedComment.comment + "</b><br>" : ""}${parsedComment.translation ? parsedComment.translation + "<br>": ""}` : "<p>");
// 将标注格式化为引用块,标注和评论分段,评论在标注后
// return "<blockquote>" + htmlContent.replace("</p>", parsedComment.translation ? "<br>" + parsedComment.translation + "</p>" : "</p>") + "</blockquote>" + parsedComment.comment;
}
return htmlContent;
};
const results = await Promise.all(annots.map(processAnnotation));
let content = results.join("");
if (_annotated > 1 && content) {
const docTitle = _item.getField("title");
const docLink = `zotero://open-pdf/0_${_item.key}`;
content = `<h3>📄For Document: <a href="${docLink}">${docTitle}</a></h3>${content}`;
}
return content;
};
let background = { value: "", tag: "Background", emoji: "🌏", color: "#ffd400" }; // general.yellow
let method = { value: "", tag: "Method", emoji: "🔬", color: "#ff6666" }; // general.red
let conclusion = { value: "", tag: "Conclusion", emoji: "📜", color: "#5fb236" }; // general.greee
let innovation = { value: "", tag: "Innovation", emoji: "💡", color: "#2ea8e5" }; // general.blue
let content = { value: "", tag: "Content", emoji: "📜", color: "#a28ae5" }; // general.purple
let problem = { value: "", tag: "Problem", emoji: "❓", color: "#e56eee" }; // general.magenta
let attention = { value: "", tag: "Attention", emoji: "❗", color: "#f19837" }; // general.orange
let others = { value: "", tag: "Others", emoji: "🚩", color: "#aaaaaa" }; // general.grey
let myAnnotations = [background, method, conclusion, innovation,content, problem, attention,others];
const attachments = Zotero.Items.get(topItem.getAttachments()).filter((i) => i.isPDFAttachment() || i.isSnapshotAttachment() || i.isEPUBAttachment());
let annotatedAttachment = 0;
for (let attachment of attachments) {
if (attachment.getAnnotations().length > 0)
annotatedAttachment++;
}
await Promise.all(myAnnotations.map(async (myAnnotation) => {
const annotationsPromises = attachments.map((attachment) => getAnnotationsByColor(attachment, myAnnotation.color, annotatedAttachment));
const renderedAnnotationsArray = await Promise.all(annotationsPromises);
const renderedAnnotations = renderedAnnotationsArray.filter(Boolean).join("");
if (renderedAnnotations) {
myAnnotation.value = renderedAnnotations;
}
}));
let res = `
<!-- 生成标签笔记 -->
${(() => {
let res = "";
for (let myAnnotation of myAnnotations) {
res += myAnnotation.value ? `<h2><span style="color: #be1b41">${myAnnotation.emoji + myAnnotation.tag}:</span></h2>${myAnnotation.value}` : '';
}
return res;
})()}
`;
return res;
})()}
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
该模板是结合两位无私奉献的朋友的代码,进行整合
其功能包括了抓取文献关键信息和抓取颜色注释,更适用于
Screenshots
Test on Zotero version
7.0.15 (64-bit)
Test on Better Notes version
2.4.1
Template Type
QuickNote
Template Share Code
Anything else
No response
Beta Was this translation helpful? Give feedback.
All reactions