Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Make default text content of img blocks a little camera emoji #1378

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ describe('convertFromHTMLToContentBlocks', () => {
].forEach(tag => testConvertingAdjacentHtmlElementsToContentBlocks(tag));

describe('img tag', function() {
test('img with http protocol should have empty content', function() {
test('img with http protocol should have camera emoji content', function() {
const blocks = convertFromHTMLToContentBlocks(
'<img src="http://www.facebook.com">',
);
expect(blocks.contentBlocks[0].text).toBe(' ');
expect(blocks.contentBlocks[0].text).toBe('\ud83d\udcf7');
});

test('img with data protocol should be correctly parsed', function() {
const blocks = convertFromHTMLToContentBlocks(
`<img src="${IMAGE_DATA_URL}">`,
);
expect(blocks.contentBlocks[0].text).toBe(' ');
expect(blocks.contentBlocks[0].text).toBe('\ud83d\udcf7');
});
});
});
5 changes: 4 additions & 1 deletion src/model/encoding/convertFromHTMLToContentBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,10 @@ function genFragment(
});
// Forcing this node to have children because otherwise no entity will be
// created for this node.
node.textContent = ' ';
// The child text node cannot just have a space or return as content -
// we strip those out.
// See https://github.com/facebook/draft-js/issues/231 for some context.
node.textContent = '\ud83d\udcf7';

// TODO: update this when we remove DraftEntity entirely
inEntity = DraftEntity.__create(
Expand Down