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