feat:聊天页面代码移植
This commit is contained in:
1 parent
6d26839aee
commit
3aaa1cb425
113 files changed
+7726
-166
No files matched your search
@@ -0,0 +1,23 @@
|
||||
|
||||
// 使用正则表达式匹配更广泛的URL格式(此正则由deepseek生成)
|
||||
const regex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]|\bwww\.[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
|
||||
|
||||
let containUrl = (content) => {
|
||||
return regex.test(content)
|
||||
}
|
||||
|
||||
|
||||
let replaceURLWithHTMLLinks = (content, color) => {
|
||||
return content.replace(regex, (url) => {
|
||||
// 如果URL不以http(s)://开头,则添加http://前缀
|
||||
if (!url.startsWith("http")) {
|
||||
url = "http://" + url;
|
||||
}
|
||||
return `<a href="${url}" target="_blank" style="color: ${color};text-decoration: underline;">${url}</a>`;
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
containUrl,
|
||||
replaceURLWithHTMLLinks
|
||||
}
|
||||
Reference in new issue
Block a user