Only linkify text if inline URLs are enabled
This commit is contained in:
parent
ebe3fcc33c
commit
e08f23ba65
@ -147,11 +147,15 @@ func (msg *FileMessage) CalculateBuffer(prefs config.UserPreferences, width int,
|
|||||||
|
|
||||||
if prefs.BareMessageView || prefs.DisableImages || len(msg.imageData) == 0 {
|
if prefs.BareMessageView || prefs.DisableImages || len(msg.imageData) == 0 {
|
||||||
url := msg.matrix.GetDownloadURL(msg.URL)
|
url := msg.matrix.GetDownloadURL(msg.URL)
|
||||||
|
var urlTString tstring.TString
|
||||||
|
if prefs.InlineURLs {
|
||||||
|
urlTString = tstring.NewStyleTString(url, tcell.StyleDefault.Hyperlink(url, msg.eventID.String()))
|
||||||
|
} else {
|
||||||
|
urlTString = tstring.NewTString(url)
|
||||||
|
}
|
||||||
text := tstring.NewTString(msg.Body).
|
text := tstring.NewTString(msg.Body).
|
||||||
Append(": ").
|
Append(": ").
|
||||||
AppendTString(tstring.NewStyleTString(
|
AppendTString(urlTString)
|
||||||
url,
|
|
||||||
tcell.StyleDefault.Hyperlink(url, msg.eventID.String())))
|
|
||||||
msg.buffer = calculateBufferWithText(prefs, text, width, uiMsg)
|
msg.buffer = calculateBufferWithText(prefs, text, width, uiMsg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -383,10 +383,13 @@ func (parser *htmlParser) tagNodeToEntity(node *html.Node) Entity {
|
|||||||
var spaces = regexp.MustCompile("\\s+")
|
var spaces = regexp.MustCompile("\\s+")
|
||||||
var links = regexp.MustCompile(`https?://\S+`)
|
var links = regexp.MustCompile(`https?://\S+`)
|
||||||
|
|
||||||
func TextToEntity(text string, eventID id.EventID) Entity {
|
func TextToEntity(text string, eventID id.EventID, linkify bool) Entity {
|
||||||
if len(text) == 0 {
|
if len(text) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if !linkify {
|
||||||
|
return NewTextEntity(text)
|
||||||
|
}
|
||||||
indices := links.FindAllStringIndex(text, -1)
|
indices := links.FindAllStringIndex(text, -1)
|
||||||
if len(indices) == 0 {
|
if len(indices) == 0 {
|
||||||
return NewTextEntity(text)
|
return NewTextEntity(text)
|
||||||
@ -418,7 +421,7 @@ func (parser *htmlParser) singleNodeToEntity(node *html.Node) Entity {
|
|||||||
node.Data = strings.ReplaceAll(node.Data, "\n", "")
|
node.Data = strings.ReplaceAll(node.Data, "\n", "")
|
||||||
node.Data = spaces.ReplaceAllLiteralString(node.Data, " ")
|
node.Data = spaces.ReplaceAllLiteralString(node.Data, " ")
|
||||||
}
|
}
|
||||||
return TextToEntity(node.Data, parser.evt.ID)
|
return TextToEntity(node.Data, parser.evt.ID, parser.prefs.InlineURLs)
|
||||||
case html.ElementNode:
|
case html.ElementNode:
|
||||||
parsed := parser.tagNodeToEntity(node)
|
parsed := parser.tagNodeToEntity(node)
|
||||||
if parsed != nil && !parsed.IsBlock() && parsed.IsEmpty() {
|
if parsed != nil && !parsed.IsBlock() && parsed.IsEmpty() {
|
||||||
|
@ -208,7 +208,7 @@ func ParseMessage(matrix ifc.MatrixContainer, room *rooms.Room, evt *muksevt.Eve
|
|||||||
return NewHTMLMessage(evt, displayname, html.Parse(matrix.Preferences(), room, content, evt, displayname))
|
return NewHTMLMessage(evt, displayname, html.Parse(matrix.Preferences(), room, content, evt, displayname))
|
||||||
}
|
}
|
||||||
content.Body = strings.Replace(content.Body, "\t", " ", -1)
|
content.Body = strings.Replace(content.Body, "\t", " ", -1)
|
||||||
return NewHTMLMessage(evt, displayname, html.TextToEntity(content.Body, evt.ID))
|
return NewHTMLMessage(evt, displayname, html.TextToEntity(content.Body, evt.ID, matrix.Preferences().InlineURLs))
|
||||||
case event.MsgImage, event.MsgVideo, event.MsgAudio, event.MsgFile:
|
case event.MsgImage, event.MsgVideo, event.MsgAudio, event.MsgFile:
|
||||||
msg := NewFileMessage(matrix, evt, displayname)
|
msg := NewFileMessage(matrix, evt, displayname)
|
||||||
if !matrix.Preferences().DisableDownloads {
|
if !matrix.Preferences().DisableDownloads {
|
||||||
|
Loading…
Reference in New Issue
Block a user