fix invisible spaces breaking some hashtags

This commit is contained in:
hzrd149 2023-08-23 10:19:59 -05:00
parent 1aa157b32e
commit e4927e7d22
2 changed files with 10 additions and 2 deletions
src
components/embed-types
helpers

@ -5,7 +5,7 @@ import QuoteNote from "../note/quote-note";
import { UserLink } from "../user-link";
import { Link } from "@chakra-ui/react";
import { Link as RouterLink } from "react-router-dom";
import { getMatchHashtag, getMatchNostrLink } from "../../helpers/regexp";
import { getMatchHashtag, getMatchNostrLink, stripInvisibleChar } from "../../helpers/regexp";
// nostr:nevent1qqsthg2qlxp9l7egtwa92t8lusm7pjknmjwa75ctrrpcjyulr9754fqpz3mhxue69uhhyetvv9ujuerpd46hxtnfduq36amnwvaz7tmwdaehgu3dwp6kytnhv4kxcmmjv3jhytnwv46q2qg5q9
// nostr:nevent1qqsq3wc73lqxd70lg43m5rul57d4mhcanttjat56e30yx5zla48qzlspz9mhxue69uhkummnw3e82efwvdhk6qgdwaehxw309ahx7uewd3hkcq5hsum
@ -59,7 +59,10 @@ export function embedNostrMentions(content: EmbedableContent, event: NostrEvent
}
export function embedNostrHashtags(content: EmbedableContent, event: NostrEvent | DraftNostrEvent) {
const hashtags = event.tags.filter((t) => t[0] === "t" && t[1]).map((t) => t[1]?.toLowerCase()) as string[];
const hashtags = event.tags
.filter((t) => t[0] === "t" && t[1])
.map((t) => t[1]?.toLowerCase())
.map(stripInvisibleChar);
return embedJSX(content, {
name: "nostr-hashtag",

@ -5,3 +5,8 @@ export const getMatchNostrLink = () =>
export const getMatchHashtag = () => /(^|[^\p{L}])#([\p{L}\p{N}]+)/gu;
export const getMatchLink = () =>
/https?:\/\/([a-zA-Z0-9\.\-]+\.[a-zA-Z]+)([\p{Letter}\p{Number}&\.-\/\?=#\-@%\+_,:]*)/gu;
// read more https://www.regular-expressions.info/unicode.html#category
export function stripInvisibleChar(str?: string) {
return str && str.replaceAll(/[\p{Cf}\p{Zs}]/gu, "");
}