From e29024562143c5c8a42f61c7570c21516e79173b Mon Sep 17 00:00:00 2001 From: Matthew Pietz Date: Mon, 26 Feb 2024 09:03:55 -0800 Subject: [PATCH] Relax hashtag pattern matching (Support Emoji) (#752) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- common/markdown_parser/parser.ts | 4 +++- web/components/page_navigator.tsx | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/common/markdown_parser/parser.ts b/common/markdown_parser/parser.ts index c2dbb3e3..84bdf6d1 100644 --- a/common/markdown_parser/parser.ts +++ b/common/markdown_parser/parser.ts @@ -19,6 +19,8 @@ import { TaskList } from "./extended_task.ts"; export const pageLinkRegex = /^\[\[([^\]\|]+)(\|([^\]]+))?\]\]/; +export const tagRegex = /#[^\d\s!@#$%^&*(),.?":{}|<>\\][^\s!@#$%^&*(),.?":{}|<>\\]*/; + const WikiLink: MarkdownConfig = { defineNodes: [ { name: "WikiLink", style: ct.WikiLinkTag }, @@ -504,7 +506,7 @@ const NakedURL = regexParser( const Hashtag = regexParser( { firstCharCode: 35, // # - regex: /^#[^#\d\s\[\]]+\w+/, + regex: new RegExp(`^${tagRegex.source}`), nodeType: "Hashtag", className: "sb-hashtag", tag: ct.HashtagTag, diff --git a/web/components/page_navigator.tsx b/web/components/page_navigator.tsx index 3e5de8dc..00c177e8 100644 --- a/web/components/page_navigator.tsx +++ b/web/components/page_navigator.tsx @@ -3,8 +3,9 @@ import { FilterOption } from "../../type/web.ts"; import { CompletionContext, CompletionResult } from "../deps.ts"; import { PageMeta } from "../../type/types.ts"; import { isFederationPath } from "$sb/lib/resolve.ts"; +import { tagRegex as mdTagRegex } from "$common/markdown_parser/parser.ts"; -export const tagRegex = /#[^#\d\s\[\]]+\w+/g; +const tagRegex = new RegExp(mdTagRegex.source, "g") export function PageNavigator({ allPages,