Closed fredericky123 closed 2 months ago
值得是如下自动提取注释的代码:
# This template is specifically for importing/sharing, using better
# notes 'import from clipboard': copy the content and
# goto Zotero menu bar, click Edit->New Template from Clipboard.
# Do not copy-paste this to better notes template editor directly.
name: "[Item] gwj1dataview11"
content: |-
<!-- author:xiehui-->
<h1><font size="4">${topItem.getField("title")}</font></h1>
<div><strong>作者</strong>:: ${topItem.getCreators().map((v)=>v.firstName+" "+v.lastName).join("; ")}</div>
<div><strong>出版年份</strong>:: ${topItem.getField('date')}</div>
<div><strong>期刊</strong>:: ${topItem.getField('publicationTitle')}</div>
<div><strong>期刊标签</strong>:: ${{
let space = " "
return Array.prototype.map.call(
Zotero.ZoteroStyle.api.renderCell(topItem, "publicationTags").childNodes,
e => {
e.innerText = space + e.innerText + space;
return e.outerHTML
}
).join(space)
}}$</div>
<div><strong>附件链接</strong>:: <a href="zotero://open-pdf/0_${Zotero.Items.get(topItem.getAttachments())[0].key}">
${Zotero.Items.get(topItem.getAttachments())[0].getFilename()}
</a></div>
<div><strong>创新摘要</strong>:: </div>
${await new Promise(async (r) => {
/*functions */
async function getAnnotation(item) {
if (!item || !item.isAnnotation()) {
return null;
}
let json = await Zotero.Annotations.toJSON(item);
json.id = item.key;
delete json.key;
for (let key in json) {
json[key] = json[key] || "";
}
json.tags = json.tags || [];
return json;
}
async function getAnnotationsByColor(_item, colorFilter) {
const annots = _item.getAnnotations().filter(colorFilter);
if (annots.length === 0) {
return {
html: "",
};
}
let annotations = [];
for (let annot of annots) {
const annotJson = await getAnnotation(annot);
annotJson.attachmentItemID = _item.id;
annotations.push(annotJson);
}
return Zotero.EditorInstanceUtilities.serializeAnnotations(annotations);
}
/*constants */
const attachments = Zotero.Items.get(topItem.getAttachments()).filter((i) =>
i.isPDFAttachment()
);
let res = ``;
const colors = ["#aaaaaa","#ffd400", "#ff6666", "#5fb236", "#2ea8e5", "#a28ae5","#e56eee","#f19837"];
const colorNames = ["💡Innovation","❓Research question", "📄Background", "📚Literature", "🔨Method", "📜Findings","🔭Future direction","🤔Inspiration"];
// Light Gray Yellow Coral Red Olive Green Light Blue Lavender Magenta Deep Orange
/*loop each attachment */
try {
for (let attachment of attachments) {
// res += `<h2>📄For Document:${attachment.attachmentFilename}</h2>`;
for (let i in colors) {
const renderedAnnotations = (
await getAnnotationsByColor(
attachment,
(_annot) => _annot.annotationColor === colors[i]
)
).html;
if (renderedAnnotations) {
res += `<h3><p style="background-color:${colors[i]};">${colorNames[i]}</p></h3>\n${renderedAnnotations}`;
}
}
const renderedAnnotations = (
await getAnnotationsByColor(
attachment,
(_annot) => !colors.includes(_annot.annotationColor)
)
).html;
if (renderedAnnotations) {
res += `<h2><p>Other Annotations</p></h2>\n${renderedAnnotations}`;
}
}
r(res);
} catch (e) {
Zotero.logError(e);
}
})}
模板实现太旧,请参考https://github.com/windingwind/zotero-better-notes/discussions/236
具体问题请联系模板作者,此处关闭
实际上根据颜色collect annotation模板的出处应该是版主 https://github.com/windingwind/zotero-better-notes/discussions/227
Is there an existing issue for this?
Environment
Describe the feature request
Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 根据颜色添加注释时,能添加annotation,但是自己框住的图却没加进来,不知如何解决? 如下图
Why do you need this feature? A clear and concise description of why you need this feature. 给图做注释也很重要,希望在提取的笔记中有所体现
Describe the solution you'd like
The solution you'd like A clear and concise description of what you want to happen.
Alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.
Anything else?
非常感谢