Skip to content

Commit

Permalink
Correctly extract hashtag content in links and Page Picker filter (fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Maarrk committed Jan 3, 2025
1 parent df9edc5 commit b344f02
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions plugs/markdown/markdown_render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "../../plug-api/lib/tags.ts";

export type MarkdownRenderOptions = {
failOnUnknown?: true;
Expand Down Expand Up @@ -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,
};
Expand Down
3 changes: 2 additions & 1 deletion web/cm_plugins/widget_util.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -45,7 +46,7 @@ export function attachWidgetEventHandlers(
return;
}
client.navigate({
page: `${tagPrefix}${el.innerText.slice(1)}`,
page: `${tagPrefix}${extractHashtag(el.innerText)}`,
pos: 0,
});
});
Expand Down
3 changes: 2 additions & 1 deletion web/components/page_navigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
} from "@codemirror/autocomplete";
import type { PageMeta } from "../../plug-api/types.ts";
import { tagRegex as mdTagRegex } from "$common/markdown_parser/constants.ts";
import { extractHashtag } from "@silverbulletmd/silverbullet/lib/tags";

const tagRegex = new RegExp(mdTagRegex.source, "g");

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b344f02

Please sign in to comment.