dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 7b3add5cbda2b83b44935f7854707aad3647035a
parent 56e237ca206be567982e084d56754727a1a951d8
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu, 19 Jan 2023 00:07:10 -0800

only replace link in text outside of a quote

Diffstat:
Mpkg/web/handlers/api/v1/topBarHandler.go | 16+++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/pkg/web/handlers/api/v1/topBarHandler.go b/pkg/web/handlers/api/v1/topBarHandler.go @@ -787,7 +787,19 @@ func makeHtmlLink(label, link string) string { return fmt.Sprintf(`<a href="%s" rel="noopener noreferrer" target="_blank">%s</a>`, link, label) } +func splitQuote(in string) (string, string) { + const quotePrefix = `<p>“[` + const quoteSuffix = `” ` + idx := strings.Index(in, quoteSuffix) + if idx == -1 || !strings.HasPrefix(in, quotePrefix) { + return "", in + } + return in[:idx], in[idx:] +} + func convertLinks(in string) string { + quote, rest := splitQuote(in) + libredditURLs := []string{ "http://spjmllawtheisznfs7uryhxumin26ssv2draj7oope3ok3wuhy43eoyd.onion", "http://fwhhsbrbltmrct5hshrnqlqygqvcgmnek3cnka55zj4y7nuus5muwyyd.onion", @@ -827,7 +839,7 @@ func convertLinks(in string) string { {"http://whonix.onion", config.WhonixOnion}, } - return linkRgx.ReplaceAllStringFunc(in, func(link string) string { + newRest := linkRgx.ReplaceAllStringFunc(rest, func(link string) string { // Handle reddit links if strings.HasPrefix(link, "https://www.reddit.com/") { old := strings.Replace(link, "https://www.reddit.com/", "https://old.reddit.com/", 1) @@ -960,6 +972,8 @@ func convertLinks(in string) string { } return makeHtmlLink(link, link) }) + + return quote + newRest } func extractPGPMessage(html string) (out string) {