www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 47285a05671d264b8d86a8d8e6dbe4bae5a5c57f
parent 71ca2c1b2c0d4259d0d2fc946c2866f32a9659b6
Author: Dan Stillman <dstillman@zotero.org>
Date:   Mon, 13 Oct 2008 21:12:55 +0000

Convert plaintext notes on the fly, to deal with multi-version syncing issues


Diffstat:
Mchrome/content/zotero/bindings/styled-textbox.xml | 2+-
Mchrome/content/zotero/xpcom/data/item.js | 20+++++++++++++++++---
2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/chrome/content/zotero/bindings/styled-textbox.xml b/chrome/content/zotero/bindings/styled-textbox.xml @@ -228,7 +228,7 @@ var html = val; if(this._format == "Integration" || this._format == "RTF") { - bodyStyle = ""; + var bodyStyle = ""; if(html.substr(0, 3) == "\\li") { // try to show paragraph formatting var returnIndex = html.indexOf("\r\n"); diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js @@ -1242,7 +1242,7 @@ Zotero.Item.prototype.save = function() { var parent = this.isNote() ? this.getSource() : null; var noteText = this._noteText ? this._noteText : ''; // Add <div> wrapper if not present - if (!noteText.match(/^<div class="zotero\-note znv[0-9]+">.*<\/div>$/)) { + if (!noteText.match(/^<div class="zotero-note znv[0-9]+">[\s\S]*<\/div>$/)) { noteText = '<div class="zotero-note znv1">' + noteText + '</div>'; } @@ -1583,7 +1583,7 @@ Zotero.Item.prototype.save = function() { var parent = this.isNote() ? this.getSource() : null; var noteText = this._noteText; // Add <div> wrapper if not present - if (!noteText.match(/^<div class="zotero\-note znv[0-9]+">.*<\/div>$/)) { + if (!noteText.match(/^<div class="zotero-note znv[0-9]+">[\s\S]*<\/div>$/)) { noteText = '<div class="zotero-note znv1">' + noteText + '</div>'; } var bindParams = [ @@ -1994,8 +1994,22 @@ Zotero.Item.prototype.getNote = function() { var sql = "SELECT note FROM itemNotes WHERE itemID=?"; var note = Zotero.DB.valueQuery(sql, this.id); + + // Convert non-HTML notes on-the-fly + if (!note.match(/^<div class="zotero-note znv[0-9]+">[\s\S]*<\/div>$/)) { + note = Zotero.Utilities.prototype.htmlSpecialChars(note); + note = '<p>' + + note.replace(/\n/g, '</p><p>') + .replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;') + .replace(/ /g, '&nbsp;&nbsp;') + + '</p>'; + note = note.replace(/<p>\s*<\/p>/g, '<p>&nbsp;</p>'); + var sql = "UPDATE itemNotes SET note=? WHERE itemID=?"; + Zotero.DB.query(sql, [note, this.id]); + } + // Don't include <div> wrapper when returning value - note = note.replace(/^<div class="zotero-note znv[0-9]+">(.*)<\/div>$/, '$1'); + note = note.replace(/^<div class="zotero-note znv[0-9]+">([\s\S]*)<\/div>$/, '$1'); this._noteText = note ? note : '';