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

Commit

Permalink
Make default text content of img blocks a little camera emoji
Browse files Browse the repository at this point in the history
Summary:
**what is the change?:**
We don't allow pasting whitespace-only blocks - see #231

In the past we set the 'src' as the text content of an 'img' block when
pasting/converting HTML, but sometimes the 'src' is really long and can
even crash the editor. Plus that's not really what users expect when
they paste an image.

An empty string as a default would be better but the code in
`convertFromHTML` needs refactored and for now I don't want to touch it.
The camera emoji is a cute and easy fix.

**why make this change?:**
Right now images are being dropped by `convertFromHTML

**test plan:**
Manual testing with examples/draft-0-10-0/convertFromHTML/convert.html

We should do a follow-up change to add a test that catches this.

**issue:**
#1377

*Before* submitting a pull request, please make sure the following is done...

1. Fork the repo and create your branch from `master`.
2. If you've added code that should be tested, add tests!
3. If you've changed APIs, update the documentation.
4. Ensure that:
  * The test suite passes (`npm test`)
  * Your code lints (`npm run lint`) and passes Flow (`npm run flow`)
  * You have followed the [testing guidelines](https://github.com/facebook/draft-js/wiki/Testing-for-Pull-Requests)
5. If you haven't already, complete the [CLA](https://code.facebook.com/cla).

Please use the simple form below as a guideline for describing your pull request.

Thanks for contributing to Draft.js!

-

**Summary**

[...]

**Test Plan**

[...]
Closes #1378

Differential Revision: D5804382

fbshipit-source-id: f465a1a92155b02c5650acb9622e27e4e3714492
  • Loading branch information
flarnie authored and facebook-github-bot committed Sep 11, 2017
1 parent d49eb13 commit 95f7f9b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
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

0 comments on commit 95f7f9b

Please sign in to comment.