diff --git a/src/export/note.js b/src/export/note.js index e6896b2077..d7433b6f4e 100644 --- a/src/export/note.js +++ b/src/export/note.js @@ -4,13 +4,19 @@ const { NOTE } = require('../constants/type') const { DOMSerializer } = require('prosemirror-model') const { schema } = require('../components/editor/schema') +const { warn } = require('../common/log') const serializer = DOMSerializer.fromSchema(schema) function toHTML(doc) { - const node = schema.nodeFromJSON(doc) - const docFragment = serializer.serializeFragment(node) - return Array.from(docFragment.children).map(x => x.outerHTML).join('') + try { + const node = schema.nodeFromJSON(doc) + const docFragment = serializer.serializeFragment(node) + return Array.from(docFragment.children).map(x => x.outerHTML).join('') + } catch (error) { + warn('Could not convert note to html', { error, doc }) + return '' + } } module.exports = function (note) { diff --git a/test/export/export_test.js b/test/export/export_test.js index 2bc28fea61..a59ce5669f 100644 --- a/test/export/export_test.js +++ b/test/export/export_test.js @@ -104,7 +104,7 @@ describe('export', () => { const item1 = (await ld)[0]['@graph'][0] expect(item1.photo[0]).to.not.have.property('note') expect(item1.photo[1]['note']['text']).to.eql('photo note') - expect(item1.photo[1]['note']['doc']).to.eql('{"foo":"bar"}') + expect(item1.photo[1]['note']['html']).to.eql('

photo note

') }) }) diff --git a/test/fixtures/export.js b/test/fixtures/export.js index 1aa9f6b7a5..cd37354b43 100644 --- a/test/fixtures/export.js +++ b/test/fixtures/export.js @@ -79,7 +79,21 @@ const tags = { } const notes = { - 1: { text: 'photo note', state: { doc: { foo: 'bar' } } }, + 1: { + text: 'photo note', + state: { + doc: { + type: 'doc', + content: [{ + type: 'paragraph', + content: [{ + type: 'text', + text: 'photo note' + }] + }] + } + } + }, 2: { text: 'selection note', state: {} } }