Skip to content

Commit

Permalink
fixing URI.withinString to accept optional start-of-URI regular expre…
Browse files Browse the repository at this point in the history
…ssion - closing #115
  • Loading branch information
rodneyrehm committed Jan 22, 2014
1 parent 9f04605 commit 4819487
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -233,6 +233,7 @@ URI.js is published under the [MIT license](http://www.opensource.org/licenses/m
* fixing `URI.protocol_expression` to properly accept `.` in compliance with [RFC 3986 - Scheme](http://tools.ietf.org/html/rfc3986#section-3.1) - ([Issue #132](https://github.com/medialize/URI.js/issues/132))
* fixing [`URI.withinString()`](http://medialize.github.com/URI.js/docs.html#static-withinString) to not use backtracking prone regular expression `URI.find_uri_expression` anymore - ([Issue #131](https://github.com/medialize/URI.js/issues/131))
* fixing [`URI.withinString()`](http://medialize.github.com/URI.js/docs.html#static-withinString) to accept options `ignore` and `ignoreHtml` to allow better control over which detected URLs get handled - ([Issue #117](https://github.com/medialize/URI.js/issues/117))
* fixing [`URI.withinString()`](http://medialize.github.com/URI.js/docs.html#static-withinString) to accept option `start` to specify the RegExp used for finding the beginning of an URL (defaults to `/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi`) - ([Issue #115](https://github.com/medialize/URI.js/issues/115))

### 1.11.2 (August 14th 2013) ###

Expand Down
11 changes: 11 additions & 0 deletions docs.html
Expand Up @@ -1289,6 +1289,17 @@ <h3 id="static-withinString">URI.withinString()</h3>
&lt;img src=&quot;http://example.org/image.png&quot; alt=&quot;&quot;&gt; is HTML,
&lt;a href='http://example.org/target.html'&gt; is HTML&lt;/a&gt;,
&lt;a href=http://example.org/target.html&gt; is HTML, too&lt;/a&gt;
*/

// custom URI beginning pattern
source = "That example.com/ is just a domain";
result = URI.withinString(source, decorate, {
// "scheme://" or "www." or "domain.tld/"
start: /\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.|[a-z]+\.[a-z]{2,4}\/)/gi
});

/* result is:
That <strong>&lt;code&gt;example.com/&lt;/code&gt;</strong> is just a domain
*/</pre>

<h3 id="static-iso8859">URI.iso8859()</h3>
Expand Down
3 changes: 3 additions & 0 deletions src/URI.js
Expand Up @@ -186,8 +186,11 @@ URI.ip6_expression = /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-
// * http://rodneyrehm.de/t/url-regex.html
URI.find_uri_expression = /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/ig;
URI.findUri = {
// valid "scheme://" or "www."
start: /\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,
// everything up to the next whitespace
end: /[\s\r\n]|$/,
// trim trailing punctuation captured by end RegExp
trim: /[`!()\[\]{};:'".,<>?«»“”„‘’]+$/
};
// http://www.iana.org/assignments/uri-schemes.html
Expand Down

0 comments on commit 4819487

Please sign in to comment.