- Do additional whitespace normalization when diffing items to prevent erroneous conflicts
- Save multiple whitespaces in TinyMCE as " " instead of " " to prevent collapsing elsewhere - Convert multiple spaces in plaintext notes (e.g., from 1.0) to " " instead of " "
This commit is contained in:
parent
8a4e7e88a4
commit
85ffc6b214
3 changed files with 31 additions and 12 deletions
|
@ -12,7 +12,7 @@
|
|||
content_css : "css/note-content.css",
|
||||
button_tile_map : true,
|
||||
language : "en", // TODO: localize
|
||||
entity_encoding : "raw",
|
||||
entities : "160,nbsp",
|
||||
gecko_spellcheck : true,
|
||||
|
||||
handle_event_callback : function (event) {
|
||||
|
|
|
@ -3679,21 +3679,42 @@ Zotero.Item.prototype.diff = function (item, includeMatches, ignoreFields) {
|
|||
}
|
||||
|
||||
if (thisData.note != undefined) {
|
||||
// replace() keeps Windows newlines from triggering erroneous conflicts,
|
||||
// though this should really be fixed at the data layer level
|
||||
// Whitespace normalization
|
||||
//
|
||||
// Using a try/catch to avoid unexpected errors in 2.1 Final
|
||||
// Ideally this would all be fixed elsewhere so we didn't have to
|
||||
// convert on every sync diff
|
||||
//
|
||||
// TEMP: Using a try/catch to avoid unexpected errors in 2.1 releases
|
||||
try {
|
||||
changed = thisData.note.replace(/\r\n/g, "\n") != otherData.note.replace(/\r\n/g, "\n");
|
||||
var thisNote = thisData.note;
|
||||
var otherNote = otherData.note;
|
||||
|
||||
// Stop Windows newlines from triggering erroneous conflicts
|
||||
thisNote = thisNote.replace(/\r\n/g, "\n");
|
||||
otherNote = otherNote.replace(/\r\n/g, "\n");
|
||||
|
||||
// Normalize multiple spaces (due to differences TinyMCE, Z.U.text2html(),
|
||||
// and the server)
|
||||
var re = /( | |\u00a0 |\u00a0\u00a0)/g;
|
||||
thisNote = thisNote.replace(re, " ");
|
||||
otherNote = otherNote.replace(re, " ");
|
||||
|
||||
// Normalize new paragraphs
|
||||
var re = /<p>( |\u00a0)<\/p>/g;
|
||||
thisNote = thisNote.replace(re, "<p> </p>");
|
||||
otherNote = otherNote.replace(re, "<p> </p>");
|
||||
|
||||
changed = thisNote != otherNote;
|
||||
}
|
||||
catch (e) {
|
||||
Zotero.debug(e);
|
||||
Components.utils.reportError(e);
|
||||
changed = thisData.note != otherData.note;
|
||||
changed = thisNote != otherNote;
|
||||
}
|
||||
|
||||
if (includeMatches || changed) {
|
||||
diff[0].note = thisData.note;
|
||||
diff[1].note = otherData.note;
|
||||
diff[0].note = thisNote;
|
||||
diff[1].note = otherNote;
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
|
|
|
@ -159,8 +159,7 @@ Zotero.Utilities = {
|
|||
if (singleNewlineIsParagraph) {
|
||||
str = '<p>'
|
||||
+ str.replace(/\n/g, '</p><p>')
|
||||
.replace(/\t/g, ' ')
|
||||
.replace(/ /g, ' ')
|
||||
.replace(/ /g, ' ')
|
||||
+ '</p>';
|
||||
}
|
||||
// \n\n => <p>, \n => <br/>
|
||||
|
@ -169,8 +168,7 @@ Zotero.Utilities = {
|
|||
str = '<p>'
|
||||
+ str.replace(/\n\n/g, '</p><p>')
|
||||
.replace(/\n/g, '<br/>')
|
||||
.replace(/\t/g, ' ')
|
||||
.replace(/ /g, ' ')
|
||||
.replace(/ /g, ' ')
|
||||
+ '</p>';
|
||||
}
|
||||
return str.replace(/<p>\s*<\/p>/g, '<p> </p>');
|
||||
|
|
Loading…
Add table
Reference in a new issue