silverbulletmd / silverbullet

The hackable notebook
https://silverbullet.md
MIT License
2.06k stars 146 forks source link

Relax hashtag pattern matching (Support Emoji) #752

Closed sirlancelot closed 4 months ago

sirlancelot commented 4 months ago

Adjust the RegExp for matching tags in order to better support compatibility with other PKM systems. Though not the exact matcher used in Obsidian (since its source is closed), this matcher is modeled mostly after it and allows most non-whitespace characters, including Emoji.

I use a task line like - [ ] Gift Idea #🎁 #Person-Name to denote gift ideas for friends and family. This patch allows SilverBullet to recognize the emoji.

sirlancelot commented 4 months ago

The RegExp is two largely identical character classes [], with the first one also excluding numbers. The effect is that tags must start with a non-numerical character, followed by zero or more of any other character, including digits.

I wrote some tests here: https://regex101.com/r/6g27ZK/1

zefhemel commented 4 months ago

Cool, but I'm pretty sure there are multiple other places, for sure in some auto complete functions where similar regexes are used. Could you do a quick codebase search for the likes of hashtagRegex or tagRegex and similar as well? Browny points if you manage to centralize it all in one place.

sirlancelot commented 4 months ago

I found one other file that uses it in web/. I went ahead and consolidated the usage to common/ and imported it within web/.

sirlancelot commented 4 months ago

Hold up, it looks like the two RegExps are ever so slightly different. I can fix it in just a min.

sirlancelot commented 4 months ago

Okay, it should be ready for you now! :)

zefhemel commented 4 months ago

This seems to work as advertised, thanks! Merging :)

sirlancelot commented 4 months ago

Thank you!