diff --git a/CHANGELOG.md b/CHANGELOG.md index 95bc5d8..66eedf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ All notable changes to this project will be documented in this file. - Added the possibility of specifying a custom hex colour in the highlight setting and the transformation associated with this colour. Added a "{{CustomHex}}" placeholder in the template gathering all the highlight using that colour - The backlink now directs to the specific annotation rather than the page in the pdf file (thanks to @CaoKang-David) - It is possible to name the notes with the author (thanks to @ThomasFKJorna) +- Added {{firstNameInitials}} to the placeholders available to format the name of authors/editors. This is in addition to {{firstName}} and {{lastName}} + +### Bugs +- Fixed bugs that prevented notes added in Zotero using markdown from being formatted properly + ## [0.9.10] ### Improvement diff --git a/manifest.json b/manifest.json index ba07431..7ced71e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "bibnotes", "name": "BibNotes Formatter", - "version": "0.9.149", + "version": "0.9.151", "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 dd08958..9b55c71 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bibnotes", - "version": "0.9.149", + "version": "0.9.151", "description": "Plugin to export and format annotations from Zotero into Obsidian", "main": "main.js", "scripts": { @@ -26,6 +26,7 @@ "debugout.js": "^1.0.0", "loglevel": "^1.8.0", "node": "^17.2.0", - "tslint": "^6.1.3" + "tslint": "^6.1.3", + "turndown": "^7.1.1" } } diff --git a/src/main.ts b/src/main.ts index 0f074cf..e0520ec 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,6 +10,10 @@ import { Plugin, Notice, normalizePath } from "obsidian"; import path from "path"; +import 'turndown' + + + // wasn't actually used //import { BooleanLiteral, isTokenKind } from "typescript"; @@ -488,7 +492,14 @@ export default class MyPlugin extends Plugin { parseAnnotationLinesintoElementsUserNote(note: string) { - note = note + + + // Replace html formatting with markdown formatting + const turndownService = new TurndownService() + note = turndownService.turndown(note) + + + note = note // Replace backticks .replace(/`/g, "'") // Correct when zotero exports wrong key (e.g. Author, date, p. p. pagenum) @@ -511,8 +522,11 @@ export default class MyPlugin extends Plugin { // Replace backticks with single quote selectedLine = replaceTemplate(selectedLine, "`", "'"); //selectedLine = replaceTemplate(selectedLine, "/", ""); - // Correct encoding issues - selectedLine = replaceTemplate(selectedLine, "&", "&"); + // Correct encoding issues with special character showing incorrectly + selectedLine = replaceTemplate(selectedLine, "&", "&").replace(/</g,'<').replace(/>/g,'>').replace(/&/g,'&'); + + + console.log(selectedLine) const lineElements: AnnotationElements = { highlightText: "", @@ -546,6 +560,7 @@ export default class MyPlugin extends Plugin { return noteElements; } parseAnnotationLinesintoElementsZotero(note: string) { + // clean the entire annotation note = note // .replace( @@ -579,6 +594,8 @@ export default class MyPlugin extends Plugin { // // Correct encoding issues selectedLine = replaceTemplate(selectedLine, "&", "&"); + console.log(selectedLine) + const lineElements: AnnotationElements = { highlightText: "", highlightColour: "", @@ -839,7 +856,6 @@ export default class MyPlugin extends Plugin { const HexRegex = new RegExp(/#([a-fA-F0-9]{6})/g); if(HexRegex.test(lineElements.highlightColour)){ - console.log(lineElements.highlightColour) const colorClassifier = new ColorClassifier(Palette.RAINBOW, AlgorithmTypes.HSV); lineElements.highlightColour = colorClassifier.classify(String(lineElements.highlightColour.match(HexRegex)), "hex"); } @@ -868,7 +884,6 @@ export default class MyPlugin extends Plugin { lineElements.highlightColour = "magenta"; } - console.log(lineElements.highlightColour) } diff --git a/src/settings.ts b/src/settings.ts index 79e2ee5..3a36c37 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -181,7 +181,7 @@ export class SettingTab extends PluginSettingTab { new Setting(settingsExport) .setName("Format Names") - .setDesc('Specify how the names of the authors/editors should be exported.') + .setDesc('Specify how the names of the authors/editors should be exported. Accepted values are {{firstName}}, {{lastName}} and {{firstNameInitials}}') .addTextArea((text) => text .setValue(settings.nameFormat) diff --git a/src/utils.ts b/src/utils.ts index f8546c0..3abe7ba 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -148,6 +148,17 @@ export function formatCreatorsName(creator: Creator, nameCustom: string) { ) { nameCustom = nameCustom.replace("{{lastName}}", creator.lastName); nameCustom = nameCustom.replace("{{firstName}}", creator.firstName); + const getInitials = function (string:string) { + let names = string.split(' '), + initials = names[0].substring(0, 1).toUpperCase()+"."; + + if (names.length > 1) { + initials += names[names.length - 1].substring(0, 1).toUpperCase()+"."; + } + return initials; + }; + + nameCustom = nameCustom.replace("{{firstNameInitials}}", getInitials(creator.firstName)); nameCustom = nameCustom.trim(); return nameCustom; } else if (