Converting H1 to Inline Notes for Evergreen Notes

My friend Joschua wrote recently about the virtues of Inline Titles in note-making. I've been solidly on the "Title & H1" camp for a while, but I've also been manually keeping them synced.

I was asking Joschua what he did to migrate his notes over to inline titles… and he replied he's been manually changing them as he encounters it in his notes. So I wrote him a script:

# work through every file ending in .md
Dir.glob("./**/*.md").each do |file|
  # extract the left part of the filename
  filename = File.basename(file, '.md')
  # read the file
  content  =
  # split the file into an array of strings
  lines    = content.lines

  # find a line that matches the filename
  matching_title = lines.find_index { |l| l.match /^# #{filename}\s*$/ }

  if matching_title then
    # find block of empty lines
    blank_lines = matching_title + 1
    while lines[blank_lines] and lines[blank_lines].match(/^\s*$/) do
      blank_lines += 1

    # remove the header matching the title and following blank lines
    lines.slice!(matching_title..blank_lines - 1)

    File.write(file, lines.join)

(from headers.rb)

This script is destructive and changes your files without warning!

I would counsel only running it on a backed-up folder if you are comfortable with scripts.

If this transformation is something you want and you need help, you can message me.

If there was enough interest, I'm sure the basic logic could be translated to JavaScript and turned into a plugin for folks that want to embrace inline titles in their Obsidian notes.