mirror of
https://github.com/aljazceru/njump.git
synced 2026-02-23 15:04:22 +01:00
Parse and show video
This commit is contained in:
20
utils.go
20
utils.go
@@ -137,7 +137,6 @@ func ReplaceURLsWithTags(line string) string {
|
||||
regexPattern := fmt.Sprintf(`\s*(https?://\S+%s)\s*`, extension)
|
||||
regex := regexp.MustCompile(regexPattern)
|
||||
matches := regex.FindAllString(line, -1)
|
||||
|
||||
for _, match := range matches {
|
||||
imgTag := fmt.Sprintf(`<img src="%s" alt="">`, strings.ReplaceAll(match, "\n", ""))
|
||||
line = strings.ReplaceAll(line, match, imgTag)
|
||||
@@ -145,6 +144,19 @@ func ReplaceURLsWithTags(line string) string {
|
||||
}
|
||||
}
|
||||
|
||||
// Match and replace mp4 URLs with <video> tag
|
||||
videoExtensions := []string{".mp4", ".ogg", ".webm"}
|
||||
for _, extension := range videoExtensions {
|
||||
regexPattern := fmt.Sprintf(`\s*(https?://\S+%s)\s*`, extension)
|
||||
regex := regexp.MustCompile(regexPattern)
|
||||
matches := regex.FindAllString(line, -1)
|
||||
for _, match := range matches {
|
||||
videoTag := fmt.Sprintf(`<video controls width="100%%"><source src="%s"></video>`, strings.ReplaceAll(match, "\n", ""))
|
||||
line = strings.ReplaceAll(line, match, videoTag)
|
||||
return line
|
||||
}
|
||||
}
|
||||
|
||||
// Match and replace npup1, nprofile1, note1, nevent1, etc
|
||||
nostrRegexPattern := `\s*nostr:((npub|note|nevent|nprofile)1[a-z0-9]+)\s*`
|
||||
nostrRegex := regexp.MustCompile(nostrRegexPattern)
|
||||
@@ -161,8 +173,8 @@ func ReplaceURLsWithTags(line string) string {
|
||||
})
|
||||
|
||||
// Match and replace other URLs with <a> tags
|
||||
otherRegexPattern := `\S*(https?://\S+)\S*`
|
||||
otherRegex := regexp.MustCompile(otherRegexPattern)
|
||||
line = otherRegex.ReplaceAllString(line, `<a href="$1">$1</a>`)
|
||||
hrefRegexPattern := `\S*(https?://\S+)\S*`
|
||||
hrefRegex := regexp.MustCompile(hrefRegexPattern)
|
||||
line = hrefRegex.ReplaceAllString(line, `<a href="$1">$1</a>`)
|
||||
return line
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user