Create Markdown Sub-Bullets

I often receive a bulleted list of agenda items for meetings that I copy and paste into Drafts. I would like to figure out an action that would take this list and add blank indented sub-bullets to it.

I thought’s @agiletortoise’s Markdown List action would be a good place to start, but it is a much more complicated script than I am comfortable editing.

Any suggestions?

Okay, I’m sure someone else will suggest a far more sophisticated solution, but if you’re willing to experiment off the back of a suggestion, try this script step in an action:

myList = draft.content.trim().replace(/\n/g,"\n\t- \n- ")
draft.content = "- " + myList + "\n\t- "
draft.update()

Super simple, nothing fancy. This assumes you don’t have anything else in the draft, as pictured. If you sometimes start with a title, it wouldn’t be too difficult to adjust to ignore the n line(s). Also could be adjusted to work solely on selected text. Or could even be set to run on the clipboard instead of the draft, so instead of copying, pasting, and then running the action, you could just copy, then run the action and produce a new draft with the copied text, bulleted and indented… Possibilities! :wink:

2 Likes

This is a quick solution and gets my engineer’s approval

2 Likes

Thank you @jsamlarose!

I will be running this inside of a larger draft on selected text, so I will work on building that part. Thanks for giving me a starting point!

1 Like

It seems like it is working! How did I do?

var myList = editor.getSelectedText().replace(/\n/g,"\n\t- \n- ");
editor.setSelectedText( "- "+myList+"\n\t- ")
draft.update()

Thanks again @jsamlarose!

1 Like

At the end of the day, as long as you can use and maintain the code, then that’s all that really matters, but I would suggest the following in terms of potential modifications.

  1. Try and get used to using let rather than var, though you could even use const, or forego the use of a separate variable entirely by merging the first and second line (though some may find merging harder to read). Using a definition with a restricted scope can save you errors when you deal with more complex code.
  2. Be consistent with your structure - it makes it easier to read and follow your own code.
    • Be consistent with your semicolons. If you are going to end lines with semi colons, try to always end with them.
    • Be consistent with your use of spaces. You have a rogue space on line two after the opening parenthesis.
  3. You are working with the editor and not changing the draft object, so the last line to update the draft I believe is redundant.
  4. If it is something you may not follow a year from now, consider adding a comment line, even if it just links to this thread.
5 Likes

Excellent feedback, thank you! I was trying to look at another action and add similar code in to this one. I see now were things got sloppy.

I updated the code with your notes and it still works (not a comment on your suggestions, just on my execution).

Thanks again @sylumer!

The sweet spot for commenting seems to me to be 3 months after you wrote the damned code. :slight_smile:

How do I apply this? Do I grab an action? And does respond to the Tab key?

I tried your script and it screwed my whole list up. I didn’t give much thought to the sentence above.

What is it you are wanting to do? This thread is about a pretty specific and unusual need to insert a series of sub-bulleted lines.

You mention tab, are you just looking for indentation? Is so, see this tip: TIP: Setup Tab / Shift-Tab Indentation Shortcuts

I needed exactly what the post title is: “Create Markdown Sub-Bullets.”

The script above didn’t work for what I needed - I tried it. It messed up my list with too many spaces between lines.

I wrote my my own script/action with the help of ChatGPT. It worked like a charm. But the action wasn’t really needed either. This is what I was trying to accomplish:

Main title

  • Section title
    • Article title

Here is the action I use to achieve the my goal in the original image.

I have a plain text list of items (not formatted in markdown) in a draft, I select the list and use this action to turn the selection into a markdown formatted list with blank sub-bullets.

I hope it helps!