I have around a thousand notes that have inline fields, something like this:
# File Name
![[embedded image]]
---
title:: abc
date:: 2022-08-08
director:: [[Ab Cdee]]
actors:: [[x ray]], [[bizzy bobs]], [[hunker munker]]
key:: value
anotherkey:: another value
---
## summary
paragraphs of text
All of the inline fields are bound by three opening and three closing dashes (---) on their own lines.
Is it possible to use regex (in VS Code) or something else to capture everything between the opening and closing dashes and move all the lines to the top of the files to create properties-friendly YAML headers? Like this:
---
title:: abc
date:: 2022-08-08
director:: [[Ab Cdee]]
actors:: [[x ray]], [[bizzy bobs]], [[hunker munker]]
key:: value
anotherkey:: another value
---
# File Name
![[embedded image]]
## summary
paragraphs of text
I have looked online but not found a way to do what I want to do.
This isn’t a simple find-and-replace operation, so you’ll need a shell script to parse the header, find the first two occurrences of the yaml hyphens, then copy the lines in between into a list, copy whatever else comes before that yaml block to another list, then rewrite your note and put both lines in the right order, add the rest of your note minus the lines you copied and put this routine in a loop to process notes in a folder / your vault.
I could lose all the opening text, I guess. So is it possible to search for and delete everything from the start of each file to the first set of dashes? That would move all of the inline fields to the top of each file.
VS cide is (mostly) capable of doing this, but there are a lot of caveats you need to handle. Here are sime of them:
how to handle if you’ve used the triple dashes for a horizontal line somewhere and not bas start or end of a block?
inline fields use double colons, not a single colon, to separate key and value
inline fields doesn’t use quotes around links, but yaml needs that
list syntax has slightly different syntax in the various incantations of inline vs yaml
how will you handle notes having a yaml block from already? How to merge together a yaml block and an inline block?
if I’ve understood it correctly, there is also the slight matter of inline field links being recognised as outlinks, while yaml links (currently?) are not?
In other words it’s not just as “simple” as either moving the first block after the other, or removing lines in front of your inline field blocks. So care should be taken before proceeding. Thread carefully…
If you want to torment(?) yourself more, or want to pursue this issue another time, I recommend reading this post where I did something similar.
It displays how I dealt with some of the caveats in a similar case, and it might give you some suggestions as to what kind of regex’s you’ll need to handle your case as well.
Python is way out of my tiny sphere of knowledge. Would be useful if Linter offered this feature, as discussed in the thread linked above and on GitHub.
I realized that I could use the regex above to repeatedly remove the first line, so I did that several times until it reached the triple-dash YAML header.
Have been running various search and replace ideas on the text and it is getting closer to what I want.
Just using a sandbox of test data at the moment. If I can really get things pretty good, I will either do a clean run of all the search and replaces or swap the sandbox data into my main vault.
Not going to be completely accurate but probably good enough until a problem crops up and needs to be rectified by hand.
I probably would have gone down the same route: that way I can measure and applaud some progress.
But – as I learned the hard way a year ago myself, overbiting with my scant regex forte – there are many unknowns down the road. So a sandbox idea was a good one.