diff --git a/chrome/content/zotero/xpcom/csl.js b/chrome/content/zotero/xpcom/csl.js
index f4f93242bf..111f632502 100644
--- 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 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$2$3');
- string = string.replace(/(doi:[ ]*)(10\.[^\s]+[0-9a-zA-Z])/g, '$1$2');
+ // 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 ? ' ' : '');
diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js
index d84b44c1fd..d9a61ffe1c 100644
--- 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 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. "
+ // "" (and other characters, with or without a space after)
+ str = str.replace(/([^>])(https?:\/\/[^\s]+)([\."'>:\]\)](\s|$))/g, '$1$2$3');
+ // "http://www.google.com"
+ // "http://www.google.com "
+ str = str.replace(/([^">])(https?:\/\/[^\s]+)(\s|$)/g, '$1$2$3');
+
+ // DOI
+ str = str.replace(/(doi:[ ]*)(10\.[^\s]+[0-9a-zA-Z])/g, '$1$2');
+ return str;
+}
+
+
/**
* Parses a text string for HTML/XUL markup and returns an array of parts. Currently only finds
* HTML links (<a> tags)