diff --git a/zettel.qml b/zettel.qml index 711b757..f1efd78 100644 --- a/zettel.qml +++ b/zettel.qml @@ -3,6 +3,18 @@ import QOwnNotesTypes 1.0 import com.qownnotes.noteapi 1.0 QtObject { + property string idMarker; + + property variant settingsVariables: [ + { + "identifier": "idMarker", + "name": "Zettelkasten ID Marker", + "description": "The in-text marker denoting that a Zettel ID is following. Make sure to use something which is not ambiguous, and does not appear in any other way than to actually denote the Zettel ID. Multiple characters are fine (as in the default '§§')", + "type": "string", + "default": "§§", + } + ] + function init() { script.registerCustomAction("zettelCreate", "Create Zettelkasten Zettel", "Zettel", "address-book-new"); script.registerCustomAction("manualLink", "Insert Zettelkasten Link", "InsertLink", "insert-link"); @@ -81,7 +93,7 @@ QtObject { } let zettel = getNoteByZettelId(uid); - script.log("Autocomplete detected, Switch to §§" + uid + " - " + zettel.name) + script.log("Autocomplete detected, Switch to " + idMarker + uid + " - " + zettel.name) script.setCurrentNote(zettel); @@ -96,7 +108,7 @@ QtObject { function zettelSelectorDialog(editableTextBox, zettelArray) { if (zettelArray == null) { zettelArray = []; - script.fetchNoteIdsByNoteTextPart("§§").forEach(function (noteId){ + script.fetchNoteIdsByNoteTextPart(idMarker).forEach(function (noteId){ let note = script.fetchNoteById(noteId); zettelArray.push(note.name + " --id:"+note.id); }); @@ -108,7 +120,8 @@ QtObject { } function extractZettelIdFromString(text) { - let markerpos = text.search(/§§\d{14}\s/) + 2; + let regex = new RegExp(idMarker + '\\d{14}\\s') + let markerpos = text.search(regex) + 2; if (markerpos == -1) { script.log("No Zettel ID Found in text"); return; @@ -117,7 +130,7 @@ QtObject { } function verifyZettelId(id) { - if (id.match(/^§§\d{14}$/) != null) { + if (id.match(new RegExp(idMarker + '^\\d{14}$')) != null) { return id.substring(2); } else if (id.match(/^\d{14}$/) != null) { return id; @@ -127,9 +140,9 @@ QtObject { } function getNoteByZettelId(uid) { - let noteId = script.fetchNoteIdsByNoteTextPart("§§" + uid); + let noteId = script.fetchNoteIdsByNoteTextPart(idMarker + uid); if (noteId.length == 0) { - script.log("No note found for Zettel ID: §§" + uid); + script.log("No note found for Zettel ID: " + idMarker + uid); return; } return script.fetchNoteById(noteId[0]); @@ -150,7 +163,7 @@ QtObject { text += "===============\n"; // Create uid tag - text += "§§" + uid.toString() + "\n\n"; + text += idMarker + uid.toString() + "\n\n"; // Create content unit (i.e. space) text += "\n\n\n\n\n";