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.
This commit is contained in:
parent
e2a238e812
commit
7611441252
1 changed files with 14 additions and 20 deletions
34
zettel.qml
34
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();
|
||||
|
|
Loading…
Reference in a new issue