For example, in the editor, if you paste a Web site,
are automatically converted to links.
The code found on the stack doesn't know how to use it, so you can look at it.
function replaceURLWithHTMLLinks(text) { var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; return text.replace(exp,"$1"); }
Is it a surveillance keyup to replace it? Hope to get everyone's answer! Thank you!
update:2013-12-09:* * *
Editor is
Reply content:
For example, in the editor, if a URL is pasted, it is automatically converted to a link.
The code found on the stack doesn't know how to use it, so you can look at it.
function replaceURLWithHTMLLinks(text) { var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; return text.replace(exp,"$1"); }
Is it a surveillance keyup to replace it? Hope to get everyone's answer! Thank you!
update:2013-12-09:* * *
Editor is
Event is not recommended keyup
because it does not respond to non-keyboard actions, such as the mouse pasted in a URL. In this case, you need to use onPropertyChange
events to be able to textarea
create actions on the changes in the property values.
In addition, the regular part of the recommendation of the last plus a space to determine, that URL+空格
is, to parse the link form, if the previous match will cause a dead loop.
http://jsfiddle.net/5kmqe/1/
Linkify:function (inputtext) {var replacedtext, replacePattern1, replacePattern2, replacePattern3; var originaltext = Inputtext; URLs starting with HTTP//, https://, file://or ftp://replacePattern1 =/(\b (https?| Ftp|file): \/\/[-a-z0-9+&@#\/%?=~_|!:,.;] *[-a-z0-9+&@#\/%=~_|]) /gi; URLs starting with "www." (without//before it, or it ' d re-link the ones done above). REPLACEPATTERN2 =/(^|[ ^\/F]) (www\.[ -a-z0-9+&@#\/%?=~_|!:,.;] *[-a-z0-9+&@#\/%=~_|]) /gi; Change email addresses to mailto:: links. REPLACEPATTERN3 =/(([a-za-z0-9\-\_\.]) +@[a-za-z\_]+? (\. [A-za-z] {2,6}) +)/gi; If there is hrefs in the original text, let's split//The text up and is work on the parts that don ' t has ur LS yet. var count = Originaltext.match (/0) {var combinedreplacedtext; Keep delimiter when splitting var splitinput = Originaltext.split (/(<\/a>)/g); For(i = 0; i < splitinput.length; i++) {if (Splitinput[i].match (/$1 '). Replace (replacePattern2, ' $1$2 '). Replace (REPLACEPATTERN3, ' $ '); }} Combinedreplacedtext = Splitinput.join ("); return combinedreplacedtext; } else {replacedtext = Inputtext.replace (replacePattern1, ' $ '); Replacedtext = Replacedtext.replace (replacePattern2, ' $1$2 '); Replacedtext = Replacedtext.replace (ReplacePattern3, ' $ $ '); return replacedtext; } },
For a piece of text, you can run it repeatedly.