commit 7a4864caf25bd8e39cc0f8c08adc117d5f42f082
parent 0b05cb34a89d35915738b5a17e0fefcb3dc563d6
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 27 Oct 2009 02:31:59 +0000
Fix incorrect linking of URLs without trailing punctuation in HTML bibliographies
Diffstat:
2 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/chrome/content/zotero/xpcom/csl.js b/chrome/content/zotero/xpcom/csl.js
@@ -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("&", "&", "g")+'"> </span>' : '');
diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js
@@ -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 (<a> tags)