diff --git a/imports/NeoChat/Component/Timeline/RichLabel.qml b/imports/NeoChat/Component/Timeline/RichLabel.qml index 5d2149c93..bfa098665 100644 --- a/imports/NeoChat/Component/Timeline/RichLabel.qml +++ b/imports/NeoChat/Component/Timeline/RichLabel.qml @@ -15,7 +15,24 @@ TextEdit { readonly property var hasSpoiler: /data-mx-spoiler/g property bool isEmote: false - property string textMessage: model.display + + /* Turn all links which aren't already in tags into hyperlinks */ + readonly property var linkRegex: /(href=["'])?(\b(https?):\/\/[^\s\<\>\"\'\\]+)/g + property string textMessage: model.display.includes("http") + ? model.display.replace(linkRegex, function() { + if (arguments[1]) { + return arguments[0]; + } else { + var l = arguments[2]; + if ([".", ","].includes(l[l.length-1])) { + var link = l.substring(0, l.length-1); + var leftover = l[l.length-1]; + return "" + link + "" + leftover; + } + return "" + l + ""; + } + }) + : model.display property bool spoilerRevealed: !hasSpoiler.test(textMessage) ListView.onReused: Qt.binding(() => !hasSpoiler.test(textMessage)) diff --git a/imports/NeoChat/Panel/RoomDrawer.qml b/imports/NeoChat/Panel/RoomDrawer.qml index f2a47a8fb..09ec3c18e 100644 --- a/imports/NeoChat/Panel/RoomDrawer.qml +++ b/imports/NeoChat/Panel/RoomDrawer.qml @@ -194,7 +194,7 @@ Kirigami.OverlayDrawer { TextEdit { Layout.fillWidth: true text: room && room.topic ? room.topic.replace(replaceLinks, "$1") : i18n("No Topic") - readonly property var replaceLinks: /\(https:\/\/[^ ]*\)/ + readonly property var replaceLinks: /(https:\/\/[^ ]*)/ textFormat: TextEdit.MarkdownText wrapMode: Text.WordWrap selectByMouse: true