add: api.convert.note2html

This commit is contained in:
windingwind 2023-08-31 11:05:33 +08:00
parent 20e2c35ef3
commit dc22d4c645
3 changed files with 26 additions and 12 deletions

View File

@ -8,6 +8,7 @@ import {
md2html,
html2md,
annotations2html,
note2html,
} from "./modules/convert/api";
import { exportNotes } from "./modules/export/api";
import { saveDocx } from "./modules/export/docx";
@ -90,6 +91,7 @@ const convert = {
md2html,
html2md,
annotations2html,
note2html,
};
const template = {

View File

@ -45,6 +45,7 @@ export {
md2html,
html2md,
annotations2html,
note2html,
};
async function note2md(
@ -217,6 +218,24 @@ function annotations2html(
return parseAnnotationHTML(annotations, options);
}
async function note2html(
noteItems: Zotero.Item | Zotero.Item[],
options: { targetNoteItem?: Zotero.Item; html?: string },
) {
if (!Array.isArray(noteItems)) {
noteItems = [noteItems];
}
const { targetNoteItem } = options;
let html = options.html;
if (!html) {
html = noteItems.map((item) => item.getNote()).join("\n");
}
if (targetNoteItem?.isNote()) {
return await copyEmbeddedImagesInHTML(html, targetNoteItem, noteItems);
}
return await renderNoteHTML(html, noteItems);
}
function note2rehype(str: string) {
const rehype = unified()
.use(remarkGfm)

View File

@ -1,6 +1,5 @@
import { itemPicker } from "../../utils/itemPicker";
import { getString } from "../../utils/locale";
import { copyEmbeddedImagesInHTML, renderNoteHTML } from "../../utils/note";
import { fill, slice } from "../../utils/str";
export { runTemplate, runTextTemplate, runItemTemplate };
@ -203,17 +202,11 @@ async function runItemTemplate(
),
);
let html = results.join("\n");
if (targetNoteItem && targetNoteItem.isNote()) {
html = await copyEmbeddedImagesInHTML(
html,
targetNoteItem,
copyImageRefNotes,
);
} else {
html = await renderNoteHTML(html, copyImageRefNotes);
}
return html;
const html = results.join("\n");
return await addon.api.convert.note2html(copyImageRefNotes, {
targetNoteItem,
html,
});
}
async function getItemTemplateData() {