Skip to content
Browse files

Merge pull request #164 from eviltrout/apostrophe

FIX: Handle URLs with apostrophes in them.
  • Loading branch information...
2 parents 9b24007 + 527f2c6 commit 2a3870865295a19b38a553c3cb2a8f30b29d3635 @evilstreak committed
Showing with 20 additions and 2 deletions.
  1. +11 −2 src/dialects/gruber.js
  2. +8 −0 test/features/links/apostrophe.json
  3. +1 −0 test/features/links/apostrophe.text
View
13 src/dialects/gruber.js
@@ -8,6 +8,9 @@ define(['../markdown_helpers', './dialect_helpers', '../parser'], function (Mark
isEmpty = MarkdownHelpers.isEmpty,
inline_until_char = DialectHelpers.inline_until_char;
+ // A robust regexp for matching URLs. Thakns: https://gist.github.com/dperini/729294
+ var urlRegexp = /(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?/i.source;
+
/**
* Gruber dialect
*
@@ -558,7 +561,7 @@ define(['../markdown_helpers', './dialect_helpers', '../parser'], function (Mark
//
// First attempt to use a strong URL regexp to catch things like parentheses. If it misses, use the
// old one.
- var m = text.match( /^!\[(.*?)][ \t]*\(((?:https?:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.])(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\([^\s()<>]+\)|[^`!()\[\]{};:'".,<>?«»“”‘’\s]))\)([ \t])*(["'].*["'])?/ ) ||
+ var m = text.match(new RegExp("^!\\[(.*?)][ \\t]*\\((" + urlRegexp + ")\\)([ \\t])*([\"'].*[\"'])?")) ||
text.match( /^!\[(.*?)\][ \t]*\([ \t]*([^")]*?)(?:[ \t]+(["'])(.*?)\3)?[ \t]*\)/ );
if ( m ) {
@@ -660,10 +663,16 @@ define(['../markdown_helpers', './dialect_helpers', '../parser'], function (Mark
return [ consumed, link ];
}
+ m = text.match(new RegExp("^\\((" + urlRegexp + ")\\)"));
+ if (m && m[1]) {
+ consumed += m[0].length;
+ link = ["link", {href: m[1]}].concat(children);
+ return [consumed, link];
+ }
+
// [Alt text][id]
// [Alt text] [id]
m = text.match( /^\s*\[(.*?)\]/ );
-
if ( m ) {
consumed += m[ 0 ].length;
View
8 test/features/links/apostrophe.json
@@ -0,0 +1,8 @@
+["html",
+ ["p",
+ ["a",
+ { "href" : "http://wiki.postgresql.org/wiki/What's_new_in_PostgreSQL_9.3" },
+ "Postgres 9.3"
+ ]
+ ]
+]
View
1 test/features/links/apostrophe.text
@@ -0,0 +1 @@
+[Postgres 9.3](http://wiki.postgresql.org/wiki/What's_new_in_PostgreSQL_9.3)

0 comments on commit 2a38708

Please sign in to comment.
Something went wrong with that request. Please try again.