Skip to content

Commit

Permalink
让导出的笔记带着tag
Browse files Browse the repository at this point in the history
  • Loading branch information
zzlb0224 committed Apr 2, 2024
1 parent 2424992 commit 4a43589
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/modules/annotationsToNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,12 +707,16 @@ function getAllAnnotations(items: Zotero.Item[]) {
async function convertHtml(arr: AnnotationRes[], targetNoteItem: Zotero.Item) {
const data = arr.map(async (ann) => {
//TODO 感觉这个方法读取图片是从缓存里面读取的,有些图片没有加载成功
ann.html = await Zotero.BetterNotes.api.convert.annotations2html(
const html = (await Zotero.BetterNotes.api.convert.annotations2html(
[ann.ann],
{
noteItem: targetNoteItem,
},
);
)) as string;
if (html)
ann.html = html
.replace(/<\/p>$/, getColorTags(ann.tags.map((c) => c.tag)) + "</p>")
.replace(/<p>[\s\r\n]*<\/p>/g, "");
return ann;
});
//使用Promise.all能并行计算?感觉比for快很多
Expand Down Expand Up @@ -911,9 +915,7 @@ async function exportNoteByType(
.flatMap((pdfTitle, index, aa) => [
`<h1> (${index + 1}/${aa.length}) ${pdfTitle.key} ${getCiteItemHtml(pdfTitle.values[0]?.item)} (${pdfTitle.values.length})</h1>`,
...pdfTitle.values.flatMap((b) => [
b.html
? b.html
: `<span style="color:#ff6666">未能加载:${b.ann.key}</span>`,
b.html ? b.html : getCiteAnnotationHtml(b.ann), // `<span style="color:#ff6666">未能加载:${b.ann.key}</span>`
]),
])
.join("\n"),
Expand All @@ -924,6 +926,7 @@ async function exportNoteByType(
},
});
}

async function exportSingleNote(tag: string, isCollection: boolean = false) {
if (tag)
exportNote({
Expand All @@ -938,6 +941,7 @@ async function exportSingleNote(tag: string, isCollection: boolean = false) {
a.values
.map(
(b) =>
b.html ??
`<h2>${getCiteAnnotationHtml(b.ann, b.ann.annotationText + b.ann.annotationComment)}</h2>`,
)
.join(" "),
Expand Down Expand Up @@ -971,15 +975,7 @@ function toText1(ans: AnnotationRes[]) {
.sort(sortKey)
.flatMap((a, index, aa) => [
`<h1>(${index + 1}/${aa.length}) ${a.key} ${getCiteItemHtmlWithPage(a.values[0].ann)}</h1>`,
a.values
.map((b) =>
b.html.replace(
/<\/p>$/,
getColorTags(b.tags.map((c) => c.tag)) + "</p>",
),
)
.map((b) => b.replace(/<p>[\r\n]*<\/p>/g, ""))
.join(" "),
a.values.map((b) => b.html).join("\n"),
])
.join("")
);
Expand Down

0 comments on commit 4a43589

Please sign in to comment.