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

Commit

Permalink
fix wrong property access in convertFromHTMLToContentBlocks
Browse files Browse the repository at this point in the history
Summary:
`_extractTextFromBlockConfigs` was checking the `blockType` property of a `ContentBlockConfig`. However, `ContentBlockConfig` doesn't actually contain a `blockType` property. The right name is just `type`.

This diff fixes that and removes the flow suppression comment. Doing this also fixes an annoying problem where blockquotes (among other things) would have extra newline characters inserted when pasting into the editor.

Reviewed By: mrkev

Differential Revision: D18581836

fbshipit-source-id: 23b2b8a4ea75fd6b7d9a89fd11dc6cc889052d5d
  • Loading branch information
Frank Thompson authored and facebook-github-bot committed Nov 22, 2019
1 parent e7ae2e7 commit 7d26fab
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,73 @@ Array [
]
`;

exports[`Should import two blockquotes without extra line breaks 1`] = `
Array [
Object {
"characterList": Array [
Object {
"entity": null,
"style": Array [],
},
Object {
"entity": null,
"style": Array [],
},
Object {
"entity": null,
"style": Array [],
},
Object {
"entity": null,
"style": Array [],
},
Object {
"entity": null,
"style": Array [],
},
],
"data": Object {},
"depth": 0,
"key": "key0",
"text": "First",
"type": "blockquote",
},
Object {
"characterList": Array [
Object {
"entity": null,
"style": Array [],
},
Object {
"entity": null,
"style": Array [],
},
Object {
"entity": null,
"style": Array [],
},
Object {
"entity": null,
"style": Array [],
},
Object {
"entity": null,
"style": Array [],
},
Object {
"entity": null,
"style": Array [],
},
],
"data": Object {},
"depth": 0,
"key": "key2",
"text": "Second",
"type": "unstyled",
},
]
`;

exports[`Should not create empty container blocks around ol and their list items 1`] = `
Array [
Object {
Expand Down Expand Up @@ -2951,17 +3018,12 @@ Array [
"entity": null,
"style": Array [],
},
Object {
"entity": null,
"style": Array [],
},
],
"data": Object {},
"depth": 0,
"key": "key1",
"text": "Hello World!
lorem ipsum
",
lorem ipsum",
"type": "ordered-list-item",
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,3 +531,21 @@ test('Should import line breaks without creating a leading space', () => {
experimentalTreeDataSupport: false,
});
});

test('Should import two blockquotes without extra line breaks', () => {
const html_string = `
<blockquote>
<div>
<span>First</span>
</div>
</blockquote
<blockquote>
<div>
<span>Second</span>
</div>
</blockquote>
`;
assertConvertFromHTMLToContentBlocks(html_string, {
experimentalTreeDataSupport: false,
});
});
5 changes: 1 addition & 4 deletions src/model/encoding/convertFromHTMLToContentBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,10 +730,7 @@ class ContentBlocksBuilder {
const config = blockConfigs[i];
text += config.text;
characterList = characterList.concat(config.characterList);
/* $FlowFixMe(>=0.68.0 site=www,mobile) This comment suppresses an error
* found when Flow v0.68 was deployed. To see the error delete this
* comment and run Flow. */
if (text !== '' && config.blockType !== 'unstyled') {
if (text !== '' && config.type !== 'unstyled') {
text += '\n';
characterList = characterList.push(characterList.last());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1608,16 +1608,11 @@ Array [
"entity": null,
"style": Array [],
},
Object {
"entity": null,
"style": Array [],
},
],
"data": Object {},
"depth": 0,
"key": "key2",
"text": "what
one
"text": "whatone
two
",
"type": "unordered-list-item",
Expand Down

0 comments on commit 7d26fab

Please sign in to comment.