Preserving Just the Headings (At All Levels) of a Notes for Editing

Use case or problem

It would be useful to have a way to extract, or preserve, only the headings of any particular note, to allow for copying and editing as a new or substitute note.

For instance, if a note has different headings, established at different levels (such as h1, h2, h3, h4), as a user, one should be able to extract, or keep, just the headings of such a file.

Proposed solution

This feature can be implemented through a plugin by allowing users to FOLD the contents of headings at DIFFERENT HEADING LEVELS by relying on a command or hitting a hotkey.

This new feature would allow users to go beyond FOLDING ALL, including subheadings, like h2, h3, and h4, UNDER THE HIGHEST HEADING LEVEL, such as h1.

Another possibility is the fact that, after making a copy of a given document, there could be a command or hotkey to DELETE any content that is subsumed or included under headings of different levels (h1 and h3).

In other words, if one were to have headings of different levels with bullet-pointed sentences, images, and/or paragraphs (without bullets or numbering), it should be possible to DELETE any and all contents under those headings, for the sake of getting an editable outline.

In turn, this would LEAVE INTACT ALL HEADINGS AT DIFFERENT LEVELS.

What would be possible as a result

This feature would allow users to have a list of all of differently-leveled headings, to get a better idea of the contents of a note.

As of now, there is only a way TO GET AN IDEA OF all of the headings of any particular note --through only VIEWING a note’s outline or table of contents.

However, USERS CANNOT COPY AND/OR EDIT such an outline or table of contents.

*(The caps, presented with kindness in the above writing/text, are there only for gentle emphasis).

You can accomplish this by using one of the regular expression (regex) search-replace plugins. I think one of them lets you save patterns.

Duplicate the note, then search ^[^#].+ (lines that don’t start with #) and replace it with nothing.

Pattern details:

  • ^ = start of line
  • [^#] = any character other than #
  • .+ = 1 or more characters
2 Likes

Thank you for the suggestion. I haven’t tried what you’ve recommended and cannot yet confirm whether it works or not.

Here are some questions whose answers would help.

Which (regex) search-replace plugin do you think would work for this?

I found the ones above but I’m unsure of which one would work best --or whether there is a better option altogether.

Also, how could we turn this into a plug in (for those of us who don’t understand regex)? Do you know of a helpful and relevant regex guide?

I’d recommend Regex Find/Replace as the simplest, or Apply Patterns if you want the added convenience of >1 saved (and maybe named) patterns.

I have Regex Find/Replace installed. It will work fine. It annoys me that it only does “replace all”, but for your purpose that’s fine. It doesn’t let you save search patterns but it remembers the last one used, which again for your purpose is fine.

I dont think I’ve tried the second one you linked, but it would require you to select the whole note first, which would be a small inconvenience.

The Apply Patterns plugin lets you save patterns (possibly it requires you to save them; I don’t remember). I remember the screen where patterns are stored being kind of annoying, but that might have changed and you wouldn’t use that part often anyway. It might let you name patterns, which would be convenient.

I don’t know how to make plugins. I know they’re made out of JavaScript. I don’t think this would be hard for someone who knows how to make them. It just needs to run the regular expression I posted on the current note and then save the result somewhere like the clipboard or a new note (or just alter the current note assuming you’ve duplicated it).

A non-regex option that isn’t quite what you’re asking for is the Table of Contents plugin. It keeps the hierarchy but changes the headings into an indented list, and you’d have to use search/replace to remove the links if you didn’t want them.

1 Like