diff --git a/src/lib/editor/index.ts b/src/lib/editor/index.ts index f88d3000..79329969 100644 --- a/src/lib/editor/index.ts +++ b/src/lib/editor/index.ts @@ -20,6 +20,7 @@ import { TagExtension, } from "nostr-editor" import type {StampedEvent} from "@welshman/util" +import {toNostrURI} from "@welshman/util" import {signer, profileSearch} from "@welshman/app" import {FileUploadExtension} from "./FileUpload" import {createSuggestions} from "./Suggestions" @@ -107,6 +108,7 @@ export const getEditorOptions = ({ Bolt11Extension.extend(asInline({addNodeView: () => SvelteNodeViewRenderer(EditBolt11)})), NProfileExtension.extend({ addNodeView: () => SvelteNodeViewRenderer(EditMention), + renderText: props => toNostrURI(props.node.attrs.nprofile), addProseMirrorPlugins() { return [ createSuggestions({ @@ -126,8 +128,18 @@ export const getEditorOptions = ({ ] }, }), - NEventExtension.extend(asInline({addNodeView: () => SvelteNodeViewRenderer(EditEvent)})), - NAddrExtension.extend(asInline({addNodeView: () => SvelteNodeViewRenderer(EditEvent)})), + NEventExtension.extend( + asInline({ + addNodeView: () => SvelteNodeViewRenderer(EditEvent), + renderText: (props: any) => toNostrURI(props.node.attrs.nevent), + }), + ), + NAddrExtension.extend( + asInline({ + addNodeView: () => SvelteNodeViewRenderer(EditEvent), + renderText: (props: any) => toNostrURI(props.node.attrs.nevent), + }), + ), ImageExtension.extend( asInline({addNodeView: () => SvelteNodeViewRenderer(EditImage)}), ).configure({defaultUploadUrl, defaultUploadType: uploadType}), diff --git a/src/lib/editor/util.ts b/src/lib/editor/util.ts index 6c070564..6231e7cf 100644 --- a/src/lib/editor/util.ts +++ b/src/lib/editor/util.ts @@ -2,6 +2,7 @@ import type {JSONContent, PasteRuleMatch, InputRuleMatch} from "@tiptap/core" import {Editor} from "@tiptap/core" import {ctx} from "@welshman/lib" import {Address} from "@welshman/util" +import {repository} from "@welshman/app" export const asInline = (extend: Record) => ({ inline: true, @@ -69,12 +70,13 @@ export const getEditorTags = (editor: Editor) => { }, ) - const neventTags = findNodes("nevent", json).map(({attrs: {id, author, relays = []}}: any) => [ - "q", - id, - ctx.app.router.FromRelays(relays).getUrl(), - author || "", - ]) + const neventTags = findNodes("nevent", json).map(({attrs: {id, author, relays = []}}: any) => { + const event = repository.getEvent(id) + const pubkey = author || repository.getEvent(id)?.pubkey || "" + const scenario = event ? ctx.app.router.Event(event) : ctx.app.router.FromPubkeys([pubkey]) + + return ["q", id, scenario.getUrl(), pubkey] + }) const mentionTags = findNodes("nprofile", json).map(({attrs: {pubkey, relays = []}}: any) => [ "p",