From 01cce369ff82ab54d12dfb514780c1cb9850ab79 Mon Sep 17 00:00:00 2001 From: Marty Date: Wed, 28 Nov 2018 16:49:24 +0000 Subject: [PATCH 1/2] Enable WikiStyle links Creates new option to allow new default style for links. Made link following more flexible, allowing for a wide range of selection or cursor positions. Ensure a Zettel exists before attempting to jump there. --- zettel.qml | 57 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/zettel.qml b/zettel.qml index f1efd78..0c7c2fd 100644 --- a/zettel.qml +++ b/zettel.qml @@ -4,6 +4,7 @@ import com.qownnotes.noteapi 1.0 QtObject { property string idMarker; + property bool wikiLinks; property variant settingsVariables: [ { @@ -12,7 +13,14 @@ QtObject { "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": "§§", - } + }, + { + "identifier": "wikiLinks", + "name": "Default to [[WikiLinks]]", + "description": "By default, links will take the form of standard markdown links. This will make automatically created links between Zettel take the form of wiki-links instead. The go to link function understands both types, regardless of this choice.", + "type": "boolean", + "default": "false", + }, ] function init() { @@ -45,7 +53,6 @@ QtObject { // Link the from the old Zettel to the new one if anything was selected if(selected !== "") { - script.log("selected: " + selected); createLinkInPlace(uid, selected); } @@ -72,12 +79,12 @@ QtObject { } function onJumpToZettelClicked() { - let selected = verifyZettelId(script.noteTextEditSelectedText()); + let selected = verifyZettelId(script.noteTextEditSelectedText(), true) ? verifyZettelId(script.noteTextEditSelectedText(), true) : verifyZettelId(script.noteTextEditCurrentWord(true), true); - if(selected == false) { - script.setCurrentNote(zettelSelectorDialog(true)); + if (selected) { + setNoteToZettelIdOrElse(selected, function(uid) {script.informationMessageBox("Zettel " + uid + " does not exist.")}); } else { - script.setCurrentNote(getNoteByZettelId(selected)); + script.setCurrentNote(zettelSelectorDialog(true)); } } @@ -86,17 +93,13 @@ QtObject { // ---------------------------- function autocompletionHook() { - let uid = verifyZettelId(script.noteTextEditCurrentWord(false)); + let uid = verifyZettelId(script.noteTextEditCurrentWord(true), true); if(uid == false) { return []; } - let zettel = getNoteByZettelId(uid); - script.log("Autocomplete detected, Switch to " + idMarker + uid + " - " + zettel.name) - - script.setCurrentNote(zettel); - + setNoteToZettelIdOrElse(uid); return []; } @@ -115,7 +118,7 @@ QtObject { } let selected = script.inputDialogGetItem("Zettel", "Select a Zettel", zettelArray, 0, editableTextBox); - + // FIXME dont display id in names - rather, go getNotebyName(name) -> (get its id) -> set note to it return script.fetchNoteById(selected.substring(selected.search(/--id:/)+5)); } @@ -123,17 +126,21 @@ QtObject { 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; } return text.substring(markerpos, markerpos+14); } - function verifyZettelId(id) { - if (id.match(new RegExp(idMarker + '^\\d{14}$')) != null) { - return id.substring(2); - } else if (id.match(/^\d{14}$/) != null) { + function stripZettelId(link) { + return link.replace(/\D*/g, ""); + } + + function verifyZettelId(id, shouldStrip) { + if (shouldStrip) id = stripZettelId(id); + if (id.match(/^\d{14}$/) != null) { return id; + } else if (id.match(new RegExp(idMarker + '^\\d{14}$')) != null) { + return id.substring(2); } else { return false; } @@ -142,14 +149,22 @@ QtObject { function getNoteByZettelId(uid) { let noteId = script.fetchNoteIdsByNoteTextPart(idMarker + uid); if (noteId.length == 0) { - script.log("No note found for Zettel ID: " + idMarker + uid); return; } return script.fetchNoteById(noteId[0]); } + function setNoteToZettelIdOrElse(uid, orElse) { + let zettel = getNoteByZettelId(uid); + if (zettel == null) { + if(orElse != null) orElse(uid); + return; + } + script.setCurrentNote(zettel); + } + function createLinkInPlace(uid, selected) { - script.noteTextEditWrite("["+selected+"](zettel://"+uid+")"); + wikiLinks ? script.noteTextEditWrite("[[" + uid + "]] " + selected) : script.noteTextEditWrite("["+selected+"](" + uid + ")"); } function createZettel(uid, headline) { @@ -193,4 +208,4 @@ QtObject { function padToLen2(text) { return ("00" + text).slice(-2) } -} +} \ No newline at end of file -- 2.45.2 From 6eee455c3690981409c4c977f78d1e9d4eca25f5 Mon Sep 17 00:00:00 2001 From: Marty Date: Wed, 28 Nov 2018 16:55:55 +0000 Subject: [PATCH 2/2] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ee5d381..d40e7f0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # QOwn-Zettelkasten -Simple Zettelkasten functionality for QOwnNotes. \ No newline at end of file +Simple Zettelkasten functionality for QOwnNotes. + +Note: If using standard markdown links for Zettel Anchors - the autocomplete function of QOwnNotes will first attempt to find a note with the *name* of the link. By default it will then ask you if you want to create that note. If you want to make use of the autocomplete for Zettelkasten links primarily (and intend to use standard markdown links) make sure to tick "Don't as again" before clicking "No". Subseqent autocompletes will instantly jump to the selected Zettel. \ No newline at end of file -- 2.45.2