From 0e3565be77dd01e2e392e209c5c2f099fc7946f6 Mon Sep 17 00:00:00 2001 From: Stefano Pagliari Date: Sun, 31 Jul 2022 22:45:08 +0100 Subject: [PATCH] fixed zotfile regex --- manifest.json | 2 +- package.json | 2 +- src/constants.ts | 0 src/main.ts | 28 +++++++++++++++------------- src/modal.ts | 6 ++---- src/settings.ts | 0 src/suggesters/FolderSuggester.ts | 0 src/suggesters/suggest.ts | 0 src/types.ts | 0 src/utils.ts | 0 10 files changed, 19 insertions(+), 19 deletions(-) mode change 100644 => 100755 src/constants.ts mode change 100644 => 100755 src/main.ts mode change 100644 => 100755 src/modal.ts mode change 100644 => 100755 src/settings.ts mode change 100644 => 100755 src/suggesters/FolderSuggester.ts mode change 100644 => 100755 src/suggesters/suggest.ts mode change 100644 => 100755 src/types.ts mode change 100644 => 100755 src/utils.ts diff --git a/manifest.json b/manifest.json index 0bf8d2f..f9e48f9 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "bibnotes", "name": "BibNotes Formatter", - "version": "0.9.206", + "version": "0.9.208", "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 9cb3fbe..0755e62 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bibnotes", - "version": "0.9.206", + "version": "0.9.208", "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 old mode 100644 new mode 100755 diff --git a/src/main.ts b/src/main.ts old mode 100644 new mode 100755 index 065e93d..9e74cdd --- a/src/main.ts +++ b/src/main.ts @@ -5,7 +5,6 @@ import ColorClassifier, { Palette, AlgorithmTypes } from "color-classifier" //import Database from "better-sqlite3"; //import DB from "better-sqlite3"; - //import { info, setLevel } from "loglevel"; import { Plugin, Notice, normalizePath } from "obsidian"; @@ -13,12 +12,9 @@ import { Plugin, Notice, normalizePath } from "obsidian"; import path from "path"; -import 'turndown' - - +import 'turndown' + -// wasn't actually used -//import { BooleanLiteral, isTokenKind } from "typescript"; import { DEFAULT_SETTINGS, @@ -32,7 +28,7 @@ import { fuzzySelectEntryFromJson, updateLibrary } from "./modal"; //Import sample settings from /settings.ts import { SettingTab } from "./settings"; import { - AnnotationElements, + AnnotationElements, MyPluginSettings, Reference, Collection, @@ -341,6 +337,8 @@ export default class MyPlugin extends Plugin { //Remote html tags const selectedLineOriginal = lines[indexLines]; + + const selectedLine = selectedLineOriginal.replace( /<\/?[^>]+(>|$)/g, "" @@ -352,7 +350,7 @@ export default class MyPlugin extends Plugin { } //Crety empty lineElements - const lineElements: AnnotationElements = { + const lineElements: AnnotationElements = { highlightText: "", highlightColour: "", annotationType: "", @@ -377,8 +375,9 @@ export default class MyPlugin extends Plugin { //Extract the citeKey lineElements.citeKey = String(selectedLine.match(/\(([^)]+)\)+$/g)); + if (lineElements.citeKey == `null`){lineElements.citeKey = String(selectedLine.match(/\(([^D+]+) \d+\S+\)/g))}; - const posCiteKeyBegins = selectedLine.indexOf(lineElements.citeKey); + const posCiteKeyBegins = selectedLine.indexOf(lineElements.citeKey); let extractedText = ""; if (posCiteKeyBegins !== -1) { @@ -492,6 +491,7 @@ export default class MyPlugin extends Plugin { // } //Identify if the text is highlight or comment. if it is a comment extract the type of comment + const annotationCommentAll = ""; if (lineElements.citeKey.includes("(note on p.")) { lineElements.commentText = extractedText; @@ -920,6 +920,7 @@ export default class MyPlugin extends Plugin { } //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,""); @@ -1341,6 +1342,8 @@ export default class MyPlugin extends Plugin { // ADD FORMATTING TO THE ZOTERO INLINE TAGS //if the hash is added to the tag, then remove empty spaces + if (typeof lineElements.inlineTagsArray == 'undefined'){lineElements.inlineTagsArray= []} + if(this.settings.isTagHash==true){ for (let index = 0; index < lineElements.inlineTagsArray.length; index++) { lineElements.inlineTagsArray[index] = lineElements.inlineTagsArray[index].replace(/ /g, "") @@ -1850,6 +1853,7 @@ export default class MyPlugin extends Plugin { ) { let note = selectedEntry.notes[indexNote].note; + // Remove special characters that would break the replacement of the text in the template //lineElements.rowEdited = lineElements.rowEdited.replaceAll("$>", '$$'); note = note.replaceAll("$&", '$ &'); @@ -1872,7 +1876,6 @@ export default class MyPlugin extends Plugin { } else { extractionType = "Other"; } - let noteElementsSingle: AnnotationElements[] = []; // array of elements if (extractionType === "Zotero") { noteElementsSingle = @@ -2484,7 +2487,7 @@ export default class MyPlugin extends Plugin { if (extractedKeywords == undefined) { extractedKeywords = []; } - + // Join the tags in the metadata with the tags extracted in the text and replace them in the text litnote = replaceTagList( selectedEntry, @@ -2511,7 +2514,6 @@ export default class MyPlugin extends Plugin { const existingNoteAll = String(fs.readFileSync(noteTitleFull)); - litnote = this.compareOldNewNote( existingNoteAll, litnote, @@ -2527,7 +2529,7 @@ export default class MyPlugin extends Plugin { bugout.downloadLog(); } fs.writeFile(noteTitleFull, litnote, function (err) { - if (err) console.log(err); + if (err) console.log(err); }); new Notice(`Imported ${selectedEntry.citationKey}!`); } diff --git a/src/modal.ts b/src/modal.ts old mode 100644 new mode 100755 index 70a4164..b1ea881 --- a/src/modal.ts +++ b/src/modal.ts @@ -45,7 +45,6 @@ export class fuzzySelectEntryFromJson extends FuzzySuggestModal { //Check sqlite 3 this.plugin.checkSQLite(); - //Load the Json file @@ -53,13 +52,12 @@ export class fuzzySelectEntryFromJson extends FuzzySuggestModal { //const data = require(this.app.vault.adapter.getBasePath() + "/" + this.plugin.settings.bibPath) const rawdata = fs.readFileSync( - this.app.vault.adapter.getBasePath() + + this.app.vault.adapter.getBasePath() + "/" + this.plugin.settings.bibPath ); const data = JSON.parse(rawdata.toString()); // rawdata is a buffer, convert to string - console.log(data) - console.log(data.items) + //const checkAdmonition = this.app.plugins.getPlugin("obsidian-admonition")._loaded const bibtexArray: Reference[] = []; diff --git a/src/settings.ts b/src/settings.ts old mode 100644 new mode 100755 diff --git a/src/suggesters/FolderSuggester.ts b/src/suggesters/FolderSuggester.ts old mode 100644 new mode 100755 diff --git a/src/suggesters/suggest.ts b/src/suggesters/suggest.ts old mode 100644 new mode 100755 diff --git a/src/types.ts b/src/types.ts old mode 100644 new mode 100755 diff --git a/src/utils.ts b/src/utils.ts old mode 100644 new mode 100755