diff --git a/chrome/content/zotero/xpcom/data/notes.js b/chrome/content/zotero/xpcom/data/notes.js index 19424c36fe..a6f89b2815 100644 --- a/chrome/content/zotero/xpcom/data/notes.js +++ b/chrome/content/zotero/xpcom/data/notes.js @@ -145,6 +145,13 @@ Zotero.Notes = new function() { } return doc.body.innerHTML; }; + + this.hasSchemaVersion = function (note) { + let parser = Components.classes['@mozilla.org/xmlextras/domparser;1'] + .createInstance(Components.interfaces.nsIDOMParser); + let doc = parser.parseFromString(note, 'text/html'); + return !!doc.querySelector('body > div[data-schema-version]'); + }; }; if (typeof process === 'object' && process + '' === '[object process]') { diff --git a/chrome/content/zotero/xpcom/editorInstance.js b/chrome/content/zotero/xpcom/editorInstance.js index cb5a23f904..5651505d00 100644 --- a/chrome/content/zotero/xpcom/editorInstance.js +++ b/chrome/content/zotero/xpcom/editorInstance.js @@ -88,8 +88,7 @@ class EditorInstance { placeholder: options.placeholder, dir: Zotero.dir, font: this._getFont(), - // TODO: We should avoid hitting `data-schema-version` in note text - hasBackup: note && note.toLowerCase().indexOf('data-schema-version') < 0 + hasBackup: note && !Zotero.Notes.hasSchemaVersion(note) || !!await Zotero.NoteBackups.getNote(this._item.id) }); } diff --git a/chrome/content/zotero/xpcom/noteBackups.js b/chrome/content/zotero/xpcom/noteBackups.js index ecad1cce51..a38a655eef 100644 --- a/chrome/content/zotero/xpcom/noteBackups.js +++ b/chrome/content/zotero/xpcom/noteBackups.js @@ -34,8 +34,7 @@ Zotero.NoteBackups = { ensureBackup: async function(item) { let note = item.note; - // TODO: We should avoid hitting `data-schema-version` in note text - if (note && note.toLowerCase().indexOf('data-schema-version') < 0) { + if (note && !Zotero.Notes.hasSchemaVersion(note)) { await Zotero.DB.queryAsync("INSERT OR IGNORE INTO noteBackups VALUES (?, ?)", [item.id, item.note]); } },