Add Zettel id marker configuration

This commit is contained in:
Unknown 2018-11-21 18:47:21 +01:00
parent ff81291884
commit 1bb44eeae0

View file

@ -3,6 +3,18 @@ import QOwnNotesTypes 1.0
import com.qownnotes.noteapi 1.0 import com.qownnotes.noteapi 1.0
QtObject { 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() { function init() {
script.registerCustomAction("zettelCreate", "Create Zettelkasten Zettel", "Zettel", "address-book-new"); script.registerCustomAction("zettelCreate", "Create Zettelkasten Zettel", "Zettel", "address-book-new");
script.registerCustomAction("manualLink", "Insert Zettelkasten Link", "InsertLink", "insert-link"); script.registerCustomAction("manualLink", "Insert Zettelkasten Link", "InsertLink", "insert-link");
@ -81,7 +93,7 @@ QtObject {
} }
let zettel = getNoteByZettelId(uid); 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); script.setCurrentNote(zettel);
@ -96,7 +108,7 @@ QtObject {
function zettelSelectorDialog(editableTextBox, zettelArray) { function zettelSelectorDialog(editableTextBox, zettelArray) {
if (zettelArray == null) { if (zettelArray == null) {
zettelArray = []; zettelArray = [];
script.fetchNoteIdsByNoteTextPart("§§").forEach(function (noteId){ script.fetchNoteIdsByNoteTextPart(idMarker).forEach(function (noteId){
let note = script.fetchNoteById(noteId); let note = script.fetchNoteById(noteId);
zettelArray.push(note.name + " --id:"+note.id); zettelArray.push(note.name + " --id:"+note.id);
}); });
@ -108,7 +120,8 @@ QtObject {
} }
function extractZettelIdFromString(text) { 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) { if (markerpos == -1) {
script.log("No Zettel ID Found in text"); script.log("No Zettel ID Found in text");
return; return;
@ -117,7 +130,7 @@ QtObject {
} }
function verifyZettelId(id) { function verifyZettelId(id) {
if (id.match(/^§§\d{14}$/) != null) { if (id.match(new RegExp(idMarker + '^\\d{14}$')) != null) {
return id.substring(2); return id.substring(2);
} else if (id.match(/^\d{14}$/) != null) { } else if (id.match(/^\d{14}$/) != null) {
return id; return id;
@ -127,9 +140,9 @@ QtObject {
} }
function getNoteByZettelId(uid) { function getNoteByZettelId(uid) {
let noteId = script.fetchNoteIdsByNoteTextPart("§§" + uid); let noteId = script.fetchNoteIdsByNoteTextPart(idMarker + uid);
if (noteId.length == 0) { 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;
} }
return script.fetchNoteById(noteId[0]); return script.fetchNoteById(noteId[0]);
@ -150,7 +163,7 @@ QtObject {
text += "===============\n"; text += "===============\n";
// Create uid tag // Create uid tag
text += "§§" + uid.toString() + "\n\n"; text += idMarker + uid.toString() + "\n\n";
// Create content unit (i.e. space) // Create content unit (i.e. space)
text += "\n\n\n\n\n"; text += "\n\n\n\n\n";