mirror of
https://github.com/coracle-social/coracle.git
synced 2024-09-20 20:16:43 +00:00
Fix interpolating links when there are multiple of the same url
This commit is contained in:
parent
2325d67700
commit
35a9274be6
@ -1,6 +1,5 @@
|
||||
# Current
|
||||
|
||||
- [ ] Check mention interpolation indexes nevent1qqsx27cspgfcj93kryt2zpzzt5ua60rtucckvcmsrqc949e6t83jaxspzemhxue69uhhyetvv9ujumn0wd68ytnzv9hxg46e8sv
|
||||
- [ ] Show loading/success on zap invoice screen
|
||||
- [ ] Fix iOS/safari/firefox
|
||||
- [ ] Update https://nostr.com/clients/coracle
|
||||
|
@ -1,3 +1,4 @@
|
||||
import {uniq} from 'ramda'
|
||||
import {ellipsize, bytes} from 'hurdak/lib/hurdak'
|
||||
|
||||
export const copyToClipboard = text => {
|
||||
@ -123,9 +124,7 @@ export const renderContent = content => {
|
||||
content = escapeHtml(content)
|
||||
|
||||
// Extract urls
|
||||
for (let url of extractUrls(content)) {
|
||||
const $a = document.createElement('a')
|
||||
|
||||
for (let url of uniq(extractUrls(content))) {
|
||||
// It's common for a period to end a url, trim it off
|
||||
if (url.endsWith('.')) {
|
||||
url = url.slice(0, -1)
|
||||
@ -133,13 +132,16 @@ export const renderContent = content => {
|
||||
|
||||
const href = url.includes('://') ? url : 'https://' + url
|
||||
const display = url.replace(/https?:\/\/(www\.)?/, '')
|
||||
const regex = new RegExp(url, 'g')
|
||||
|
||||
const $a = document.createElement('a')
|
||||
|
||||
$a.href = href
|
||||
$a.target = "_blank"
|
||||
$a.className = "underline"
|
||||
$a.innerText = ellipsize(display, 50)
|
||||
|
||||
content = content.replace(url, $a.outerHTML)
|
||||
content = content.replace(regex, $a.outerHTML)
|
||||
}
|
||||
|
||||
return content.trim()
|
||||
|
Loading…
Reference in New Issue
Block a user