Thanks holroy!
I paste here my script, working and probably a little verbose. I also paste a screencapture to show what does what, in case someone else has a similar wish and can adapt this.
Goal
When I am reading historical sources, I come across dates of events. I want to collect them, but very quickly. So I have a template that can parse what is fast for me to type:
starting-date::1930-03-10
label:: Legislation passed on ...
After I select that text, I press hotkeys to run a template. That template will create a new file with a unique name (date with seconds)
and indicate it’s a “timeline_item” in my system. I want to keep track which Obsidian note is the “parent” note, or “source” note.
I haven’t decided if I want to put information in the YAML header or in the body of the new to-be-created-note. So in the script below. I put it in both places. Single colon in the YAML header and double colon in the body of the to-be-created-note.
I also want all the “timeline_items” to be collected into a separate folder. That is hard-coded in my script.
And in the parent document, after I run this template, I want to:
wrap the selected text to enclose it in backticks ```, to quickly give me a visual
indication that these name-value pairs have been turned into a timeline_item.
And I make a link from the parent note to the just-created-note with an aliased “TL”.
I pasted a screenshot too, below. It’s a bit messy, but perhaps useful.
<%*
/* https://silentvoid13.github.io/Templater/internal-functions/internal-modules/system-module.html */
let my_content = tp.file.selection();
let my_source_note = tp.file.title;
/* somehow these three are the same: (which confuses me) */
/* 1) tp.config.target_file.name 2) tp.config.active_file.name
/* and 3) tp.file.title point to the parent document */
if (my_content) {
newfilename = tp.date.now("YYYYMMDD-hhmmss") + "_timeline_item";
tp.file.create_new("---\nsource-note:\"" + my_source_note + "\"\n---\n"
+ my_content + "\n"
+ "source-note:: [[" + my_source_note + "]]",
newfilename, false, app.vault.getAbstractFileByPath("Delta-Mississippi/timeline_items") );
tR = "```\n" + tp.file.selection() + "\n```" + " \n" + "[[" + newfilename + "|TL]]"
}
%>