Merge pull request #528 from v0l/fix-nostr-npub-broken-links

don't render nostr:npub as a link
This commit is contained in:
2023-04-20 21:49:46 +01:00
committed by GitHub
4 changed files with 60 additions and 3 deletions

View File

@ -7,7 +7,7 @@ import * as unist from "unist";
import { HexKey, NostrPrefix } from "@snort/nostr";
import { MentionRegex, InvoiceRegex, HashtagRegex } from "Const";
import { eventLink, hexToBech32, splitByUrl, unwrap } from "Util";
import { eventLink, hexToBech32, splitByUrl, unwrap, validateNostrLink } from "Util";
import Invoice from "Element/Invoice";
import Hashtag from "Element/Hashtag";
import Mention from "Element/Mention";
@ -36,7 +36,21 @@ export default function Text({ content, tags, creator, disableMedia, depth }: Te
.map(f => {
if (typeof f === "string") {
return splitByUrl(f).map(a => {
if (a.match(/^(?:https?|(?:web\+)?nostr|magnet):/i)) {
const validateLink = () => {
const normalizedStr = a.toLowerCase();
if (normalizedStr.startsWith("web+nostr:") || normalizedStr.startsWith("nostr:")) {
return validateNostrLink(normalizedStr);
}
return (
normalizedStr.startsWith("http:") ||
normalizedStr.startsWith("https:") ||
normalizedStr.startsWith("magnet:")
);
};
if (validateLink()) {
if (disableMedia ?? false) {
return (
<a href={a} onClick={e => e.stopPropagation()} target="_blank" rel="noreferrer" className="ext">