windingwind / zotero-better-notes

Everything about note management. All in Zotero.
GNU Affero General Public License v3.0
5.59k stars 188 forks source link

(2024.8.19更新代码)我使用win10,程序安装版zotero7.0.1 beta3 (zotero7正式版也能用) betternote 和zotero style 已升级最新版(请注意,这两个插件必须安装!!!,友好建议:如果有问题,检查插件是否正确安装,如果仍然有问题,先到右上角 搜索问题,可以检索到其他讨论中是否提过,之后再提问,希望最好能够提供复现错误的步骤),其他插件版本或许也适用,没有做验证。 #1120

Closed shuaichennn closed 2 months ago

shuaichennn commented 2 months ago

(2024.8.19更新代码)我使用win10,程序安装版zotero7.0.1 beta3 (zotero7正式版也能用) betternote 和zotero style 已升级最新版(请注意,这两个插件必须安装!!!,友好建议:如果有问题,检查插件是否正确安装,如果仍然有问题,先到右上角 搜索问题,可以检索到其他讨论中是否提过,之后再提问,希望最好能够提供复现错误的步骤),其他插件版本或许也适用,没有做验证。

(2024.8.30 修改新增模板代码) 可以根据颜色自动将注释分类(包括文本和图片)。 注意,这里指的图片是如下图红框所示的注释图片可以自动被收集到笔记中。其他的例如绘图等等类型暂不支持。 image

提供示例代码如下,可以根据自己喜好改变colorNames内容的顺序对应相应的颜色。如果向每次打开文献都能自动更新笔记,请增加action插件,具体查看https://github.com/windingwind/zotero-actions-tags/discussions/108#discussioncomment-10440673

效果:1.保持了简洁性,去掉了前面表格,保留了期刊,日期,作者,期刊标签等

  1. 采用了div换行,实现了导出obsidian没有“\”的比较完美的效果
  2. 为了适应dataview检索,采用英文双冒号的形式,其中创新摘要:: 是为了dataview中直观展示文献核心创新

大家可以根据自己需要适当修改模板和代码。 obsidian中dataview代码如下(如果不需要obsidian,本条可以不看,直接复制better-notes的模板代码即可):

table 出版年份,作者,创新摘要
from  "02-Reading/07-zotero本身笔记"  双引号内是同步文件夹目录,改为自己的即可

better-notes具体模板代码如下: 复制如下代码,点击zotero 工具--从剪切板导入笔记模板

# 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] gwj1dataview"
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>

  <h2 style="color:#2E7D32; background-color:    #F1F8E9;">🔬 研究方法</h2> <hr/>
  <p></p>
  <h2 style="color:#4A148C; background-color:    #F5F5F5;">🚩 结论</h2> <hr/>
  <p></p>
  <h2 style="color: #006064; background-color:   #E0F7FA;">📌 思路 </h2> <hr/>
  <p></p>
  <h2 style="color:#1565C0; background-color:   #E1F5FE;">🔬 借鉴点(图表,语句)</h2> <hr/>

根据颜色自动对注释分类的代码如下:

# 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>

  ${{
    async function getAnnotationsByColor(item, colorFilter) {
      const annots = item.getAnnotations().filter(colorFilter);
    return await Zotero.BetterNotes.api.convert.annotations2html(annots, { noteItem: targetNoteItem });
    }

    const attachments = Zotero.Items.get(topItem.getAttachments()).filter((i) =>
      i.isPDFAttachment() || i.isSnapshotAttachment() || i.isEPUBAttachment()
    );
    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

    for (let attachment of attachments) {
     // res += `<h1>${attachment.getFilename()}</h1>`;
      for (let i in colors) {
        const renderedAnnotations = (
          await getAnnotationsByColor(
            attachment,
            (annot) => annot.annotationColor === colors[i]
          )
        );
        if (renderedAnnotations) {
          res += `<h2><p style="background-color:${colors[i]};">${colorNames[i]} </p></h2>\n${renderedAnnotations}`;
        }
      }
      const renderedAnnotations = (
        await getAnnotationsByColor(
          attachment,
          (annot) => !colors.includes(annot.annotationColor)
        )
      );
      if (renderedAnnotations) {
        res += `<h2><p>Other Annotations</p></h2>\n${renderedAnnotations}`;
      }
    }
    return res;
  }}$

Originally posted by @thebetter2 in https://github.com/windingwind/zotero-better-notes/discussions/668

windingwind commented 2 months ago

请发布在discussion对应栏