Is there an easy way to getting or set MMD metadata easily in scripts?

I’m playing with MMD metadata or front matter quite a bit at the moment… and I find myself re-writing the same janky javascript functions.

I’ve been looking through the scripting API, and it’d be awfully nice to be able to use some of the stuff I’m seeing in MultiMarkdown-6:

// Insert/replace metadata in string, returning new string
char * mmd_string_update_metavalue_for_key(const char * source, const char * key, const char * value);

Specifically… I’d love an easy way to get the normal content without the metadata, and a way to CRUD metadata easily without having to copy paste a big ol’ function between my actions.

Anyway, just a thought. Thank you!

Drafts does not expose native C MultiMarkdown constructs to manipulate the document tree. You can control a number of options with the MultiMarkdown script object, but it does not attempt to wrap the C code in a JS API and probably never will - that level of processing is deeper and would be a lot of code to wrap and maintain (those APIs change over MMD versions, etc.).

There’s no need to copy and paste functions, however. You can use the Include Action step to reuse a script defined in another step, or use require(path) to load it from a file in iCloud Drive to reuse a library of functions.

Not sure what your exact goals are either. You could manipulate the meta data at the top of the content before running it through the Markdown processor pretty easily, relative to try to manipulate those values in the parsed tree like those C function do.

That may be enough… what is shared between steps in terms of Include Action? If I wrote a library to manage MMD metadata, and it’s in a script action… are variables shared between script steps?

Answered my own question with some searching.

This is awesome. Thank you!

1 Like

I ended up writing a small “library” to fit my particular use case… zettelkasten in MMD. You can read about what I’m doing here on my blog.

If you want to see the library, you can look at this gist.

I posted the Action Group (my first!) to the Action Directory here.

2 Likes