function properlyEncoded(linkdef) {
        return linkdef.replace(/^\s*(.*?)(?:\s+"(.+)")?\s*$/, function (wholematch, link, title) {

            var inQueryString = false;

            // Having `[^\w\d-./]` in there is just a shortcut that lets us skip
            // the most common characters in URLs. Replacing that it with `.` would not change
            // the result, because encodeURI returns those characters unchanged, but it
            // would mean lots of unnecessary replacement calls. Having `[` and `]` in that
            // section as well means we do *not* enocde square brackets. These characters are
            // a strange beast in URLs, but if anything, this causes URLs to be more readable,
            // and we leave it to the browser to make sure that these links are handled without
            // problems.
            link = link.replace(/%(?:[\da-fA-F]{2})|\?|\+|[^-\w\d./[\]]/g, function (match) {
                // Valid percent encoding. Could just return it as is, but we follow RFC3986
                // Section 2.1 which says "For consistency, URI producers and normalizers
                // should use uppercase hexadecimal digits for all percent-encodings."
                // Note that we also handle (illegal) stand-alone percent characters by
                // replacing them with "%25"
                if (match.length === 3 && match.charAt(0) == "%") {
                    return match.toUpperCase();
                }
                switch (match) {
                    case "?":
                        inQueryString = true;
                        return "?";
                        break;

                    // In the query string, a plus and a space are identical -- normalize.
                    // Not strictly necessary, but identical behavior to the previous version
                    // of this function.
                    case "+":
                        if (inQueryString)
                            return "%20";
                        break;
                }
                return encodeURI(match);
            });

            if (title) {
                title = title.trim ? title.trim() : title.replace(/^\s*/, "").replace(/\s*$/, "");
                title = title.replace(/"/g, "quot;").replace(/\(/g, "&#40;").replace(/\)/g, "&#41;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
            }

            return title ? link + ' "' + title + '"' : link;
        });
    }
// sure the URL and the optinal title are "nice".

sure the URL and the optinal title are "nice".
sure the URL and the optinal title are " nice " .
function properlyEncoded(linkdef) {
        return linkdef.replace(/^\s*(.*?)(?:\s+"(.+)")?\s*$/, function (wholematch, link, title) {
            var inQueryString = false;
            link = link.replace(/%(?:[\da-fA-F]{2})|\?|\+|[^-\w\d./[\]]/g, function (match) {
                if (match.length === 3 && match.charAt(0) == "%") {
                    return match.toUpperCase();
                }
                switch (match) {
                    case "?":
                        inQueryString = true;
                        return "?";
                        break;
                    case "+":
                        if (inQueryString)
                            return "%20";
                        break;
                }
                return encodeURI(match);
            });
            if (title) {
                title = title.trim ? title.trim() : title.replace(/^\s*/, "").replace(/\s*$/, "");
                title = title.replace(/"/g, "quot;").replace(/\(/g, "&#40;").replace(/\)/g, "&#41;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
            }
            return title ? link + ' "' + title + '"' : link;
        });
    }
function properlyEncoded ( linkdef ) { return linkdef . replace ( / ^\s*(.*?)(?:\s+"(.+)")?\s*$ / , function ( wholematch , link , title ) { var inQueryString = false ; link = link . replace ( / %(?:[\da-fA-F]{2})|\?|\+|[^-\w\d./[\]] / g , function ( match ) { if ( match . length === 3 && match . charAt ( 0 ) == "%" ) { return match . toUpperCase ( ) ; } switch ( match ) { case "?" : inQueryString = true ; return "?" ; break ; case "+" : if ( inQueryString ) return "%20" ; break ; } return encodeURI ( match ) ; } ) ; if ( title ) { title = title . trim ? title . trim ( ) : title . replace ( / ^\s* / , "" ) . replace ( / \s*$ / , "" ) ; title = title . replace ( / " / g , "quot;" ) . replace ( / \( / g , "&#40;" ) . replace ( / \) / g , "&#41;" ) . replace ( / < / g , "&lt;" ) . replace ( / > / g , "&gt;" ) ; } return title ? link + ' "' + title + '"' : link ; } ) ; }
sure the URL and the optinal title are "nice".
sure the URL and the optinal title are " nice " .
// Having `[^\w\d-./]` in there is just a shortcut that lets us skip
 // the most common characters in URLs. Replacing that it with `.` would not change
 // the result, because encodeURI returns those characters unchanged, but it
 // would mean lots of unnecessary replacement calls. Having `[` and `]` in that
 // section as well means we do *not* enocde square brackets. These characters are
 // a strange beast in URLs, but if anything, this causes URLs to be more readable,
 // and we leave it to the browser to make sure that these links are handled without
 // problems.
 // Valid percent encoding. Could just return it as is, but we follow RFC3986
 // Section 2.1 which says "For consistency, URI producers and normalizers
 // should use uppercase hexadecimal digits for all percent-encodings."
 // Note that we also handle (illegal) stand-alone percent characters by
 // replacing them with "%25"
 // In the query string, a plus and a space are identical -- normalize.
 // Not strictly necessary, but identical behavior to the previous version
 // of this function.
