Skip to content

Process, whitelist, blacklist, migrate available blocks, styles and entities when pasting rich text#50

Merged
thibaudcolas merged 27 commits intomasterfrom
feature/rich-paste-filtering
Dec 3, 2017
Merged

Process, whitelist, blacklist, migrate available blocks, styles and entities when pasting rich text#50
thibaudcolas merged 27 commits intomasterfrom
feature/rich-paste-filtering

Conversation

@thibaudcolas
Copy link
Copy Markdown
Member

Very WIP.

@thibaudcolas thibaudcolas added the enhancement New feature or request label Mar 10, 2017
@coveralls
Copy link
Copy Markdown

coveralls commented Mar 10, 2017

Coverage Status

Coverage increased (+0.2%) to 56.543% when pulling e2feca2 on feature/rich-paste-filtering into fa88c74 on master.

@coveralls
Copy link
Copy Markdown

coveralls commented Mar 10, 2017

Coverage Status

Coverage increased (+0.2%) to 56.543% when pulling 3e36fd5 on feature/rich-paste-filtering into 3641d6f on master.

@thibaudcolas thibaudcolas force-pushed the feature/rich-paste-filtering branch from 3e36fd5 to 9b3a7bd Compare May 25, 2017 15:45
@thibaudcolas thibaudcolas force-pushed the feature/rich-paste-filtering branch 2 times, most recently from 74e7acb to 80ea9c3 Compare October 18, 2017 08:03
@thibaudcolas thibaudcolas mentioned this pull request Oct 18, 2017
10 tasks
@thibaudcolas thibaudcolas force-pushed the feature/rich-paste-filtering branch 2 times, most recently from 9ec1f12 to f5ab772 Compare December 2, 2017 13:48
@thibaudcolas thibaudcolas force-pushed the feature/rich-paste-filtering branch from f5ab772 to dcba485 Compare December 3, 2017 17:09
@thibaudcolas thibaudcolas changed the title [WIP] Filter available blocks, styles and entities when pasting rich text Filter available blocks, styles and entities when pasting rich text Dec 3, 2017
@thibaudcolas thibaudcolas changed the title Filter available blocks, styles and entities when pasting rich text Process, whitelist, blacklist, migrate available blocks, styles and entities when pasting rich text Dec 3, 2017
@thibaudcolas thibaudcolas added this to the Wagtail 2.0 milestone Dec 3, 2017
@thibaudcolas thibaudcolas self-assigned this Dec 3, 2017
Comment thread .github/CONTRIBUTING.md
* [ ] [Google Docs](https://docs.google.com/)
* [ ] [Apple Pages](https://www.apple.com/lae/pages/)
* [ ] [Dropbox Paper](https://www.dropbox.com/paper)
* [ ] [Open Office Writer](https://www.openoffice.org/product/writer.html)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, I don't want to support this.

Comment thread .travis.yml
- npm run test:ci
# Move build artefacts to public folder so they are published on the demo site.
- mv webpack/webpack-stats.html public || true
- mv coverage/lcov-report public || true
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated.

Comment thread docs/README.md

Here are specific external sources we want to pay special attention too, and for which we have ready-made test documents with all of the possible rich content.

* [ ] [Microsoft Word](https://products.office.com/en/word): TODO
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO, urgently. I want to try this on Windows especially, and it will be easier once this is merged.

Comment thread docs/README.md
* https://github.com/springload/draftail/blob/df903f86c882bd5101eb05e152e8b8a8b9a4915e/lib/api/behavior.js#L100-L110
* https://github.com/springload/draftail/commit/8d9de77349cd2f7ee1cba36b03f2946a21039dde
* https://github.com/springload/draftail/blob/df903f86c882bd5101eb05e152e8b8a8b9a4915e/lib/api/behavior.js#L23:L26
* https://github.com/springload/draftail/commit/162fc13e193ac581f662de393151efde477183b9
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might add a few more once this is merged, because the paste behavior is very dependent on Draft.js internals right now.

Comment thread examples/index.html

<hr>

<h3>Copy/paste test cases</h3>
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might put this in a separate file in the future.

Comment thread lib/api/normalize.js
.filter(type => !enabledTypes.includes(type))
.forEach(type => {
altered = true;
newChar = CharacterMetadata.removeStyle(newChar, type);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reducing over the array to create a char without any styles. There may be a simpler way, but I doubt there would be chars with more than say 10 inline styles in a worst case scenario. 2-3 is already a lot for real-world content.

Comment thread lib/api/normalize.js
block =>
block.getType() === BLOCK_TYPE.ATOMIC &&
(block.getText() !== ' ' ||
block.getInlineStyleAt(0).size !== 0),
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normalises the block if its text isn't right, or if it has inline styles on it. Happens with pasting from Google Docs.

Comment thread lib/api/normalize.js
const entityKey = block.getEntityAt(0);
let shouldReset = false;

if (entityKey) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how there could be an atomic block without an entity in real-world content, but we never know.

Comment thread lib/api/normalize.js
* on paste.
* A better approach would probably be to split the block where the image is and
* create an atomic block there, but that's another story. This is what Draft.js
* does when the copy-paste is all within one editor.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not be that complicated with the Modifier method that does this, but another time.

Comment thread lib/api/normalize.js
* that Draft.js inserts.
* If we want to remove this in the future, consider that:
* - It needs to be removed in the block text, where it's 2 chars / 1 code point.
* - The corresponding CharacterMetadata needs to be removed too, and it's 2 instances
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unicode fun.

@thibaudcolas thibaudcolas merged commit 8361d48 into master Dec 3, 2017
@thibaudcolas thibaudcolas deleted the feature/rich-paste-filtering branch December 3, 2017 20:26
@wagtail wagtail deleted a comment from deborahharrus Dec 3, 2017
@thibaudcolas thibaudcolas mentioned this pull request Dec 4, 2017
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants