From 76114412526b28625f4b9530cf79f34cfd7eb055 Mon Sep 17 00:00:00 2001 From: Marty Date: Wed, 28 Nov 2018 18:56:47 +0000 Subject: [PATCH] Add Customizable Template Added option to set a template to be used upon creating a new Zettel. Makes use of 2 placeholders: {headline} and {anchor} which get inserted on creation. --- zettel.qml | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/zettel.qml b/zettel.qml index 00d4c9c..05a4761 100644 --- a/zettel.qml +++ b/zettel.qml @@ -6,6 +6,7 @@ QtObject { property bool anchorInFilename; property string idMarker; property bool wikiLinks; + property string template; property variant settingsVariables: [ { @@ -29,6 +30,13 @@ QtObject { "type": "boolean", "default": "false", }, + { + "identifier": "template", + "name": "Zettel Template", + "description": "What gets created when letting the script create a new Zettel.\nUse {headline} and {anchor} as placeholders to be put there on Zettel creation.", + "type": "text", + "default": "{headline}\n===============\n{anchor}\n\n\n\n\n\n\n## Related\n\n\n\n## Reference\n\n", + }, ] function init() { @@ -172,7 +180,6 @@ QtObject { } // Looks for the uID (optionally) in all note texts. - // If no uID passed in, simply return all notes which conform to the Zettel-Title template. function _getAllZettelFromTitle(optionaluID) { let allnotes = script.fetchNoteIdsByNoteTextPart(""); let noteIds = []; @@ -217,26 +224,13 @@ QtObject { if (headline == "") { headline = "Zettel" } - let text = ""; + let text = template; - if (anchorInFilename) text += uid.toString() + " "; - - text += headline.toString() + "\n"; - - // Create Headline Separator - text += "===============\n"; - - // Create uid tag - if (!anchorInFilename) text += idMarker + uid.toString() + "\n\n"; - - // Create content unit (i.e. space) - text += "\n\n\n\n\n"; - - // Create Related unit - FIXME add option to automatically link back to the card this was created from - text += "## Related\n\n\n\n"; - - // Create Source unit - text += "## Reference\n\n"; + if (anchorInFilename) { + text = text.replace(/\{headline\}/, uid.toString() + " " + headline).replace(/\{anchor\}/, ""); + } else { + text = text.replace(/\{headline\}/, headline).replace(/\{anchor\}/, idMarker + uid.toString()); + } script.createNote(text); return script.currentNote();