Skip to content

Commit 4819487

Browse files
committed
fixing URI.withinString to accept optional start-of-URI regular expression - closing #115
1 parent 9f04605 commit 4819487

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ URI.js is published under the [MIT license](http://www.opensource.org/licenses/m
233233
* 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))
234234
* 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))
235235
* 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))
236+
* 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))
236237

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

docs.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,17 @@ <h3 id="static-withinString">URI.withinString()</h3>
12891289
&lt;img src=&quot;http://example.org/image.png&quot; alt=&quot;&quot;&gt; is HTML,
12901290
&lt;a href='http://example.org/target.html'&gt; is HTML&lt;/a&gt;,
12911291
&lt;a href=http://example.org/target.html&gt; is HTML, too&lt;/a&gt;
1292+
*/
1293+
1294+
// custom URI beginning pattern
1295+
source = "That example.com/ is just a domain";
1296+
result = URI.withinString(source, decorate, {
1297+
// "scheme://" or "www." or "domain.tld/"
1298+
start: /\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.|[a-z]+\.[a-z]{2,4}\/)/gi
1299+
});
1300+
1301+
/* result is:
1302+
That <strong>&lt;code&gt;example.com/&lt;/code&gt;</strong> is just a domain
12921303
*/</pre>
12931304

12941305
<h3 id="static-iso8859">URI.iso8859()</h3>

src/URI.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,11 @@ URI.ip6_expression = /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-
186186
// * http://rodneyrehm.de/t/url-regex.html
187187
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;
188188
URI.findUri = {
189+
// valid "scheme://" or "www."
189190
start: /\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,
191+
// everything up to the next whitespace
190192
end: /[\s\r\n]|$/,
193+
// trim trailing punctuation captured by end RegExp
191194
trim: /[`!()\[\]{};:'".,<>?«»]+$/
192195
};
193196
// http://www.iana.org/assignments/uri-schemes.html

0 commit comments

Comments
 (0)