More control over parts of a draft in scripting

I may be missing something, but it looks like you can only interact with either the title or the entire contents of a draft through scripting (without resorting to parsing the draft contents in the script.)

It would be handy to interact with just the body through draft.body or a specific line like draft.line[6] or something like that.

Could you elaborate by what you mean by “interact with” and how it could be easier? Or what you are trying to accomplish?

You can extract lines and such pretty flexibly with the template engine (tags like [[line|2..4]]). Without details it’s hard to say.

Or do you mean “all the paragraphs” as an array? or “all the headings”? Or “all the sections”? Here a section starts with a heading and carries on to the next heading. (Actually in md2pptx I - since yesterday - deem a horizontal rule as another section boundary.)

I think you can do all this in javascript, BTW. I’m just exploring your meaning and use cases.

Sure, I’ll try to elaborate a bit better.

So I’ve been working on a script (Help - adding to Jira) to add items to Jira. I’d like to pass the title of the draft in as the issue summary, and the body in as the issue description. So ideally I’d like to do something like this:

var summary = draft.title
var description = draft.body

The behaviour of the above is ‘summary’ will have a value populated from the title, but ‘description’ will be undefined.

To get around it, I’m currently adding a step in the action before the script gets run to copy the [[body]] to the clipboard, then declaring description with

var description = app.getClipboard();

So, in a way, I am using the template engine for this purpose, but it just feels kludgy to me to pass the data to the script through the clipboard. I guess what I’m getting it, is, is there a way to directly use template tags within a script itself?

1 Like

The “proper” way to do that is use the template engine, like:

var description = draft.processTemplate("[[body]]");

This works with any of the supported template tags in the template, just like you were configuring a template in other action steps.

1 Like

Ah, thanks, somehow I missed that function when I was looking at the scripting documentation. That totally solves this - thanks!

I’m curious, what’s the rationale of having the .title function in scripting as its own special thing? Or was that just a holdover from before the template engine was introduced?

1 Like