From 1508f6bcbfd9990ad55bafb72713b7c417764f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20S=2E=20=C5=81ukasiewicz?= Date: Tue, 7 Jan 2025 19:57:46 +0100 Subject: [PATCH] Correctly extract hashtag content in links and Page Picker filter (fix #1196) (#1199) --- plugs/markdown/markdown_render.ts | 5 +++-- web/cm_plugins/widget_util.ts | 3 ++- web/components/page_navigator.tsx | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/plugs/markdown/markdown_render.ts b/plugs/markdown/markdown_render.ts index 5b8b822e..17458c91 100644 --- a/plugs/markdown/markdown_render.ts +++ b/plugs/markdown/markdown_render.ts @@ -15,6 +15,7 @@ import { Fragment, renderHtml, type Tag } from "./html_render.ts"; import { isLocalPath } from "@silverbulletmd/silverbullet/lib/resolve"; import type { PageMeta } from "@silverbulletmd/silverbullet/types"; import * as TagConstants from "../../plugs/index/constants.ts"; +import { extractHashtag } from "@silverbulletmd/silverbullet/lib/tags"; export type MarkdownRenderOptions = { failOnUnknown?: true; @@ -342,8 +343,8 @@ function render( name: "a", attrs: { class: "hashtag sb-hashtag", - "data-tag-name": tagText.replace("#", ""), - href: `/${TagConstants.tagPrefix}${tagText.replace("#", "")}`, + "data-tag-name": extractHashtag(tagText), + href: `/${TagConstants.tagPrefix}${extractHashtag(tagText)}`, }, body: tagText, }; diff --git a/web/cm_plugins/widget_util.ts b/web/cm_plugins/widget_util.ts index f2765ddf..39a9ddf5 100644 --- a/web/cm_plugins/widget_util.ts +++ b/web/cm_plugins/widget_util.ts @@ -1,6 +1,7 @@ import { parsePageRef } from "@silverbulletmd/silverbullet/lib/page_ref"; import type { Client } from "../client.ts"; import { tagPrefix } from "../../plugs/index/constants.ts"; +import { extractHashtag } from "@silverbulletmd/silverbullet/lib/tags"; export function attachWidgetEventHandlers( div: HTMLElement, @@ -45,7 +46,7 @@ export function attachWidgetEventHandlers( return; } client.navigate({ - page: `${tagPrefix}${el.innerText.slice(1)}`, + page: `${tagPrefix}${extractHashtag(el.innerText)}`, pos: 0, }); }); diff --git a/web/components/page_navigator.tsx b/web/components/page_navigator.tsx index f9460bc3..453c4223 100644 --- a/web/components/page_navigator.tsx +++ b/web/components/page_navigator.tsx @@ -4,8 +4,9 @@ import type { CompletionContext, CompletionResult, } from "@codemirror/autocomplete"; -import type { PageMeta } from "../../plug-api/types.ts"; +import type { PageMeta } from "@silverbulletmd/silverbullet/types"; import { tagRegex as mdTagRegex } from "$common/markdown_parser/constants.ts"; +import { extractHashtag } from "@silverbulletmd/silverbullet/lib/tags"; const tagRegex = new RegExp(mdTagRegex.source, "g"); @@ -151,7 +152,7 @@ export function PageNavigator({ const allTags = phrase.match(tagRegex); if (allTags) { // Search phrase contains hash tags, let's pre-filter the results based on this - const filterTags = allTags.map((t) => t.slice(1)); + const filterTags = allTags.map((t) => extractHashtag(t)); options = options.filter((pageMeta) => { if (!pageMeta.tags) { return false;