Fix incorrect linking of URLs without trailing punctuation in HTML bibliographies

This commit is contained in:
Dan Stillman 2009-10-27 02:31:59 +00:00
parent 0b05cb34a8
commit 7a4864caf2
2 changed files with 25 additions and 6 deletions

View file

@ -407,13 +407,11 @@ Zotero.CSL.prototype.formatBibliography = function(itemSet, format) {
if(format == "HTML") {
var coins = Zotero.OpenURL.createContextObject(item.zoteroItem, "1.0");
// Wrap URLs in <a href=""> links, in a very unsophisticated manner
// Wrap URLs and DOIs in HTML links
//
// This should be done earlier when the data is still in variables
//
// Ignore URLs preceded by '>', since these are likely already links
string = string.replace(/([^>])(https?:\/\/[^\s]+)([\."'>:\]\)\s])/g, '$1<a href="$2">$2</a>$3');
string = string.replace(/(doi:[ ]*)(10\.[^\s]+[0-9a-zA-Z])/g, '$1<a href="http://dx.doi.org/$2">$2</a>');
// This should be handled when the values are still in variables
// (and presumably will be in the new engine)
string = Zotero.Utilities.prototype.autoLink(string);
var span = (coins ? ' <span class="Z3988" title="'+coins.replace("&", "&amp;", "g")+'">&nbsp;</span>' : '');

View file

@ -203,6 +203,27 @@ Zotero.Utilities.prototype.unescapeHTML = function(/**String*/ str) {
return nsISUHTML.unescape(str);
}
/**
* Wrap URLs and DOIs in <a href=""> links in plain text
*
* Ignore URLs preceded by '>', just in case there are already links
*/
Zotero.Utilities.prototype.autoLink = function (str) {
// "http://www.google.com."
// "http://www.google.com. "
// "<http://www.google.com>" (and other characters, with or without a space after)
str = str.replace(/([^>])(https?:\/\/[^\s]+)([\."'>:\]\)](\s|$))/g, '$1<a href="$2">$2</a>$3');
// "http://www.google.com"
// "http://www.google.com "
str = str.replace(/([^">])(https?:\/\/[^\s]+)(\s|$)/g, '$1<a href="$2">$2</a>$3');
// DOI
str = str.replace(/(doi:[ ]*)(10\.[^\s]+[0-9a-zA-Z])/g, '$1<a href="http://dx.doi.org/$2">$2</a>');
return str;
}
/**
* Parses a text string for HTML/XUL markup and returns an array of parts. Currently only finds
* HTML links (&lt;a&gt; tags)