Move hashtag from end of line to beginning

When I import an outline from MindNode into Drafts the tags are appended to the end of the line. I would love a fancy way to move those tags to the beginning of the line. Here’s an example.

From this:

  • Lorem ipsum dolor sit amet, consectetur adipisicing elit. #keyPoint

to this:

  • #keyPoint Lorem ipsum dolor sit amet, consectetur adipisicing elit.

I don’t know the first thing about modifying text like this. Any and all help is appreciated.

Hopefully, this does what you need.

The technical detail is that the action uses a script step to do a line-by-line regular expression based substitution. It won’t modify lines without hashtags, but any line with a hash tag, it will move from that hash tag and anything following it to the start of the line; also stripping the space preceding the hash tag, and inserting a space after the moved text to separate it from the original line start.

draft.content = => strLine.replace(/^(.*?) \#(.*)/, "#$2 $1")).join("\n");

You are exactly the person I was hoping would see my distress call. :grin: Thank you!

The action is really close to what I want. Could it be modified to put the hashtag after the bullet (- in markdown)? Or, could it delete the bullet, then prepend it to the hashtag, accomplishing the same goal?

Ah okay. I thought the bullets were just your way of separating the lines put in the post. The forum deals in Markdown, so if you have Markdown in sample draft text, it is best to post that text as a code block so it remains as plain text rather than interpreted Markdown.

A bit of an update to the substitution I think should set it right.

Is that more aligned to your needs?

It’s perfect! Next time I’ll be sure to put my text in a code block.

Thank you so much for your help.

Note: Moving the octothorpe (#) to the beginning of the line makes it a heading level 1 - in Markdown.

Possibly not the effect you want.

Markdown headings defined using octothorpes are as 1-6 octothorpes at the start of a line, followed by a space, followed by the text of a heading, optionally followed by a space and closing set of octothorpes.

Moving a hashtag to the start of a line should not cause the line to be interpreted as a heading. That line should only become a heading if the line that follows uses equals or hyphen based underlining - another way to define a heading in Markdown, but referencing the previous line.

1 Like