Prepend each line with static text during an action

Hi!

I would like to create an action that prepends each line in the draft with a static text, e.g. “Birthday of”. That should be in action because I will later send the draft text to Things with the titles action.

I guess that should be easy with Javascript, but right now I am a newbie. Therefore I would be very happy if some could post a JS snippet how to do that.

Best,

Daniel

The TAD-Prefix Text action in the ThoughtAsylum - Writing action group will let you do that.

You can also search on the TADpoLe site for “prefix” and you’ll find a few TADpoLe functions you can access to give you some options on when to prefix.


Hope that helps.

1 Like

This is also something you can do pretty easily with regular expression find/replace.

^(.*)$ will find each line. Using the $1 capture group in the replace inserts the text found between the parentheses.

1 Like

Thanks for both posts of you. I would like to make those prepending as a step in an action and not manually. Right now, my action has only one url step.

I need an action step that manipulates my current [[draft]] and prepends every line with a string. Is there an intro somewhere how to do that? Personally I would like to do it without an additional library if possible.

The same regex approach for find and replace can be done in script as well. That would look something like:

// define the prefix you want to prepend
const prefix = "Birthday of ";
// do the replacement 
draft.content = draft.content.replace(/^(.*)$/gm, function(v) {
	return `${prefix}${v}`
});
draft.update();
2 Likes

Perfect, Greg. That works fine and I have an idea now how that works. Thanks a lot.

1 Like