Skip to content

Commit

Permalink
Feature release version
Browse files Browse the repository at this point in the history
  • Loading branch information
anoopkcn committed Dec 27, 2022
1 parent aaaa829 commit 8ba0114
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 47 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-zotero-annotations",
"name": "Zotero Annotations",
"version": "0.2.8",
"version": "0.3.0",
"description": "Plugin to import metadata and annotations from Zotero",
"author": "Anoop K. Chandran",
"authorUrl": "anoopkcn.com",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-zotero-annotations",
"version": "0.2.8",
"version": "0.3.0",
"description": "Plugin to import and format annotations from Zotero",
"main": "main.js",
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion src/creators.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Creator, CreatorArray } from "./types";
import { getInitials, makeQuotes, makeWiki, replaceTemplate } from "./utils";


export const getCreatorKey = (creators: CreatorArray) => {
const authorKey: string[] = [];
const editorKey: string[] = [];
Expand Down
3 changes: 1 addition & 2 deletions src/notes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//Solution copied from obsidian-bibnotes: https://github.com/stefanopagliari/bibnotes/blob/master/src/main.ts

//Solution copied and modified from obsidian-bibnotes: https://github.com/stefanopagliari/bibnotes/blob/master/src/main.ts

import { Notice, TFile, WorkspaceLeaf } from "obsidian";
import * as fs from "fs";
Expand Down
20 changes: 0 additions & 20 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ export function extractAnnotation(
}

if (selectedEntry.notes.length > 0) {

// cincatinate notes and annotations from multiple files for the same reference
if (settings.importAllAnnotationFiles) {
for (indexNote = 0; indexNote < selectedEntry.notes.length; indexNote++) {
Expand All @@ -187,7 +186,6 @@ export function extractAnnotation(
);

keywordArray = resultsLineElements.keywordArray;

//Create the annotation by merging the individial elements of rowEditedArray. Do the same for the colour
extractedAnnotations =
resultsLineElements.rowEditedArray.join("\n");
Expand Down Expand Up @@ -260,15 +258,12 @@ export function parseMetadata(

//Fix itemType
selectedEntry.itemType = camelToNormalCase(selectedEntry.itemType);

// Create in-line citation (e.g. Collier, Laporte and Seawright (2009))
selectedEntry.citationInLine = `${getCreatorKey(selectedEntry.creators)} (${selectedEntry.year})`;
selectedEntry.citationInLine = selectedEntry.citationInLine.replace("()", "");

// Create in-line citation with initials (e.g. Collier, D., Laporte, J. and Seawright, J. (2009))
selectedEntry.citationInLineInitials = `${getCreatorFullInitials(selectedEntry.creators)} (${selectedEntry.year})`;
selectedEntry.citationInLineInitials = selectedEntry.citationInLineInitials.replace("()", "");

// Create in-line citation with initials (e.g. Collier, D., Laporte, J. and Seawright, J. (2009))
selectedEntry.citationInLineFullName = `${getCreatorFullNames(selectedEntry.creators)} (${selectedEntry.year})`;
selectedEntry.citationInLineFullName = selectedEntry.citationInLineFullName.replace("()", "");
Expand All @@ -277,7 +272,6 @@ export function parseMetadata(
if (selectedEntry.itemType == "Journal Article") {
selectedEntry.citationShort = `${selectedEntry.citationInLine} '${selectedEntry.title}'`;
selectedEntry.citationFull = `${selectedEntry.citationShort}, *${selectedEntry.publicationTitle}*, ${selectedEntry.volume}(${selectedEntry.issue}), pp. ${selectedEntry.pages}.`;

selectedEntry.citationFull = selectedEntry.citationFull.replace("() ", "");
selectedEntry.citationShort = selectedEntry.citationShort.replace("** ", "");
selectedEntry.citationFull = selectedEntry.citationFull.replace("** ", "");
Expand All @@ -289,15 +283,12 @@ export function parseMetadata(
selectedEntry.file = getLocalFileLink(selectedEntry);
// Create an array with all the fields
const entriesArray = Object.keys(selectedEntry);

//replace the single-value placeholders with the value of the field
note = replaceAllTemplates(entriesArray, note, selectedEntry);

//remove single backticks but retain triple backticks
note = note.replace(/```/g, "HEREISAPLACEHOLDERFORBACKTICK");
note = note.replace(/`/g, "'");
note = note.replace(/HEREISAPLACEHOLDERFORBACKTICK/g, "```");

// //if the abstract is missing, delete Abstract headings
// Return the metadata
return note;
Expand All @@ -314,12 +305,9 @@ export function parseAnnotationLinesintoElementsZotfile(
for (let indexLines = 0; indexLines < lines.length; indexLines++) {
//Remote html tags
const selectedLineOriginal = lines[indexLines];

const selectedLine = selectedLineOriginal.replace(/<\/?[^>]+(>|$)/g, "");

//Skip if empty
if (selectedLine === "") continue;

//Crety empty lineElements
//@ts-ignore
const lineElements: AnnotationElements = {
Expand Down Expand Up @@ -354,7 +342,6 @@ export function parseAnnotationLinesintoElementsZotfile(
}

const posCiteKeyBegins = selectedLine.indexOf(lineElements.citeKey);

let extractedText = "";
if (posCiteKeyBegins !== -1) {
extractedText = selectedLine
Expand Down Expand Up @@ -464,10 +451,8 @@ export function parseAnnotationLinesintoElementsUserNote(note: string) {
const lengthLines = Object.keys(lines).length;
for (let indexLines = 0; indexLines < lengthLines; indexLines++) {
const selectedLineOriginal = unescape(lines[indexLines]);

// Replace backticks with single quote
let selectedLine = replaceTemplate(selectedLineOriginal, "`", "'");

// Correct encoding issues with special character showing incorrectly
selectedLine = replaceTemplate(selectedLine, "&amp;", "&")
.replace(/&lt;/g, "<")
Expand Down Expand Up @@ -508,9 +493,7 @@ export function parseAnnotationLinesintoElementsUserNote(note: string) {
};

lineElements.rowEdited = selectedLine;

//Add the element to the array containing all the elements

noteElements.push(lineElements);
}

Expand Down Expand Up @@ -568,15 +551,13 @@ export function parseAnnotationLinesintoElementsZotero(

//Record the extraction method
lineElements.extractionSource = "zotero";

//Identify images
if (/data-attachment-key=/gm.test(selectedLineOriginal)) {
lineElements.annotationType = "typeImage";
lineElements.imagePath = String(selectedLineOriginal.match(/key="([^"]*)"/g)[0])
.replaceAll('"', "")
.replace("key=", "");
}

//Extract the colour of the highlight
if (/"color":"#......"/gm.test(selectedLineOriginal)) {
let highlightColour = String(selectedLineOriginal.match(/"color":"#......"/gm));
Expand All @@ -585,7 +566,6 @@ export function parseAnnotationLinesintoElementsZotero(
highlightColour = highlightColour.replace('"', "");
lineElements.highlightColour = highlightColour;
}

// Extract the location of the annotation in the PDF
// "locator":"12345"
if (/"locator":"\d+"/gm.test(selectedLineOriginal)) {
Expand Down
5 changes: 0 additions & 5 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ export class SettingsTab extends PluginSettingTab {
const { settings } = plugin;

containerEl.empty();

// containerEl.createEl("h1", { text: "Zotero Annotations " });

containerEl.createEl("h2", { text: "General Settings" });
new Setting(containerEl)
.setName(t("JSON_FILE_PATH"))
Expand Down Expand Up @@ -58,7 +55,6 @@ export class SettingsTab extends PluginSettingTab {
})
);

// containerEl.createEl("h2", { text: "Template" });
new Setting(containerEl)
.setName(t("TEMPLATE_FILE"))
.setDesc(fragWithHTML(t("TEMPLATE_FILE_DESC")))
Expand Down Expand Up @@ -134,7 +130,6 @@ export class SettingsTab extends PluginSettingTab {
})
);

// containerEl.createEl("h2", { text: "In-text citations" });
new Setting(containerEl)
.setName(t("CREATE_BACKLINKS"))
.setDesc(fragWithHTML(t("CREATE_BACKLINKS_DESC")))
Expand Down
26 changes: 9 additions & 17 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,25 +159,21 @@ export function replaceMissingFields(

export function getLocalFileLink(reference: Reference) {
//if there is no attachment, return placeholder
if (reference.attachments.length == 0) return "{{localFile}}";
const len_attachments = reference.attachments.length;
if (len_attachments == 0) return "{{localFile}}";
const filesList: string[] = [];

for (
let attachmentindex = 0;
attachmentindex < reference.attachments.length;
attachmentindex++
) {
if (reference.attachments[attachmentindex].itemType !== "attachment")
continue;

let index = 0; index < len_attachments; index++) {
if (reference.attachments[index].itemType !== "attachment") continue;
//remove white spaces from file name
if (reference.attachments[attachmentindex].path == undefined) {
reference.attachments[attachmentindex].path = "";
if (reference.attachments[index].path == undefined) {
reference.attachments[index].path = "";
}

const selectedfile: string =
"[" + reference.attachments[attachmentindex].title + "](file:///" +
encodeURI(reference.attachments[attachmentindex].path.replaceAll(" ", " ")) + ")";
"[" + reference.attachments[index].title + "](file:///" +
encodeURI(reference.attachments[index].path.replaceAll(" ", " ")) + ")";

filesList.push(selectedfile);
}
Expand Down Expand Up @@ -208,10 +204,7 @@ export function getNoteTitle(
return exportTitle;
}

export function createNotePath(
noteTitle: string,
exportPath: string
) {
export function createNotePath(noteTitle: string, exportPath: string) {
return resolvePath(`${exportPath}/${noteTitle}.md`)
}

Expand Down Expand Up @@ -296,7 +289,6 @@ export function getZoteroAppInfo(
//first look into the same path as the pdf attachment
let pathZoteroStorage = "";
let zoteroBuildWindows: boolean = undefined;

//check if the base path where the attachment is stored is in Zotero/storage
const zoteroStorageMac = new RegExp(/.+?(?=Zotero\/storage)Zotero\/storage\//gm);

Expand Down

0 comments on commit 8ba0114

Please sign in to comment.