Skip to content

Commit

Permalink
Create "Replace with custom Text" setting
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanopagliari committed Jan 20, 2022
1 parent e5c80dc commit 9d4393d
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 13 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
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": "bibnotes",
"version": "0.9.03",
"version": "0.9.04",
"description": "Plugin to export and format annotations from Zotero into Obsidian",
"main": "main.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export const DEFAULT_SETTINGS: MyPluginSettings = {
highlightCitationsLink: true,
debugMode: false,
zoteroStoragePath: "",
missingfieldreplacement: "NA",

};

Expand Down
5 changes: 1 addition & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 16 additions & 3 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -915,7 +928,7 @@ export class SettingTab extends PluginSettingTab {
.onChange(async (value) => {
settings.zoteroStoragePath = value;
await plugin.saveSettings();
}));
}));


if(settings.imagesImport){
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ export interface MyPluginSettings {
highlightCitationsFormat: string;
highlightCitationsLink: boolean;
debugMode: boolean;
zoteroStoragePath: string;
missingfieldreplacement: string;
}

export interface Reference {
Expand Down
8 changes: 4 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
Expand Down

0 comments on commit 9d4393d

Please sign in to comment.