diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index ca70f47..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.github/.DS_Store b/.github/.DS_Store deleted file mode 100644 index 44e8bcf..0000000 Binary files a/.github/.DS_Store and /dev/null differ diff --git a/.github/workflows/.DS_Store b/.github/workflows/.DS_Store deleted file mode 100644 index 5008ddf..0000000 Binary files a/.github/workflows/.DS_Store and /dev/null differ diff --git a/src/constants.ts b/src/constants.ts index 99663fb..8f0e199 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -126,6 +126,9 @@ export const DEFAULT_SETTINGS: MyPluginSettings = { commentPrependDefault: false, commentPrependDivider: ": ", commentAppendDivider: "-> ", + TagBeginningConfig: "Tag: ", + TagEndConfig: "", + TagDividerConfig: "; ", keyH1: "#", keyH2: "##", keyH3: "###", @@ -140,17 +143,27 @@ export const DEFAULT_SETTINGS: MyPluginSettings = { isHighlightBullet: true, isHighlightBlockquote: false, isHighlightQuote: true, + highlightCustomTextBefore: "", + highlightCustomTextAfter: "", isCommentItalic: false, isCommentBold: true, isCommentHighlighted: false, isCommentBullet: false, isCommentBlockquote: true, isCommentQuote: false, - isDoubleSpaced: true, - highlightCustomTextBefore: "", - highlightCustomTextAfter: "", commentCustomTextBefore: "", commentCustomTextAfter: "", + isTagItalic: false, + isTagBold: false, + isTagHighlighted: false, + isTagBullet: false, + isTagBlockquote: false, + isTagQuote: false, + tagCustomTextBefore: "#", + tagCustomTextAfter: "", + tagCustomTextBeforeFirst: "", + tagCustomTextAfterLast: "", + isDoubleSpaced: true, colourYellowText: "{{highlight}}", colourPurpleText: "{{highlight}}", colourRedText: "{{highlight}}", diff --git a/src/main.ts b/src/main.ts index 6e89765..364e177 100644 --- a/src/main.ts +++ b/src/main.ts @@ -119,6 +119,14 @@ export default class MyPlugin extends Plugin { isHighlightBullet, isHighlightBlockquote, isHighlightQuote, + tagCustomTextAfter, + tagCustomTextBefore, + isTagItalic, + isTagBold, + isTagHighlighted, + isTagBullet, + isTagBlockquote, + isTagQuote, } = this.settings; //Set the formatting variables based on the highlightsettings @@ -151,7 +159,6 @@ export default class MyPlugin extends Plugin { highlightItalic + highlightBold + highlightHighlighted + - " " + highlightCustomTextAfter; const highlightPrepend = @@ -178,7 +185,46 @@ export default class MyPlugin extends Plugin { commentCustomTextAfter; const commentPrepend = - commentBullet + commentBlockquote + " " + commentCustomTextBefore; + commentBullet + commentBlockquote + commentCustomTextBefore; + + + //Set the tag formatting variables based on the tag settings + const [ + tagItalic, + tagBold, + tagHighlighted, + tagBullet, + tagBlockquote, + tagQuoteOpen, + tagQuoteClose, + ] = [ + isTagItalic ? "*" : "", + isTagBold ? "**" : "", + isTagHighlighted ? "==" : "", + isTagBullet ? "- " : "", + isTagBlockquote ? "> " : "", + isTagQuote ? "“" : "", + isTagQuote ? "”" : "", + ]; + + const tagFormatBefore = + tagHighlighted + + tagBold + + tagItalic + + tagQuoteOpen; + + const tagFormatAfter = + tagQuoteClose + + tagItalic + + tagBold + + tagHighlighted + + tagCustomTextAfter; + + let tagPrepend = "" + if(tagBullet != "" || tagBlockquote != ""){tagPrepend = "\n" + + tagBullet + tagBlockquote + tagCustomTextBefore;} else { + tagPrepend = tagBullet + tagBlockquote + tagCustomTextBefore;} + console.log(tagPrepend) return { highlightFormatBefore, @@ -187,6 +233,9 @@ export default class MyPlugin extends Plugin { commentFormatBefore, commentFormatAfter, commentPrepend, + tagFormatBefore, + tagFormatAfter, + tagPrepend, }; } @@ -492,7 +541,6 @@ export default class MyPlugin extends Plugin { parseAnnotationLinesintoElementsUserNote(note: string) { - console.log(note) // Replace html formatting with markdown formatting const turndownService = new TurndownService() @@ -505,10 +553,8 @@ export default class MyPlugin extends Plugin { // Correct when zotero exports wrong key (e.g. Author, date, p. p. pagenum) .replace(/, p. p. /g, ", p. ") .trim(); - console.log(note) // Split the annotations into an array where each row is an entry const lines = note.split(/<\/h1>|\n\n|<\/p>/gm); - console.log(lines) const noteElements: AnnotationElements[] = []; //Loop through the lines @@ -516,7 +562,6 @@ export default class MyPlugin extends Plugin { for (let indexLines = 0; indexLines < lengthLines; indexLines++) { const selectedLineOriginal = unescape(lines[indexLines]); - console.log(selectedLineOriginal) // Replace backticks with single quote let selectedLine = replaceTemplate(selectedLineOriginal, "`", "'"); @@ -595,6 +640,8 @@ export default class MyPlugin extends Plugin { annotationType: "", citeKey: "", commentText: "", + inlineTagsText: "", + inlineTagsArray: [], rowOriginal: selectedLine, rowEdited: selectedLine, indexNote: undefined, @@ -809,13 +856,67 @@ export default class MyPlugin extends Plugin { annotationCommentAll.length ) .trim(); + + //Extract the tags + + //check if the inline tags are found in the text of the comment + if (lineElements.commentText.includes(this.settings.TagBeginningConfig)){ + + //if the tags are at the end of the comment, tehn extract the text between the beginning of the tag and the end of the comment + if(this.settings.TagEndConfig.length==0){ + lineElements.inlineTagsText = lineElements.commentText.slice( + lineElements.commentText.indexOf(this.settings.TagBeginningConfig), + lineElements.commentText.length, + ); + } else { + //if the tags are in the middle/beginning of the comment, tehn extract the text between the beginning of the tag and the specified end of the tag + lineElements.inlineTagsText = lineElements.commentText.slice( + lineElements.commentText.indexOf(this.settings.TagBeginningConfig), + lineElements.commentText.lastIndexOf(this.settings.TagEndConfig), + ); + } + + //Remove the tags from the comment + lineElements.commentText = lineElements.commentText.replace(lineElements.inlineTagsText,"").trim() + } + + //Check if there are any tags before performing manipulations of inlineTagsText + if(typeof lineElements.inlineTagsText !== `undefined`){ + //Remove the tag beginning and end marker from the inlineTagsText + lineElements.inlineTagsText = lineElements.inlineTagsText.replace(this.settings.TagBeginningConfig,""); + + if(this.settings.TagEndConfig.length!=0){ + lineElements.inlineTagsText = lineElements.inlineTagsText.replace(this.settings.TagEndConfig,""); + } + + //Split the different tags in an array if there are tags + lineElements.inlineTagsArray = lineElements.inlineTagsText.split(this.settings.TagDividerConfig) + + // Identify what type of annotation is based on the tags word. Loop through each of the tags + if (lineElements.annotationType !== "typeImage") { + for (let indexTag = 0; indexTag < lineElements.inlineTagsArray.length; indexTag++) { + const tempAnnotationType = this.getAnnotationType( + lineElements.inlineTagsArray[indexTag], + annotationCommentAll); + //Currently bibnotes can only incorporate one transformation. So as soon as one of the tags matches one transformation this is applied to the code (superseding the first character) and the loop is interrupted. The tag is removed from the list that is printed after the comment + if (tempAnnotationType != "noKey") { + lineElements.annotationType = tempAnnotationType; + + //Remove this from the array + lineElements.inlineTagsArray.splice(indexTag,1) + + break + } + } + } + } + } else { lineElements.rowEdited = selectedLine; } - //Add the element to the array containing all the elements noteElements.push(lineElements); - } + } return noteElements; } @@ -992,10 +1093,15 @@ export default class MyPlugin extends Plugin { highlightFormatAfter, highlightFormatBefore, highlightPrepend, + tagFormatBefore, + tagFormatAfter, + tagPrepend, } = this.createFormatting(); //Create an index of rows to be removed const indexRowsToBeRemoved: number[] = []; + + //Create elements with subset of highlights/notes to be exported const noteElementsArray: AnnotationElements[] = []; const keywordArray: string[] = []; const rowEditedArray: string[] = []; @@ -1022,6 +1128,7 @@ export default class MyPlugin extends Plugin { //Select one element to process let lineElements = noteElements[i]; + console.log(lineElements) //Run the function to extract the transformation associated with the highlighted colour lineElements = this.formatColourHighlight(lineElements); @@ -1118,6 +1225,63 @@ export default class MyPlugin extends Plugin { lineElements.rowEdited = "**" + lineElements.rowOriginal.toUpperCase() + "**"; } + + // ADD FORMATTING TO THE HIGHLIGHTS + if(lineElements.highlightText != ""){ lineElements.highlightFormatted = + highlightPrepend + + colourTextBefore + + highlightFormatBefore + + lineElements.highlightText + + highlightFormatAfter + + colourTextAfter + + " "} else {lineElements.highlightFormatted = ""} + + + // ADD FORMATTING TO THE COMMENTS + if(lineElements.commentText != ""){lineElements.commentFormatted = + commentPrepend + + commentFormatBefore + + lineElements.commentText + + commentFormatAfter + " "} else {lineElements.commentFormatted = ""} + + // ADD FORMATTING TO THE ZOTERO INLINE TAGS + const TempTag = lineElements.inlineTagsArray + .map(i => tagPrepend + tagFormatBefore + i + tagFormatAfter); + console.log(TempTag) + + // Check if there are any inline tags + function allAreEmpty(arr:string[]) { + return arr.every(element => element == ""); + } + console.log(allAreEmpty(lineElements.inlineTagsArray)); // 👉️ true + + // If there are inline tags, format them. otherwise create empty element + if (allAreEmpty(lineElements.inlineTagsArray)==false){ + lineElements.inlineTagsFormatted = TempTag.join(' '); + lineElements.inlineTagsFormatted = this.settings.tagCustomTextBeforeFirst + lineElements.inlineTagsFormatted + this.settings.tagCustomTextAfterLast + } else {lineElements.inlineTagsFormatted = ""} + console.log(lineElements.inlineTagsFormatted) + + + + //FORMAT HIGHLIGHTED SENTENCES WITHOUT ANY COMMENT + //OR WITHOUT ANY SPECIAL CONSIDERATIONS + if (lineElements.annotationType === "noKey") { + // if there is an highlighted text, then the reference goes after the highlight + if (lineElements.highlightText !== "") { + lineElements.rowEdited = + lineElements.highlightFormatted + + lineElements.citeKey + " " + + lineElements.commentFormatted + + lineElements.inlineTagsFormatted} + // if it is a standalone comment without highlight, the link to the pdf goes after the comment + else {lineElements.rowEdited = + lineElements.highlightFormatted + + lineElements.commentFormatted + + lineElements.zoteroBackLink + " " + + lineElements.inlineTagsFormatted}} + + //FORMAT IMAGES if (lineElements.annotationType === "typeImage") { @@ -1138,7 +1302,7 @@ export default class MyPlugin extends Plugin { dir: this.settings.zoteroStoragePathManual + lineElements.imagePath, base: "image.png", - })}; + })} pathImageNew = path.normalize( path.format({ @@ -1198,16 +1362,12 @@ export default class MyPlugin extends Plugin { lineElements.rowEdited + "\n" + "\n" + - commentPrepend + - commentFormatBefore + - lineElements.commentText + - commentFormatAfter; + lineElements.commentFormatted + + lineElements.inlineTagsFormatted; } else { lineElements.rowEdited = - commentPrepend + - commentFormatBefore + - lineElements.commentText + - commentFormatAfter + + lineElements.commentFormatted + + lineElements.inlineTagsFormatted + "\n" + "\n" + lineElements.rowEdited; @@ -1217,13 +1377,13 @@ export default class MyPlugin extends Plugin { // MERGE HIGHLIGHT WITH THE PREVIOUS ONE ABOVE if (lineElements.annotationType === "typeMergeAbove") { noteElements[i].rowEdited = (noteElements[i - 1].rowEdited.replace(/\[.*\)/, '') + - this.settings.highlightCustomTextBefore + - colourTextBefore + - highlightFormatBefore + - lineElements.highlightText + - highlightFormatAfter + - lineElements.zoteroBackLink + - colourTextAfter).replace(/((?<=\p{Unified_Ideograph})\s*(?=\p{Unified_Ideograph}))/ug, ''); + lineElements.highlightFormatted + + lineElements.zoteroBackLink).replace(/((?<=\p{Unified_Ideograph})\s*(?=\p{Unified_Ideograph}))/ug, '') + + " " + + this.settings.commentAppendDivider + + lineElements.commentFormatted + + lineElements.inlineTagsFormatted + //Add the highlighted text to the previous one @@ -1241,7 +1401,6 @@ export default class MyPlugin extends Plugin { } //commentPrependDefault if (lineElements.annotationType === "typeCommentPrepend") { - console.log(this.settings.commentPrependDivider ) //add the comment before the highlight lineElements.rowEdited = highlightPrepend + @@ -1254,9 +1413,9 @@ export default class MyPlugin extends Plugin { lineElements.highlightText + highlightFormatAfter + lineElements.citeKey + - colourTextAfter; + colourTextAfter + + lineElements.inlineTagsFormatted; } - console.log(lineElements.annotationType) // FORMAT THE HEADERS // Transform header in H1/H2/H3/H4/H5/H6 Level @@ -1271,7 +1430,8 @@ export default class MyPlugin extends Plugin { `\n${hashes} ` + lineElements.highlightText + lineElements.commentText + - lineElements.zoteroBackLink; + lineElements.zoteroBackLink + + lineElements.inlineTagsFormatted; } //Create Task @@ -1291,10 +1451,11 @@ export default class MyPlugin extends Plugin { lineElements.highlightText + highlightFormatAfter + lineElements.zoteroBackLink + - colourTextAfter; + colourTextAfter + + lineElements.inlineTagsFormatted; } else if ( lineElements.commentText == "" && - lineElements.highlightColour !== "" + lineElements.highlightText !== "" ) { lineElements.rowEdited = `- [ ] ` + @@ -1303,17 +1464,19 @@ export default class MyPlugin extends Plugin { lineElements.highlightText + highlightFormatAfter + lineElements.zoteroBackLink + - colourTextAfter; + colourTextAfter + + lineElements.inlineTagsFormatted;; } else if ( lineElements.commentText !== "" && - lineElements.highlightColour === "" + lineElements.highlightText === "" ) { lineElements.rowEdited = `- [ ] ` + commentFormatBefore + lineElements.commentText + commentFormatAfter + - lineElements.zoteroBackLink; + lineElements.zoteroBackLink + + lineElements.inlineTagsFormatted;; } } @@ -1329,47 +1492,13 @@ export default class MyPlugin extends Plugin { indexRowsToBeRemoved.push(i); } - //FORMAT HIGHLIGHTED SENTENCES WITHOUT ANY COMMENT - //OR WITHOUT ANY SPECIAL CONSIDERATIONS - if (lineElements.annotationType === "noKey") { - if (lineElements.highlightText !== "") { - lineElements.rowEdited = - highlightPrepend + - colourTextBefore + - highlightFormatBefore + - lineElements.highlightText + - highlightFormatAfter + - lineElements.citeKey + - colourTextAfter; - if (lineElements.commentText !== "") { - lineElements.rowEdited = - lineElements.rowEdited + - this.settings.commentAppendDivider + - commentPrepend + - commentFormatBefore + - lineElements.commentText + - commentFormatAfter; - } - // //FORMAT THE COMMENTS ADDED OUTSIDE OF ANY ANNOTATION - } else if ( - lineElements.highlightText === "" && - lineElements.commentText !== "" - ) { - - - lineElements.rowEdited = - commentPrepend + - commentFormatBefore + - lineElements.commentText + - commentFormatAfter + - lineElements.zoteroBackLink; - } - } + //Copy the edited text into an array to be exported noteElementsArray.push(lineElements); + } // PERFORM THE FOLLOWING OPERATIONS ON THE WHOLE ARRAY @@ -1524,6 +1653,7 @@ export default class MyPlugin extends Plugin { } extractAnnotation(selectedEntry: Reference, noteTitleFull: string) { + let extractedAnnotations = ""; let extractedAnnotationsYellow = ""; let extractedAnnotationsRed = ""; @@ -2140,6 +2270,7 @@ export default class MyPlugin extends Plugin { //set the authorkey field on the entry to use when creating the title selectedEntry.authorKey = authorKey; + //create bugout to store and export logs in a file let bugout = new Debugout({ realTimeLoggingOn: false }); if (this.settings.debugMode === true) { diff --git a/src/modal.ts b/src/modal.ts index 8195558..e46500b 100644 --- a/src/modal.ts +++ b/src/modal.ts @@ -151,6 +151,7 @@ export class fuzzySelectEntryFromJson extends FuzzySuggestModal { ) { //Create an array where you store the citekey to be processed let citeKeyToBeProcessed: string[] = []; + //If the entire library has been selected, then add all the if (referenceSelected.citationKey === "Entire Library") { diff --git a/src/settings.ts b/src/settings.ts index 2bd96b7..184bf00 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -559,7 +559,164 @@ export class SettingTab extends PluginSettingTab { }) ); - containerEl.createEl('h3', {text: 'Additional Transformations'}); + containerEl.createEl('h3', {text: 'Zotero Tags'}); + const settingsTags: HTMLDetailsElement = + containerEl.createEl("details"); + + settingsTags.setAttribute("open", ""); + settingsTags.createEl("summary", {text: "" }); + + new Setting(settingsTags) + .setDesc( " In order to extract tags added from the Zotero PDF reader, open Zotero -> Preferences -> Advanced -> Config Editor -> extensions.zotero.annotations.noteTemplates.highlight
Replace default value with:

{{highlight quotes='true'}} {{citation}} {{comment}} {{if tags}} Tag: {{tags join='; '}}{{endif}}

") + + /* + new Setting(settingsTags) + + .setName("Text before the {{tags}} in the Zotero advanced config ") + .setDesc("Zotero -> Preferences -> Advanced -> Config Editor -> extensions.zotero.annotations.noteTemplates.highlight \n Default value:

{{highlight quotes='true'}} {{citation}} {{comment}} {{if tags}} Tag: {{tags join='; '}}{{endif}}

") + .addText((text) => + text + .setValue(settings.TagBeginningConfig) + .onChange(async (value) => { + settings.TagBeginningConfig = value; + await plugin.saveSettings(); + }) + ); + new Setting(settingsTags) + .setName("Text after the {{tags}} in the Zotero advanced config ") + .setDesc("Zotero -> Preferences -> Advanced -> Config Editor -> extensions.zotero.annotations.noteTemplates.highlight
Default value:

{{highlight quotes='true'}} {{citation}} {{comment}} {{if tags}} Tag: {{tags join='; '}}{{endif}}

") + .addText((text) => + text + .setValue(settings.TagEndConfig) + .onChange(async (value) => { + settings.TagEndConfig = value; + await plugin.saveSettings(); + }) + ); + new Setting(settingsTags) + .setName("Text between {{tags}} in the Zotero advanced config ") + .setDesc("Zotero -> Preferences -> Advanced -> Config Editor -> extensions.zotero.annotations.noteTemplates.highlight
Default value:

{{highlight quotes='true'}} {{citation}} {{comment}} {{if tags}} Tag: {{tags join='; '}}{{endif}}

") + .addText((text) => + text + .setValue(settings.TagDividerConfig) + .onChange(async (value) => { + settings.TagDividerConfig = value; + await plugin.saveSettings(); + }) + ); + */ + new Setting(settingsTags) + .setName("Quotation Marks") + .addToggle((text) => + text + .setValue(settings.isTagQuote) + .onChange(async (value) => { + settings.isTagQuote = value; + await plugin.saveSettings(); + this.display(); + }) + ); + + new Setting(settingsTags).setName("Bold").addToggle((text) => + text + .setValue(settings.isTagBold) + .onChange(async (value) => { + settings.isTagBold = value; + await plugin.saveSettings(); + this.display(); + }) + ); + new Setting(settingsTags).setName("Italic").addToggle((text) => + text + .setValue(settings.isTagItalic) + .onChange(async (value) => { + settings.isTagItalic = value; + await plugin.saveSettings(); + this.display(); + }) + ); + + new Setting(settingsTags) + .setName("Highlighted") + .addToggle((text) => + text + .setValue(settings.isTagHighlighted) + .onChange(async (value) => { + settings.isTagHighlighted = value; + await plugin.saveSettings(); + this.display(); + }) + ); + new Setting(settingsTags) + .setName("Bullet Points") + .addToggle((text) => + text + .setValue(settings.isTagBullet) + .onChange(async (value) => { + settings.isTagBullet = value; + await plugin.saveSettings(); + this.display(); + }) + ); + + new Setting(settingsTags) + .setName("Blockquote") + .addToggle((text) => + text + .setValue(settings.isTagBlockquote) + .onChange(async (value) => { + settings.isTagBlockquote = value; + await plugin.saveSettings(); + this.display(); + }) + ); + + new Setting(settingsTags) + .setName("Custom text before each individual tag") + .addTextArea((text) => + text + .setValue(settings.tagCustomTextBefore) + .onChange(async (value) => { + settings.tagCustomTextBefore = value; + await plugin.saveSettings(); + }) + ); + + new Setting(settingsTags) + .setName("Custom text after each individual tag") + .addTextArea((text) => + text + .setValue(settings.tagCustomTextAfter) + .onChange(async (value) => { + settings.tagCustomTextAfter = value; + await plugin.saveSettings(); + }) + ); + + new Setting(settingsTags) + .setName("Custom text before first tag") + .addTextArea((text) => + text + .setValue(settings.tagCustomTextBeforeFirst) + .onChange(async (value) => { + settings.tagCustomTextBeforeFirst = value; + await plugin.saveSettings(); + }) + ); + new Setting(settingsTags) + .setName("Custom text after last tag") + .addTextArea((text) => + text + .setValue(settings.tagCustomTextAfterLast) + .onChange(async (value) => { + settings.tagCustomTextAfterLast = value; + await plugin.saveSettings(); + }) + ); + + + + containerEl.createEl('h3', {text: 'Additional Transformations'}); const settingsAdvanced: HTMLDetailsElement = containerEl.createEl("details"); settingsAdvanced.setAttribute("open", ""); diff --git a/src/types.ts b/src/types.ts index 2eef080..803c2de 100644 --- a/src/types.ts +++ b/src/types.ts @@ -20,6 +20,9 @@ export interface MyPluginSettings { commentPrependDefault: boolean; commentPrependDivider: string; commentAppendDivider: string; + TagBeginningConfig: string; + TagEndConfig: string; + TagDividerConfig: string; keyH1: string; keyH2: string; keyH3: string; @@ -46,6 +49,16 @@ export interface MyPluginSettings { isCommentQuote: boolean; commentCustomTextBefore: string; commentCustomTextAfter: string; + isTagItalic: boolean; + isTagBold: boolean; + isTagHighlighted: boolean; + isTagBullet: boolean; + isTagBlockquote: boolean; + isTagQuote: boolean; + tagCustomTextBefore: string; + tagCustomTextAfter: string; + tagCustomTextBeforeFirst: string; + tagCustomTextAfterLast: string; isDoubleSpaced: boolean; colourYellowText: string; colourPurpleText: string; @@ -123,8 +136,13 @@ export interface AnnotationElements { annotationType: string; citeKey: string; commentText: string; + commentFormatted: string; highlightText: string; highlightColour: string; + highlightFormatted: string; + inlineTagsText: string; + inlineTagsArray: string[]; + inlineTagsFormatted: string; indexNote: number; rowOriginal: string; rowEdited: string;