|
|
|
@ -1,3 +1,14 @@ |
|
|
|
|
|
|
|
import { |
|
|
|
|
|
|
|
EMBEDDED_EVENT_REGEX, |
|
|
|
|
|
|
|
EMBEDDED_MENTION_REGEX, |
|
|
|
|
|
|
|
EMOJI_SHORT_CODE_REGEX, |
|
|
|
|
|
|
|
HASHTAG_REGEX, |
|
|
|
|
|
|
|
IMAGE_REGEX, |
|
|
|
|
|
|
|
URL_REGEX, |
|
|
|
|
|
|
|
VIDEO_REGEX, |
|
|
|
|
|
|
|
WS_URL_REGEX |
|
|
|
|
|
|
|
} from '@/constants' |
|
|
|
|
|
|
|
|
|
|
|
export type TEmbeddedNodeType = |
|
|
|
export type TEmbeddedNodeType = |
|
|
|
| 'text' |
|
|
|
| 'text' |
|
|
|
| 'image' |
|
|
|
| 'image' |
|
|
|
@ -25,12 +36,12 @@ type TContentParser = { type: Exclude<TEmbeddedNodeType, 'images'>; regex: RegEx |
|
|
|
|
|
|
|
|
|
|
|
export const EmbeddedHashtagParser: TContentParser = { |
|
|
|
export const EmbeddedHashtagParser: TContentParser = { |
|
|
|
type: 'hashtag', |
|
|
|
type: 'hashtag', |
|
|
|
regex: /#[\p{L}\p{N}\p{M}_]+/gu |
|
|
|
regex: HASHTAG_REGEX |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const EmbeddedMentionParser: TContentParser = { |
|
|
|
export const EmbeddedMentionParser: TContentParser = { |
|
|
|
type: 'mention', |
|
|
|
type: 'mention', |
|
|
|
regex: /nostr:(npub1[a-z0-9]{58}|nprofile1[a-z0-9]+)/g |
|
|
|
regex: EMBEDDED_MENTION_REGEX |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const EmbeddedLegacyMentionParser: TContentParser = { |
|
|
|
export const EmbeddedLegacyMentionParser: TContentParser = { |
|
|
|
@ -40,34 +51,32 @@ export const EmbeddedLegacyMentionParser: TContentParser = { |
|
|
|
|
|
|
|
|
|
|
|
export const EmbeddedEventParser: TContentParser = { |
|
|
|
export const EmbeddedEventParser: TContentParser = { |
|
|
|
type: 'event', |
|
|
|
type: 'event', |
|
|
|
regex: /nostr:(note1[a-z0-9]{58}|nevent1[a-z0-9]+|naddr1[a-z0-9]+)/g |
|
|
|
regex: EMBEDDED_EVENT_REGEX |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const EmbeddedImageParser: TContentParser = { |
|
|
|
export const EmbeddedImageParser: TContentParser = { |
|
|
|
type: 'image', |
|
|
|
type: 'image', |
|
|
|
regex: |
|
|
|
regex: IMAGE_REGEX |
|
|
|
/https?:\/\/[\w\p{L}\p{N}\p{M}&.-/?=#\-@%+_:!~*]+\.(jpg|jpeg|png|gif|webp|bmp|tiff|heic|svg)(\?[\w\p{L}\p{N}\p{M}&.-/?=#\-@%+_:!~*]+)?/giu |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const EmbeddedVideoParser: TContentParser = { |
|
|
|
export const EmbeddedVideoParser: TContentParser = { |
|
|
|
type: 'video', |
|
|
|
type: 'video', |
|
|
|
regex: |
|
|
|
regex: VIDEO_REGEX |
|
|
|
/https?:\/\/[\w\p{L}\p{N}\p{M}&.-/?=#\-@%+_:!~*]+\.(mp4|webm|ogg|mov)(\?[\w\p{L}\p{N}\p{M}&.-/?=#\-@%+_:!~*]+)?/giu |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const EmbeddedWebsocketUrlParser: TContentParser = { |
|
|
|
export const EmbeddedWebsocketUrlParser: TContentParser = { |
|
|
|
type: 'websocket-url', |
|
|
|
type: 'websocket-url', |
|
|
|
regex: /wss?:\/\/[\w\p{L}\p{N}\p{M}&.-/?=#\-@%+_:!~*]+/gu |
|
|
|
regex: WS_URL_REGEX |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const EmbeddedNormalUrlParser: TContentParser = { |
|
|
|
export const EmbeddedNormalUrlParser: TContentParser = { |
|
|
|
type: 'url', |
|
|
|
type: 'url', |
|
|
|
regex: /https?:\/\/[\w\p{L}\p{N}\p{M}&.-/?=#\-@%+_:!~*]+/gu |
|
|
|
regex: URL_REGEX |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const EmbeddedEmojiParser: TContentParser = { |
|
|
|
export const EmbeddedEmojiParser: TContentParser = { |
|
|
|
type: 'emoji', |
|
|
|
type: 'emoji', |
|
|
|
regex: /:[a-zA-Z0-9_-]+:/g |
|
|
|
regex: EMOJI_SHORT_CODE_REGEX |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function parseContent(content: string, parsers: TContentParser[]) { |
|
|
|
export function parseContent(content: string, parsers: TContentParser[]) { |
|
|
|
|