Hi everyone! I’m trying to make a script that will find if a draft has a link in it and will add the tag “links” to it. Of course, I can do this manually, but where’s the fun in that, especially if I want to be consistent about tagging?
Right now, I don’t really know RegEx at all, and can barely write JavaScript. I’ve been looking around in the Drafts script reference and action directory but I haven’t been able to find things similar.
Currently, my script looks like this
// add links tag
// define regex to use...
const findRegex = /(\[((?:\[[^\]]*\]|[^\[\]])*)\]\([ \t]*()<?((?:\([^)]*\)|[^()\s])*?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g;
if (draft.content.(findRegex) = true) {
draft.addTag("links");
}
This RegEx is something that I found on regexr.com, and it finds markdown links, which isn’t totally ideal, but it’s a start. It doesn’t seem to me like there is a way to search a draft to get a boolean back, but I am really over my head here and any pointers or anything would be great!