Converting nested headers to a hierarchical list

I have a note with a hierarchy of headers like:

# 1
## 2a
### 2a1
## 2b

I’d like to convert it to:

- 1
  - 2a
     - 2a1
  - 2b

Is there an Action that does this? I tried to search the repository and found the following that does the reverse: Convert Lists to Headers

I think that does something a bit different to the opposite of what you want. It allows you to select a set of list items to transform to a specific heading level and switches the text to title case. Even in reverse, I think you want something more general and sweeping.

From your example text, I think you want something like this.

What would be nice would be something that goes both ways - both promotion and demotion. One implementation detail would need sorting out:

For some documents I go to Heading Level 5 before heading into bullets. md2pptx ascribes meaning up to 4 (3 being w content slide and 4 a card within a slide). Most people want to go to 3, I expect.

So some way of saying e.g. “the highest heading number is n and after that it’s bullets” would be handy.

A nit is that I use asterisks rather than dashes for bullets as dashes can be used by Taskpaper.

Shame I’ve got too much in to build this myself right now.

My action above does use a function that incorporates one boundary heading level. It would be trivial to replace the “start at 1” basis with another boundary. Similarly, there’s a constant set to be the bullet type. That could again be parameterised.

Do keep in mind that Taskpaper and Markdown are different syntaxes and so should not be considered as in influence of one another.

If you are choosing to mix formats and constrain things by convention within your own utility, then you probably need to consider a modification to match all the nuances you might encounter.

1 Like