0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 15:23:29 -05:00

Make email addresses into links on paste.

This commit is contained in:
Neil Jenkins 2012-03-08 15:02:33 +11:00
parent 64b8f9affa
commit f8273e7d15

View file

@ -843,7 +843,7 @@
// --- Clean --- // --- Clean ---
var urlRegExp = /\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/i; var linkRegExp = /\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’])|(?:[\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,4}))/i;
var addLinks = function ( frag ) { var addLinks = function ( frag ) {
var doc = frag.ownerDocument, var doc = frag.ownerDocument,
walker = doc.createTreeWalker( frag, SHOW_TEXT, walker = doc.createTreeWalker( frag, SHOW_TEXT,
@ -852,7 +852,7 @@
}, false ), }, false ),
node, parts, i, l, text, parent, next; node, parts, i, l, text, parent, next;
while ( node = walker.nextNode() ) { while ( node = walker.nextNode() ) {
parts = node.data.split( urlRegExp ); parts = node.data.split( linkRegExp );
l = parts.length; l = parts.length;
if ( l > 1 ) { if ( l > 1 ) {
parent = node.parentNode; parent = node.parentNode;
@ -863,7 +863,8 @@
if ( i % 2 ) { if ( i % 2 ) {
node = doc.createElement( 'A' ); node = doc.createElement( 'A' );
node.textContent = text; node.textContent = text;
node.href = /^https?:/.test( text ) ? node.href = /@/.test( text ) ? 'mailto:' + text :
/^https?:/.test( text ) ?
text : 'http://' + text; text : 'http://' + text;
} else { } else {
node = doc.createTextNode( text ); node = doc.createTextNode( text );