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 {
|
||||
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)
|
||||
if ee.IsReply() {
|
||||
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)
|
||||
} else {
|
||||
// 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
|
||||
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
|
||||
|
||||
@@ -255,7 +255,7 @@ func renderEvent(w http.ResponseWriter, r *http.Request) {
|
||||
data.content = mdToHTML(data.content, data.templateId == TelegramInstantView)
|
||||
} else {
|
||||
// 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
|
||||
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
|
||||
|
||||
@@ -76,7 +76,7 @@ func renderProfile(w http.ResponseWriter, r *http.Request, code string) {
|
||||
|
||||
Metadata: data.metadata,
|
||||
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,
|
||||
Nprofile: data.nprofile,
|
||||
AuthorRelays: data.authorRelays,
|
||||
|
||||
14
utils.go
14
utils.go
@@ -215,7 +215,7 @@ func scheduleEventExpiration(eventId string, ts time.Duration) {
|
||||
// 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 {
|
||||
switch {
|
||||
case imageExtensionMatcher.MatchString(match):
|
||||
@@ -229,7 +229,11 @@ func replaceURLsWithTags(input string, imageReplacementTemplate, videoReplacemen
|
||||
// or markdown !()[...] tags for further processing => ``
|
||||
return fmt.Sprintf(videoReplacementTemplate, match)
|
||||
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(
|
||||
`<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)
|
||||
}
|
||||
|
||||
func basicFormatting(input string, skipNostrEventLinks bool, usingTelegramInstantView bool) string {
|
||||
func basicFormatting(input string, skipNostrEventLinks bool, usingTelegramInstantView bool, skipLinks bool) string {
|
||||
nostrMatcher := nostrEveryMatcher
|
||||
if skipNostrEventLinks {
|
||||
nostrMatcher = nostrNpubNprofileMatcher
|
||||
@@ -355,7 +359,7 @@ func basicFormatting(input string, skipNostrEventLinks bool, usingTelegramInstan
|
||||
|
||||
lines := strings.Split(input, "\n")
|
||||
for i, line := range lines {
|
||||
line = replaceURLsWithTags(line, imageReplacementTemplate, videoReplacementTemplate)
|
||||
line = replaceURLsWithTags(line, imageReplacementTemplate, videoReplacementTemplate, skipLinks)
|
||||
line = replaceNostrURLsWithTags(nostrMatcher, line)
|
||||
lines[i] = line
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user