Assistance with Syntax Not Working

I’ve created a custom syntax based on the Agile Tortoise example: “Demo: Hashtags and Mentions”

All I’ve done to this is modify and add some syntax variables…

I am getting this error inside the Drafts > Syntax pane: Invalid pattern: 3, error loading

Here is a link to the file

Can anyone assist with
[1] why my colors are not displaying?
[2] Resolve the error?

Many thanks!

1 Like

That error is telling you that at least one of your pattern matches is invalid. Those patterns are the regular expressions you have defined in the syntax.

But, some of your marker characters are special characters in regular expressions. For example a dollar symbol represents the end of line position. Therefore each of these reserved regular expression characters need to be escaped with a backslash; in fact two because of the way the regular expression is read in from the JSON.

After you do that, drop the example text in a draft, and set the syntax type, and you then get this, which I think is what you are looking for with regards to the colours.

My advice is to make use of regular expression testing tools like regex101.com to make sure that your regular expressions are valid definitions and do what is required. It is far easier to debug individually with a specialist tool for these pattern matches than from general error messages as given in Drafts, which is coming at it from a higher functional level.

Also a typo for your sample text, there’s no “o” in “skipping”.

Hope that helps.

1 Like

@sylumer -

Thank you for pointing me in all the right directions. As a result of your advice I was able to successfully render my syntax as intended - link to the file if it helps anyone.

I’m left scratching my head on the depth of what’s next:

  • Highlighting more than the one word associated with the marker characters…
  • Extending support of MultiMarkdown so I do not lose all that critical functionality…

Being that this is my first foray into this type of customization - I may need to adjust my expectations for the time being…

Many thanks,
Jason

1 Like

How might your regex know when to stop, if you’re hoping to capture more than one word? Perhaps consider a closing marker (I daresay this would be easiest)— e.g. !!this phrase for attention!!

2 Likes

Once you’re happy with your definitions, it shouldn’t be too difficult to combine them with another existing syntax. A little fiddly, perhaps, and a JSON validator will serve you well, but should be achievable without too many headaches… :wink:

2 Likes

Yes, realizing after creating, the power and necessity of closing tags!! Will add.

1 Like

Thanks for the direction and encouragement- will be doing!

2 Likes