You can do this with a single line script step.
tag in the
tags of a draft, and prefixes them with an octothorps then
joins then together with spaces between.
draft.tags.map(tag => "#" + tag).join(" ");
To insert at the current cursor position, you could expand the line to set the current text selection in the editor to this string of hash tags.
editor.setSelectedText(draft.tags.map(tag => "#" + tag).join(" "));
Bonus: I also added a line to position the cursor at the end afterwards rather than retaining the selection of the inserted text.
Note if you have no selected text, you actually do. It just has zero length and so rather than replacing some text it is effectively just being inserted.
To always append the string of hash tags to the end of the draft, you can simply switch out the first part about the editor for an append to the end of the draft. This will add a newline automatically. Even though it occurs implicitly for a simple script, we force an update of the draft as good practice. The editor will then automatically pick up the update and display it.
draft.append(draft.tags.map(tag => "#" + tag).join(" "));
Welcome to day one of learning to code in Drafts . In all seriousness the forum is full of suggestions for learning how to do this stuff, and everyone starts from zero.