Skip to content

Commit

Permalink
fixed zotfile regex
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanopagliari committed Jul 31, 2022
1 parent 0766045 commit 0e3565b
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 19 deletions.
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.206",
"version": "0.9.208",
"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.206",
"version": "0.9.208",
"description": "Plugin to export and format annotations from Zotero into Obsidian",
"main": "main.js",
"scripts": {
Expand Down
Empty file modified src/constants.ts
100644 → 100755
Empty file.
28 changes: 15 additions & 13 deletions src/main.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@ 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";
//import { App, Plugin, Notice, normalizePath, Vault } from "obsidian";

import path from "path";

import 'turndown'


import 'turndown'


// wasn't actually used
//import { BooleanLiteral, isTokenKind } from "typescript";

import {
DEFAULT_SETTINGS,
Expand All @@ -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,
Expand Down Expand Up @@ -341,6 +337,8 @@ export default class MyPlugin extends Plugin {
//Remote html tags
const selectedLineOriginal = lines[indexLines];



const selectedLine = selectedLineOriginal.replace(
/<\/?[^>]+(>|$)/g,
""
Expand All @@ -352,7 +350,7 @@ export default class MyPlugin extends Plugin {
}

//Crety empty lineElements
const lineElements: AnnotationElements = {
const lineElements: AnnotationElements = {
highlightText: "",
highlightColour: "",
annotationType: "",
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,"");
Expand Down Expand Up @@ -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, "")
Expand Down Expand Up @@ -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("$&", '$ &');
Expand All @@ -1872,7 +1876,6 @@ export default class MyPlugin extends Plugin {
} else {
extractionType = "Other";
}

let noteElementsSingle: AnnotationElements[] = []; // array of elements
if (extractionType === "Zotero") {
noteElementsSingle =
Expand Down Expand Up @@ -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,
Expand All @@ -2511,7 +2514,6 @@ export default class MyPlugin extends Plugin {
const existingNoteAll = String(fs.readFileSync(noteTitleFull));



litnote = this.compareOldNewNote(
existingNoteAll,
litnote,
Expand All @@ -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}!`);
}
Expand Down
6 changes: 2 additions & 4 deletions src/modal.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,19 @@ export class fuzzySelectEntryFromJson extends FuzzySuggestModal<Reference> {

//Check sqlite 3
this.plugin.checkSQLite();


//Load the Json file

//Create the full path

//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[] = [];
Expand Down
Empty file modified src/settings.ts
100644 → 100755
Empty file.
Empty file modified src/suggesters/FolderSuggester.ts
100644 → 100755
Empty file.
Empty file modified src/suggesters/suggest.ts
100644 → 100755
Empty file.
Empty file modified src/types.ts
100644 → 100755
Empty file.
Empty file modified src/utils.ts
100644 → 100755
Empty file.

0 comments on commit 0e3565b

Please sign in to comment.