fix: template preview image bug
This commit is contained in:
parent
45beb47153
commit
d2b73f1bd6
|
|
@ -180,12 +180,16 @@ function updateEditor() {
|
|||
|
||||
async function updatePreview() {
|
||||
const name = getSelectedTemplateName();
|
||||
const html = await addon.api.template.renderTemplatePreview(name);
|
||||
let html = (await addon.api.template.renderTemplatePreview(name))
|
||||
.replace(/ /g, "#160;")
|
||||
.replace(/<br>/g, "<br/>")
|
||||
.replace(/<hr>/g, "<hr/>")
|
||||
.replace(/<img([^>]+)\>/g, "<img$1/>");
|
||||
const win = addon.data.templateEditor.window;
|
||||
const container = win?.document.getElementById("preview-container");
|
||||
if (container) {
|
||||
if (ztoolkit.isZotero7()) {
|
||||
container.innerHTML = html.replace(/ /g, "#160;");
|
||||
container.innerHTML = html;
|
||||
} else {
|
||||
container.innerHTML = "";
|
||||
container.appendChild(
|
||||
|
|
|
|||
|
|
@ -118,7 +118,5 @@ async function renderTemplatePreview(
|
|||
} else {
|
||||
html = `<p>Preview not available for template ${templateName}</p>`;
|
||||
}
|
||||
// complete <br> and <hr> tags
|
||||
html = html.replace(/<br>/g, "<br/>").replace(/<hr>/g, "<hr/>");
|
||||
return html;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ function serializeAnnotations(
|
|||
if (
|
||||
(!annotation.text &&
|
||||
!annotation.comment &&
|
||||
!annotation.imageAttachmentKey) ||
|
||||
!annotation.imageAttachmentKey &&
|
||||
!annotation.image) ||
|
||||
annotation.type === "ink"
|
||||
) {
|
||||
continue;
|
||||
|
|
@ -130,6 +131,11 @@ function serializeAnnotations(
|
|||
)}"/>`;
|
||||
}
|
||||
|
||||
// Image in b64
|
||||
if (annotation.image) {
|
||||
imageHTML = `<img src="${annotation.image}"/>`;
|
||||
}
|
||||
|
||||
// Text
|
||||
if (annotation.text) {
|
||||
let text = Zotero.EditorInstanceUtilities._transformTextToHTML.call(
|
||||
|
|
@ -202,15 +208,15 @@ function serializeAnnotations(
|
|||
}
|
||||
|
||||
export async function importAnnotationImagesToNote(
|
||||
note: Zotero.Item,
|
||||
note: Zotero.Item | undefined,
|
||||
annotations: CustomAnnotationJSON[]
|
||||
) {
|
||||
for (let annotation of annotations) {
|
||||
if (annotation.image) {
|
||||
if (annotation.image && note) {
|
||||
annotation.imageAttachmentKey =
|
||||
(await importImageToNote(note, annotation.image)) || "";
|
||||
delete annotation.image;
|
||||
}
|
||||
delete annotation.image;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -230,8 +236,8 @@ export async function parseAnnotationHTML(
|
|||
}
|
||||
annotationJSONList.push(annotJson!);
|
||||
}
|
||||
options.noteItem &&
|
||||
(await importAnnotationImagesToNote(options.noteItem, annotationJSONList));
|
||||
|
||||
await importAnnotationImagesToNote(options.noteItem, annotationJSONList);
|
||||
const html = serializeAnnotations(
|
||||
annotationJSONList as Required<CustomAnnotationJSON>[],
|
||||
false,
|
||||
|
|
|
|||
Loading…
Reference in New Issue