11
Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.
Tóm lại, tôi có một trang web được thực hiện theo biên tập viên Wix.com và mã hóa đã được thực hiện vài tháng trước. Tôi đã thiết lập một hộp bình luận tùy chỉnh, để người dùng có thể đăng bình luận của họ và đọc những người khác.
Bây giờ, điều này là, "đầu vào nhận xét" lấy văn bản đơn giản và bất cứ khi nào một liên kết được đăng, nó được hiển thị dưới dạng văn bản thuần túy, không màu, không có khả năng nhấp chuột.
Tôi muốn một mã 'đọc' danh sách các bình luận và chuyển đổi mọi văn bản bắt đầu bằng 'https' hoặc 'http' hoặc 'www' ... màu cam và có thể nhấp [mở trong một tab mới]
Bất kỳ giải pháp xin vui lòng?
Cảm ơn !
Tôi đã thử nhiều thứ như:
$w['#text95'].html =
[/[[|][^\s]+[\w]]/g, '$1'].replace;
Text95 = các nhận xét được hiển thị [nó là một văn bản lặp lại cho bao nhiêu bình luận như có]
$1']; //URLs starting with "www." [without // before it, or it'd re-link the ones done above]. replacePattern2 = /[^|[^\/]][www\.[\S]+[\b|$]]/gim; replacedText = replacedText.replace[replacePattern2, '$1$2']; //Change email addresses to mailto:: links. replacePattern3 = /[[[a-zA-Z0-9\-\_\.]]+@[a-zA-Z\_]+?[\.[a-zA-Z]{2,6}]+]/gim; replacedText = replacedText.replace[replacePattern3, '$1']; return replacedText; }
Gọi nó với:
$w['#text95'].innerHTML = linkify[$w['#text95'].html];
stackoverflow.com is very clumsy and this developer.mozilla.org is not much better. This one apple.com is nice but www can be removed.
Văn bản liên kết sau đó hiển thị như sau:
Liên kết vụng về này stackoverflow.com rất vụng về và nhà phát triển này.mozilla.org không tốt hơn nhiều. Một apple.com này rất tốt nhưng www có thể được gỡ bỏ.
$1']; //URLs starting with "www." [without // before it, or it'd re-link the ones done above]. replacePattern2 = /[^|[^\/]][www\.[\S]+[\b|$]]/gim; replacedText = replacedText.replace[replacePattern2, '$1$2']; //Change email addresses to mailto:: links. replacePattern3 = /[[[a-zA-Z0-9\-\_\.]]+@[a-zA-Z\_]+?[\.[a-zA-Z]{2,6}]+]/gim; replacedText = replacedText.replace[replacePattern3, '$1']; return replacedText; } 5 là gì hoặc nếu bạn thực sự có thể gán HTML như vậy, nhưng tôi đoán đây là jQuery vì
function linkify[inputText] {
var replacedText, replacePattern1, replacePattern2, replacePattern3;
//URLs starting with //, //, or ftp://
replacePattern1 = /[\b[https?|ftp]:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]]/gim;
replacedText = inputText.replace[replacePattern1, '$1'];
//URLs starting with "www." [without // before it, or it'd re-link the ones done above].
replacePattern2 = /[^|[^\/]][www\.[\S]+[\b|$]]/gim;
replacedText = replacedText.replace[replacePattern2, '$1$2'];
//Change email addresses to mailto:: links.
replacePattern3 = /[[[a-zA-Z0-9\-\_\.]]+@[a-zA-Z\_]+?[\.[a-zA-Z]{2,6}]+]/gim;
replacedText = replacedText.replace[replacePattern3, '$1'];
return replacedText;
}
6 thường đề cập đến đối tượng jQuery.Thử của bạn đã gần, nó sẽ là ..
function linkify[inputText] {
var replacedText, replacePattern1, replacePattern2, replacePattern3;
//URLs starting with //, //, or ftp://
replacePattern1 = /[\b[https?|ftp]:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]]/gim;
replacedText = inputText.replace[replacePattern1, '$1'];
//URLs starting with "www." [without // before it, or it'd re-link the ones done above].
replacePattern2 = /[^|[^\/]][www\.[\S]+[\b|$]]/gim;
replacedText = replacedText.replace[replacePattern2, '$1$2'];
//Change email addresses to mailto:: links.
replacePattern3 = /[[[a-zA-Z0-9\-\_\.]]+@[a-zA-Z\_]+?[\.[a-zA-Z]{2,6}]+]/gim;
replacedText = replacedText.replace[replacePattern3, '$1'];
return replacedText;
}
7thử nó..
$['#text95'].html[$['#text95'].html[].replace[/[[|][^\s]+[\w]]/g, '$1']];
stuff and stuff and //ww.stuff.com stuff
Đã trả lời ngày 3 tháng 4 năm 2018 lúc 16:32Apr 3, 2018 at 16:32
' + linkText + '']; } else { aLink.push['']; } } else { aLink.push['' + linkText + '']; } text = text.split[linksFound[i]].map[item => { return aLink[i].includes['iframe'] ? item.trim[] : item }].join[aLink[i]]; } return text; } else { return input; } };
Usage:
const text = 'Hello. This is a link //www.google.com and this is youtube video //www.youtube.com/watch?v=O-hnSlicxV4';
convertLinks[text];
Đã trả lời ngày 8 tháng 4 năm 2020 lúc 13:11Apr 8, 2020 at 13:11
$1']; //URLs starting with "www." [without // before it, or it'd re-link the ones done above]. replacePattern2 = /[^|[^\/]][www\.[\S]+[\b|$]]/gim; replacedText = replacedText.replace[replacePattern2, '$1$2']; //Change email addresses to mailto:: links. replacePattern3 = /[[[a-zA-Z0-9\-\_\.]]+@[a-zA-Z\_]+?[\.[a-zA-Z]{2,6}]+]/gim; replacedText = replacedText.replace[replacePattern3, '$1']; return replacedText; } 8 hoặc
function linkify[inputText] {
var replacedText, replacePattern1, replacePattern2, replacePattern3;
//URLs starting with //, //, or ftp://
replacePattern1 = /[\b[https?|ftp]:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]]/gim;
replacedText = inputText.replace[replacePattern1, '$1'];
//URLs starting with "www." [without // before it, or it'd re-link the ones done above].
replacePattern2 = /[^|[^\/]][www\.[\S]+[\b|$]]/gim;
replacedText = replacedText.replace[replacePattern2, '$1$2'];
//Change email addresses to mailto:: links.
replacePattern3 = /[[[a-zA-Z0-9\-\_\.]]+@[a-zA-Z\_]+?[\.[a-zA-Z]{2,6}]+]/gim;
replacedText = replacedText.replace[replacePattern3, '$1'];
return replacedText;
}
9, ví dụ $w['#text95'].innerHTML = linkify[$w['#text95'].html];
0Tôi đã lấy được những điều sau đây từ mã của anh ấy, khắc phục các vấn đề này và bỏ qua các công cụ nhúng video mà tôi không muốn:
function linkify[inputText] {
var replacedText, replacePattern1, replacePattern2, replacePattern3;
//URLs starting with //, //, or ftp://
replacePattern1 = /[\b[https?|ftp]:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]]/gim;
replacedText = inputText.replace[replacePattern1, '$1'];
//URLs starting with "www." [without // before it, or it'd re-link the ones done above].
replacePattern2 = /[^|[^\/]][www\.[\S]+[\b|$]]/gim;
replacedText = replacedText.replace[replacePattern2, '$1$2'];
//Change email addresses to mailto:: links.
replacePattern3 = /[[[a-zA-Z0-9\-\_\.]]+@[a-zA-Z\_]+?[\.[a-zA-Z]{2,6}]+]/gim;
replacedText = replacedText.replace[replacePattern3, '$1'];
return replacedText;
}
0Để giải thích biểu thức chính quy chính:
1 nhìn phía sau [trước] liên kết để xác định nơi liên kết bắt đầu, đó là bất kỳ khoảng trắng nào hoặc đầu của chuỗi$w['#text95'].innerHTML = linkify[$w['#text95'].html];
2 khớp với sự khởi đầu của một liên kết - một mẫu như xxx.x hoặc thậm chí xxx: //xxx.xxxx.x or even xxx://xxx.x$w['#text95'].innerHTML = linkify[$w['#text95'].html];
3 Một sự kết hợp của một hoặc nhiều chữ cái, dấu gạch nối, dấu chấm hoặc dấu gạch chéo$w['#text95'].innerHTML = linkify[$w['#text95'].html];
4 theo sau ngay lập tức bởi một dấu chấm$w['#text95'].innerHTML = linkify[$w['#text95'].html];
5 theo sau ngay sau một lá thư khác$w['#text95'].innerHTML = linkify[$w['#text95'].html];
6 khớp với phần còn lại của liên kết.$w['#text95'].innerHTML = linkify[$w['#text95'].html];
7 nhìn về phía trước [sau] liên kết để xác định nơi liên kết kết thúc$w['#text95'].innerHTML = linkify[$w['#text95'].html];
8 Lookahead tích cực$w['#text95'].innerHTML = linkify[$w['#text95'].html];
9 Liên kết được kết thúc bằng bất kỳ khoảng trắng nào hoặc vào cuối chuỗi$w['#text95'].innerHTML = linkify[$w['#text95'].html];
0 Trừ khi không gian trắng hoặc cuối chuỗi ngay trước một trong bảy dấu chấm câu này, trong trường hợp dấu chấm câu này kết thúc liên kết.const convertLinks = [ input ] => { let text = input; const linksFound = text.match[ /[?:www|https?][^\s]+/g ]; const aLink = []; if [ linksFound != null ] { for [ let i=0; i { return aLink[i].includes['iframe'] ? item.trim[] : item } ].join[ aLink[i] ]; } return text; } else { return input; } }
Về mặt kỹ thuật, tôi cũng nên cho phép các chữ số khi khớp với sự bắt đầu của một liên kết, để W3.org sẽ được liên kết, ví dụ. Tuy nhiên, điều này có thể liên kết các số thập phân như 2.25, vì vậy tôi đã chọn không làm như vậy.w3.org would be linkified, for example. However, this could linkify decimal numbers such as 2.25, so I have opted not to do so.
Đây là một đoạn trích nếu bạn muốn thử một số khối văn bản khác nhau để xem cách chúng được liên kết:
function linkify[inputText] {
var replacedText, replacePattern1, replacePattern2, replacePattern3;
//URLs starting with //, //, or ftp://
replacePattern1 = /[\b[https?|ftp]:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]]/gim;
replacedText = inputText.replace[replacePattern1, '$1'];
//URLs starting with "www." [without // before it, or it'd re-link the ones done above].
replacePattern2 = /[^|[^\/]][www\.[\S]+[\b|$]]/gim;
replacedText = replacedText.replace[replacePattern2, '$1$2'];
//Change email addresses to mailto:: links.
replacePattern3 = /[[[a-zA-Z0-9\-\_\.]]+@[a-zA-Z\_]+?[\.[a-zA-Z]{2,6}]+]/gim;
replacedText = replacedText.replace[replacePattern3, '$1'];
return replacedText;
}
1function linkify[inputText] {
var replacedText, replacePattern1, replacePattern2, replacePattern3;
//URLs starting with //, //, or ftp://
replacePattern1 = /[\b[https?|ftp]:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]]/gim;
replacedText = inputText.replace[replacePattern1, '$1'];
//URLs starting with "www." [without // before it, or it'd re-link the ones done above].
replacePattern2 = /[^|[^\/]][www\.[\S]+[\b|$]]/gim;
replacedText = replacedText.replace[replacePattern2, '$1$2'];
//Change email addresses to mailto:: links.
replacePattern3 = /[[[a-zA-Z0-9\-\_\.]]+@[a-zA-Z\_]+?[\.[a-zA-Z]{2,6}]+]/gim;
replacedText = replacedText.replace[replacePattern3, '$1'];
return replacedText;
}
2Đã trả lời ngày 4 tháng 4 lúc 8:27Apr 4 at 8:27
$1']; //URLs starting with "www." [without // before it, or it'd re-link the ones done above]. replacePattern2 = /[^|[^\/]][www\.[\S]+[\b|$]]/gim; replacedText = replacedText.replace[replacePattern2, '$1$2']; //Change email addresses to mailto:: links. replacePattern3 = /[[[a-zA-Z0-9\-\_\.]]+@[a-zA-Z\_]+?[\.[a-zA-Z]{2,6}]+]/gim; replacedText = replacedText.replace[replacePattern3, '$1']; return replacedText; } 3
Tôi không chắc
function linkify[inputText] {
var replacedText, replacePattern1, replacePattern2, replacePattern3;
//URLs starting with //, //, or ftp://
replacePattern1 = /[\b[https?|ftp]:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]]/gim;
replacedText = inputText.replace[replacePattern1, '$1'];
//URLs starting with "www." [without // before it, or it'd re-link the ones done above].
replacePattern2 = /[^|[^\/]][www\.[\S]+[\b|$]]/gim;
replacedText = replacedText.replace[replacePattern2, '$1$2'];
//Change email addresses to mailto:: links.
replacePattern3 = /[[[a-zA-Z0-9\-\_\.]]+@[a-zA-Z\_]+?[\.[a-zA-Z]{2,6}]+]/gim;
replacedText = replacedText.replace[replacePattern3, '$1'];
return replacedText;
}
5 là gì hoặc nếu bạn thực sự có thể gán HTML như vậy, nhưng tôi đoán đây là jQuery vì function linkify[inputText] {
var replacedText, replacePattern1, replacePattern2, replacePattern3;
//URLs starting with //, //, or ftp://
replacePattern1 = /[\b[https?|ftp]:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]]/gim;
replacedText = inputText.replace[replacePattern1, '$1'];
//URLs starting with "www." [without // before it, or it'd re-link the ones done above].
replacePattern2 = /[^|[^\/]][www\.[\S]+[\b|$]]/gim;
replacedText = replacedText.replace[replacePattern2, '$1$2'];
//Change email addresses to mailto:: links.
replacePattern3 = /[[[a-zA-Z0-9\-\_\.]]+@[a-zA-Z\_]+?[\.[a-zA-Z]{2,6}]+]/gim;
replacedText = replacedText.replace[replacePattern3, '$1'];
return replacedText;
}
6 thường đề cập đến đối tượng jQuery.function linkify[inputText] {
var replacedText, replacePattern1, replacePattern2, replacePattern3;
//URLs starting with //, //, or ftp://
replacePattern1 = /[\b[https?|ftp]:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]]/gim;
replacedText = inputText.replace[replacePattern1, '$1'];
//URLs starting with "www." [without // before it, or it'd re-link the ones done above].
replacePattern2 = /[^|[^\/]][www\.[\S]+[\b|$]]/gim;
replacedText = replacedText.replace[replacePattern2, '$1$2'];
//Change email addresses to mailto:: links.
replacePattern3 = /[[[a-zA-Z0-9\-\_\.]]+@[a-zA-Z\_]+?[\.[a-zA-Z]{2,6}]+]/gim;
replacedText = replacedText.replace[replacePattern3, '$1'];
return replacedText;
}
4Thử của bạn đã gần, nó sẽ là ..Oct 12, 2021 at 12:33