From 9d4393d94ae34c018c41c569588f988ba8afc3ed Mon Sep 17 00:00:00 2001 From: stefanopagliari <30759878+stefanopagliari@users.noreply.github.com> Date: Thu, 20 Jan 2022 21:17:34 +0000 Subject: [PATCH] Create "Replace with custom Text" setting --- CHANGELOG.md | 9 +++++++++ manifest.json | 2 +- package.json | 2 +- src/constants.ts | 1 + src/main.ts | 5 +---- src/settings.ts | 19 ++++++++++++++++--- src/types.ts | 2 ++ src/utils.ts | 8 ++++---- 8 files changed, 35 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71fe257..f0425fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ All notable changes to this project will be documented in this file. +## [0.9.04] +### Improvement +- Added setting to activate "debugging mode". This will print the console log from the processing of an entry into a txt file that can be easily shared to debug a problem with the plugin +- Expanded the size of the text area to input the custom template (thanks to @MichaBrugger) +- Replaced in the setting "Replace with NA" with "Replace with custom text", and added a field to specify the text to add in the case of a missing value. + +### Bugs +- Fixed filepath of images on Windows + ## [0.9.01] ### Bugs - Fixed filepath of images on Windows diff --git a/manifest.json b/manifest.json index 247113c..35be28c 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "bibnotes", "name": "BibNotes Formatter", - "version": "0.9.03", + "version": "0.9.04", "minAppVersion": "0.12.0", "description": "Plugin to import and format annotations from Zotero.", "author": "Stefano Pagliari", diff --git a/package.json b/package.json index 3e3e5db..642ed9d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bibnotes", - "version": "0.9.03", + "version": "0.9.04", "description": "Plugin to export and format annotations from Zotero into Obsidian", "main": "main.js", "scripts": { diff --git a/src/constants.ts b/src/constants.ts index 471a575..5122f6c 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -167,6 +167,7 @@ export const DEFAULT_SETTINGS: MyPluginSettings = { highlightCitationsLink: true, debugMode: false, zoteroStoragePath: "", + missingfieldreplacement: "NA", }; diff --git a/src/main.ts b/src/main.ts index bb45190..5a89161 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1126,9 +1126,6 @@ export default class MyPlugin extends Plugin { const selectedLine = noteElementsArray[index] - bugout.log(selectedLine) - - rowEditedArray.push(selectedLine.rowEdited) // Copy the rows highlighted in a certain colour into colour-specific arrays @@ -1751,7 +1748,7 @@ export default class MyPlugin extends Plugin { //delete the missing fields in the metadata const missingFieldSetting = this.settings.missingfield - litnote = replaceMissingFields(litnote, missingFieldSetting); + litnote = replaceMissingFields(litnote, missingFieldSetting, this.settings.missingfieldreplacement); // Compare old note and new note if (this.settings.saveManualEdits!=="Overwrite Entire Note" && fs.existsSync(noteTitleFull)){ //Check if the settings in settings.saveManualEdits are TRUE. In that case compare existing file with new notes. If false don't look at existing note diff --git a/src/settings.ts b/src/settings.ts index 5d744d9..b29a030 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -160,21 +160,34 @@ export class SettingTab extends PluginSettingTab { ) .addDropdown((d) => { d.addOption("Leave placeholder", "Leave placeholder"); - d.addOption("Replace with NA", "Replace with NA"); d.addOption("Remove (entire row)", "Remove (entire row)"); + d.addOption("Replace with custom text", "Replace with custom text"); d.setValue(settings.missingfield); d.onChange( async ( v: | "Leave placeholder" - | "Replace with NA" | "Remove (entire row)" + | "Replace with custom text" ) => { settings.missingfield = v; await plugin.saveSettings(); + this.display(); } ); }); + if (settings.missingfield==="Replace with custom text") { + new Setting(settingsExport) + .setName("Replacement for missing fields") + .addText((text) => + text + .setValue(settings.missingfieldreplacement) + .onChange(async (value) => { + settings.missingfieldreplacement = value; + await plugin.saveSettings(); + }) + ); + } new Setting(settingsExport) .setName("Multiple Entries Divider") @@ -915,7 +928,7 @@ export class SettingTab extends PluginSettingTab { .onChange(async (value) => { settings.zoteroStoragePath = value; await plugin.saveSettings(); - })); + })); if(settings.imagesImport){ diff --git a/src/types.ts b/src/types.ts index 97feb69..6474e2a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -135,6 +135,8 @@ export interface MyPluginSettings { highlightCitationsFormat: string; highlightCitationsLink: boolean; debugMode: boolean; + zoteroStoragePath: string; + missingfieldreplacement: string; } export interface Reference { diff --git a/src/utils.ts b/src/utils.ts index 37d2b6b..962a032 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -232,11 +232,11 @@ export function createTagList(tagList: string[], note:string){ //function to replace the missing fields in the template -export function replaceMissingFields(note: string, missingfield: string) { +export function replaceMissingFields(note: string, missingfield: string, missingfieldreplacement: string) { let copy = note.slice(); - if (missingfield === "Replace with NA") { - copy = copy.replace(TEMPLATE_BRACKET_REG, "*NA*").trim(); - copy = copy.replace(TEMPLATE_REG, "*NA*").trim(); + if (missingfield === "Replace with custom text") { + copy = copy.replace(TEMPLATE_BRACKET_REG, missingfieldreplacement).trim(); + copy = copy.replace(TEMPLATE_REG, missingfieldreplacement).trim(); } else if (missingfield === "Remove (entire row)") { //console.log("Trying to remove all rows with missing field"); const lines = copy.split(/\r?\n/);