mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-17 06:14:22 +01:00
Add an option to basicFormatting to skip links
SQUASH
This commit is contained in:
2
data.go
2
data.go
@@ -77,7 +77,7 @@ func (ee EnhancedEvent) RssTitle() string {
|
|||||||
|
|
||||||
func (ee EnhancedEvent) RssContent() string {
|
func (ee EnhancedEvent) RssContent() string {
|
||||||
content := ee.event.Content
|
content := ee.event.Content
|
||||||
content = basicFormatting(html.EscapeString(content), true, false)
|
content = basicFormatting(html.EscapeString(content), true, false, false)
|
||||||
content = renderQuotesAsHTML(context.Background(), content, false)
|
content = renderQuotesAsHTML(context.Background(), content, false)
|
||||||
if ee.IsReply() {
|
if ee.IsReply() {
|
||||||
nevent, _ := nip19.EncodeEvent(ee.Reply().Value(), ee.relays, ee.event.PubKey)
|
nevent, _ := nip19.EncodeEvent(ee.Reply().Value(), ee.relays, ee.event.PubKey)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func renderEmbedded(w http.ResponseWriter, r *http.Request, code string) {
|
|||||||
data.content = mdToHTML(data.content, data.templateId == TelegramInstantView)
|
data.content = mdToHTML(data.content, data.templateId == TelegramInstantView)
|
||||||
} else {
|
} else {
|
||||||
// first we run basicFormatting, which turns URLs into their appropriate HTML tags
|
// first we run basicFormatting, which turns URLs into their appropriate HTML tags
|
||||||
data.content = basicFormatting(html.EscapeString(data.content), true, false)
|
data.content = basicFormatting(html.EscapeString(data.content), true, false, false)
|
||||||
// then we render quotes as HTML, which will also apply basicFormatting to all the internal quotes
|
// then we render quotes as HTML, which will also apply basicFormatting to all the internal quotes
|
||||||
data.content = renderQuotesAsHTML(r.Context(), data.content, data.templateId == TelegramInstantView)
|
data.content = renderQuotesAsHTML(r.Context(), data.content, data.templateId == TelegramInstantView)
|
||||||
// we must do this because inside <blockquotes> we must treat <img>s differently when telegram_instant_view
|
// we must do this because inside <blockquotes> we must treat <img>s differently when telegram_instant_view
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ func renderEvent(w http.ResponseWriter, r *http.Request) {
|
|||||||
data.content = mdToHTML(data.content, data.templateId == TelegramInstantView)
|
data.content = mdToHTML(data.content, data.templateId == TelegramInstantView)
|
||||||
} else {
|
} else {
|
||||||
// first we run basicFormatting, which turns URLs into their appropriate HTML tags
|
// first we run basicFormatting, which turns URLs into their appropriate HTML tags
|
||||||
data.content = basicFormatting(html.EscapeString(data.content), true, false)
|
data.content = basicFormatting(html.EscapeString(data.content), true, false, false)
|
||||||
// then we render quotes as HTML, which will also apply basicFormatting to all the internal quotes
|
// then we render quotes as HTML, which will also apply basicFormatting to all the internal quotes
|
||||||
data.content = renderQuotesAsHTML(r.Context(), data.content, data.templateId == TelegramInstantView)
|
data.content = renderQuotesAsHTML(r.Context(), data.content, data.templateId == TelegramInstantView)
|
||||||
// we must do this because inside <blockquotes> we must treat <img>s differently when telegram_instant_view
|
// we must do this because inside <blockquotes> we must treat <img>s differently when telegram_instant_view
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ func renderProfile(w http.ResponseWriter, r *http.Request, code string) {
|
|||||||
|
|
||||||
Metadata: data.metadata,
|
Metadata: data.metadata,
|
||||||
NormalizedAuthorWebsiteURL: normalizeWebsiteURL(data.metadata.Website),
|
NormalizedAuthorWebsiteURL: normalizeWebsiteURL(data.metadata.Website),
|
||||||
RenderedAuthorAboutText: template.HTML(basicFormatting(html.EscapeString(data.metadata.About), false, false)),
|
RenderedAuthorAboutText: template.HTML(basicFormatting(html.EscapeString(data.metadata.About), false, false, false)),
|
||||||
Npub: data.npub,
|
Npub: data.npub,
|
||||||
Nprofile: data.nprofile,
|
Nprofile: data.nprofile,
|
||||||
AuthorRelays: data.authorRelays,
|
AuthorRelays: data.authorRelays,
|
||||||
|
|||||||
14
utils.go
14
utils.go
@@ -215,7 +215,7 @@ func scheduleEventExpiration(eventId string, ts time.Duration) {
|
|||||||
// Rendering functions
|
// Rendering functions
|
||||||
// ### ### ### ### ### ### ### ### ### ### ###
|
// ### ### ### ### ### ### ### ### ### ### ###
|
||||||
|
|
||||||
func replaceURLsWithTags(input string, imageReplacementTemplate, videoReplacementTemplate string) string {
|
func replaceURLsWithTags(input string, imageReplacementTemplate, videoReplacementTemplate string, skipLinks bool) string {
|
||||||
return urlMatcher.ReplaceAllStringFunc(input, func(match string) string {
|
return urlMatcher.ReplaceAllStringFunc(input, func(match string) string {
|
||||||
switch {
|
switch {
|
||||||
case imageExtensionMatcher.MatchString(match):
|
case imageExtensionMatcher.MatchString(match):
|
||||||
@@ -229,7 +229,11 @@ func replaceURLsWithTags(input string, imageReplacementTemplate, videoReplacemen
|
|||||||
// or markdown !()[...] tags for further processing => ``
|
// or markdown !()[...] tags for further processing => ``
|
||||||
return fmt.Sprintf(videoReplacementTemplate, match)
|
return fmt.Sprintf(videoReplacementTemplate, match)
|
||||||
default:
|
default:
|
||||||
return "<a href=\"" + match + "\">" + match + "</a>"
|
if skipLinks {
|
||||||
|
return match
|
||||||
|
} else {
|
||||||
|
return "<a href=\"" + match + "\">" + match + "</a>"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -313,7 +317,7 @@ func renderQuotesAsHTML(ctx context.Context, input string, usingTelegramInstantV
|
|||||||
|
|
||||||
content := fmt.Sprintf(
|
content := fmt.Sprintf(
|
||||||
`<blockquote class="border-l-05rem border-l-strongpink border-solid"><div class="-ml-4 bg-gradient-to-r from-gray-100 dark:from-zinc-800 to-transparent mr-0 mt-0 mb-4 pl-4 pr-2 py-2">quoting %s </div> %s </blockquote>`, match, event.Content)
|
`<blockquote class="border-l-05rem border-l-strongpink border-solid"><div class="-ml-4 bg-gradient-to-r from-gray-100 dark:from-zinc-800 to-transparent mr-0 mt-0 mb-4 pl-4 pr-2 py-2">quoting %s </div> %s </blockquote>`, match, event.Content)
|
||||||
return basicFormatting(content, false, usingTelegramInstantView)
|
return basicFormatting(content, false, usingTelegramInstantView, false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,7 +341,7 @@ func sanitizeXSS(html string) string {
|
|||||||
return p.Sanitize(html)
|
return p.Sanitize(html)
|
||||||
}
|
}
|
||||||
|
|
||||||
func basicFormatting(input string, skipNostrEventLinks bool, usingTelegramInstantView bool) string {
|
func basicFormatting(input string, skipNostrEventLinks bool, usingTelegramInstantView bool, skipLinks bool) string {
|
||||||
nostrMatcher := nostrEveryMatcher
|
nostrMatcher := nostrEveryMatcher
|
||||||
if skipNostrEventLinks {
|
if skipNostrEventLinks {
|
||||||
nostrMatcher = nostrNpubNprofileMatcher
|
nostrMatcher = nostrNpubNprofileMatcher
|
||||||
@@ -355,7 +359,7 @@ func basicFormatting(input string, skipNostrEventLinks bool, usingTelegramInstan
|
|||||||
|
|
||||||
lines := strings.Split(input, "\n")
|
lines := strings.Split(input, "\n")
|
||||||
for i, line := range lines {
|
for i, line := range lines {
|
||||||
line = replaceURLsWithTags(line, imageReplacementTemplate, videoReplacementTemplate)
|
line = replaceURLsWithTags(line, imageReplacementTemplate, videoReplacementTemplate, skipLinks)
|
||||||
line = replaceNostrURLsWithTags(nostrMatcher, line)
|
line = replaceNostrURLsWithTags(nostrMatcher, line)
|
||||||
lines[i] = line
|
lines[i] = line
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user