diff --git a/linkify.js b/linkify.js
index 4d8013c..6512dac 100644
--- a/linkify.js
+++ b/linkify.js
@@ -8,7 +8,7 @@
*
* Usage: See demonstration page: linkify.html
*/
-function linkify(text) {
+function linkify(text, provided_target) {
/* Here is a commented version of the regex (in PHP string format):
$url_pattern = '/# Rev:20100913_0900 github.com\/jmrware\/LinkifyURL
# Match http & ftp URL that is not already linkified.
@@ -51,9 +51,15 @@ function linkify(text) {
) # End $14. Other non-delimited URL.
/imx';
*/
- var url_pattern = /(\()((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]+)(\))|(\[)((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]+)(\])|(\{)((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]+)(\})|(<|&(?:lt|#60|#x3c);)((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]+)(>|&(?:gt|#62|#x3e);)|((?:^|[^=\s'"\]])\s*['"]?|[^=\s]\s+)(\b(?:ht|f)tps?:\/\/[a-z0-9\-._~!$'()*+,;=:\/?#[\]@%]+(?:(?!&(?:gt|#0*62|#x0*3e);|&(?:amp|apos|quot|#0*3[49]|#x0*2[27]);[.!&',:?;]?(?:[^a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]|$))&[a-z0-9\-._~!$'()*+,;=:\/?#[\]@%]*)*[a-z0-9\-_~$()*+=\/#[\]@%])/img;
- var url_replace = '$1$4$7$10$13$2$5$8$11$14$3$6$9$12';
- return text.replace(url_pattern, url_replace);
+ var target = '_self';
+ if (provided_target) {
+ target = provided_target;
+ }
+ var url_pattern = /(\()((?:(?:ht|f)tps?:\/\/|www\.)[a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]+)(\))|(\[)((?:(?:ht|f)tps?:\/\/|www\.)[a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]+)(\])|(\{)((?:(?:ht|f)tps?:\/\/|www\.)[a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]+)(\})|(<|&(?:lt|#60|#x3c);)((?:(?:ht|f)tps?:\/\/|www\.)[a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]+)(>|&(?:gt|#62|#x3e);)|((?:^|[^=\s'"\]])\s*['"]?|[^=\s]\s+)(\b(?:(?:ht|f)tps?:\/\/|www\.)[a-z0-9\-._~!$'()*+,;=:\/?#[\]@%]+(?:(?!&(?:gt|#0*62|#x0*3e);|&(?:amp|apos|quot|#0*3[49]|#x0*2[27]);[.!&',:?;]?(?:[^a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]|$))&[a-z0-9\-._~!$'()*+,;=:\/?#[\]@%]*)*[a-z0-9\-_~$()*+=\/#[\]@%])/img;
+ var url_replace = '$1$4$7$10$13$2$5$8$11$14$3$6$9$12';
+ var output = text.replace(url_pattern, url_replace);
+ output = output.replace(/href="www\./img, 'href="http://www.');
+ return output;
}
function linkify_html(text) {
text = text.replace(/'/g, '''); // IE does not handle ' entity!