diff --git a/src/model/encoding/__tests__/__snapshots__/convertFromHTMLToContentBlocks-test.js.snap b/src/model/encoding/__tests__/__snapshots__/convertFromHTMLToContentBlocks-test.js.snap index cca45960a7..febc6878c1 100644 --- a/src/model/encoding/__tests__/__snapshots__/convertFromHTMLToContentBlocks-test.js.snap +++ b/src/model/encoding/__tests__/__snapshots__/convertFromHTMLToContentBlocks-test.js.snap @@ -1539,6 +1539,8 @@ exports[`img with data protocol should be correctly parsed 1`] = `"📷"`; exports[`img with http protocol should have camera emoji content 1`] = `"📷"`; +exports[`img with role presentation should not be rendered 1`] = `null`; + exports[`must convert root ContentBlockNodes to matching ContentBlock nodes for
1`] = `true`; exports[`must convert root ContentBlockNodes to matching ContentBlock nodes for 1`] = `true`; diff --git a/src/model/encoding/__tests__/__snapshots__/convertFromHTMLToContentBlocks2-test.js.snap b/src/model/encoding/__tests__/__snapshots__/convertFromHTMLToContentBlocks2-test.js.snap index eeae77c209..5f8d79afbb 100644 --- a/src/model/encoding/__tests__/__snapshots__/convertFromHTMLToContentBlocks2-test.js.snap +++ b/src/model/encoding/__tests__/__snapshots__/convertFromHTMLToContentBlocks2-test.js.snap @@ -2486,6 +2486,8 @@ exports[`img with data protocol should be correctly parsed 1`] = `"📷"`; exports[`img with http protocol should have camera emoji content 1`] = `"📷"`; +exports[`img with role presentation should not be rendered 1`] = `Array []`; + exports[`must convert root ContentBlockNodes to matching ContentBlock nodes for 1`] = `true`; exports[`must convert root ContentBlockNodes to matching ContentBlock nodes for 1`] = `true`; diff --git a/src/model/encoding/__tests__/convertFromHTMLToContentBlocks-test.js b/src/model/encoding/__tests__/convertFromHTMLToContentBlocks-test.js index 828148202d..681d7ba9db 100644 --- a/src/model/encoding/__tests__/convertFromHTMLToContentBlocks-test.js +++ b/src/model/encoding/__tests__/convertFromHTMLToContentBlocks-test.js @@ -60,7 +60,13 @@ const normalizeBlock = block => { const toggleExperimentalTreeDataSupport = enabled => { jest.doMock('gkx', () => name => { - return name === 'draft_tree_data_support' ? enabled : false; + if (name === 'draft_tree_data_support') { + return enabled; + } + if (name === 'draftjs_fix_paste_for_img') { + return true; + } + return false; }); }; @@ -152,6 +158,13 @@ test('img with data protocol should be correctly parsed', () => { expect(blocks.contentBlocks[0].text).toMatchSnapshot(); }); +test('img with role presentation should not be rendered', () => { + const blocks = convertFromHTMLToContentBlocks( + ``, + ); + expect(blocks.contentBlocks).toMatchSnapshot(); +}); + test('converts nested html blocks when experimentalTreeDataSupport is enabled', () => { const html_string = `diff --git a/src/model/encoding/__tests__/convertFromHTMLToContentBlocks2-test.js b/src/model/encoding/__tests__/convertFromHTMLToContentBlocks2-test.js index 41647ae262..ccb10ff789 100644 --- a/src/model/encoding/__tests__/convertFromHTMLToContentBlocks2-test.js +++ b/src/model/encoding/__tests__/convertFromHTMLToContentBlocks2-test.js @@ -60,7 +60,13 @@ const normalizeBlock = block => { const toggleExperimentalTreeDataSupport = enabled => { jest.doMock('gkx', () => name => { - return name === 'draft_tree_data_support' ? enabled : false; + if (name === 'draft_tree_data_support') { + return enabled; + } + if (name === 'draftjs_fix_paste_for_img') { + return true; + } + return false; }); }; @@ -152,6 +158,13 @@ test('img with data protocol should be correctly parsed', () => { expect(blocks.contentBlocks[0].text).toMatchSnapshot(); }); +test('img with role presentation should not be rendered', () => { + const blocks = convertFromHTMLToContentBlocks( + ``, + ); + expect(blocks.contentBlocks).toMatchSnapshot(); +}); + test('converts nested html blocks when experimentalTreeDataSupport is enabled', () => { const html_string = `diff --git a/src/model/encoding/convertFromHTMLToContentBlocks.js b/src/model/encoding/convertFromHTMLToContentBlocks.js index c6b474fe77..7901e9e5be 100644 --- a/src/model/encoding/convertFromHTMLToContentBlocks.js +++ b/src/model/encoding/convertFromHTMLToContentBlocks.js @@ -446,10 +446,16 @@ const genFragment = ( }); // Forcing this node to have children because otherwise no entity will be // created for this node. - // The child text node cannot just have a space or return as content - - // we strip those out. + // The child text node cannot just have a space or return as content (since + // we strip those out), unless the image is for presentation only. // See https://github.com/facebook/draft-js/issues/231 for some context. - node.textContent = '\ud83d\udcf7'; + if (gkx('draftjs_fix_paste_for_img')) { + if (node.getAttribute('role') !== 'presentation') { + node.textContent = '\ud83d\udcf7'; + } + } else { + node.textContent = '\ud83d\udcf7'; + } // TODO: update this when we remove DraftEntity entirely inEntity = DraftEntity.__create('IMAGE', 'MUTABLE', entityConfig || {}); diff --git a/src/model/encoding/convertFromHTMLToContentBlocks2.js b/src/model/encoding/convertFromHTMLToContentBlocks2.js index 0b8d7dfbe1..9c6f463c10 100644 --- a/src/model/encoding/convertFromHTMLToContentBlocks2.js +++ b/src/model/encoding/convertFromHTMLToContentBlocks2.js @@ -534,11 +534,17 @@ class ContentBlocksBuilder { entityConfig, ); - // The child text node cannot just have a space or return as content - - // we strip those out. + // The child text node cannot just have a space or return as content (since + // we strip those out), unless the image is for presentation only. // See https://github.com/facebook/draft-js/issues/231 for some context. + if (gkx('draftjs_fix_paste_for_img')) { + if (node.getAttribute('role') !== 'presentation') { + this._appendText('\ud83d\udcf7'); + } + } else { + this._appendText('\ud83d\udcf7'); + } - this._appendText('\ud83d\udcf7'); this.currentEntity = null; }