Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mgmeyers committed Mar 27, 2022
1 parent 26b83fa commit f82b478
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions src/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function loadTemplate(
new Notice(`Error: ${name} template not found ${path}`);
return null;
}

return app.vault.cachedRead(headerTemplateFile as TFile);
}

Expand All @@ -108,6 +108,34 @@ async function getTemplates(app: App, params: ExportToMarkdownParams) {
};
}

function processNote(note: any) {
if (note.note) {
note.note = htmlToMarkdown(note.note);
}
if (note.dateAdded) {
note.dateAdded = moment(new Date(note.dateAdded));
}

if (note.dateModified) {
note.dateModified = moment(new Date(note.dateModified));
}
}

function processAttachment(attachment: any) {
if (attachment.dateAdded) {
attachment.dateAdded = moment(new Date(attachment.dateAdded));
}

if (attachment.dateModified) {
attachment.dateModified = moment(new Date(attachment.dateModified));
}

if (attachment.uri) {
attachment.itemKey = attachment.uri.split("/").pop();
attachment.desktopURI = `zotero://select/library/items/${attachment.itemKey}`;
}
}

async function processItem(
item: any,
exportDate: moment.Moment,
Expand All @@ -117,7 +145,7 @@ async function processItem(
item.desktopURI = `zotero://select/library/items/${item.itemKey}`;

if (item.accessDate) {
item.accessDate = moment(item.accessDate);
item.accessDate = moment(new Date(item.accessDate));
}

if (item.dateAdded) {
Expand All @@ -142,33 +170,8 @@ async function processItem(
return false;
}

item.notes?.forEach((note: any) => {
if (note.note) {
note.note = htmlToMarkdown(note.note);
}
if (note.dateAdded) {
note.dateAdded = moment(new Date(note.dateAdded));
}

if (note.dateModified) {
note.dateModified = moment(new Date(note.dateModified));
}
});

item.attachments.forEach((a: any) => {
if (a.dateAdded) {
a.dateAdded = moment(new Date(a.dateAdded));
}

if (a.dateModified) {
a.dateModified = moment(new Date(a.dateModified));
}

if (a.uri) {
a.itemKey = a.uri.split("/").pop();
a.desktopURI = `zotero://select/library/items/${a.itemKey}`;
}
});
item.notes?.forEach(processNote);
item.attachments?.forEach(processAttachment);
}

export async function exportToMarkdown(
Expand Down

0 comments on commit f82b478

Please sign in to comment.