draft-js-utils
draft-js-utils copied to clipboard
Add option to not render blocks with only whitespace
Is that behaviour intentional? Wouldn't it be better to return an empty string instead?
...
import { stateToHTML } from 'draft-js-export-html';
...
console.log(stateToHTML(EditorState.createEmpty().getCurrentContent()));
// <p><br></p>
const blockArray = convertFromHTML('');
const contentState = ContentState.createFromBlockArray(blockArray);
console.log(stateToHTML(contentState));
// <p><br></p>
...
Similar with spaces. It returns <p> </p>
.
Could you please add option to not render lines (blocks) which have only whitespaces?
Does any one have a temporary work around for this?
To follow up on my last comment, I ended up just doing a draft getPlainText().trim() check before saving to DB. Not an ideal solution but it works. Looking forward to this request getting done.
part of the problem is solved https://github.com/sstur/draft-js-utils/pull/93
In case anyone is still looking for a work around. I just hacked around the styling for empty blocks. Hope this helps
let options = {
blockStyleFn: (block) => {
const type = block.getType();
if (type === 'unstyled') {
return {
style: {
display: 'none'
},
}
}
}
}
const options = {
blockRenderer: {
unstyled(block) {
if (!block.getText().trim().length) {
return "";
}
}
}
}
const options = { blockRenderer: { unstyled(block) { if (!block.getText().trim().length) { return ""; } } } }
const options = {
blockRenderers: {
unstyled: (block) => {
if (!block.getText().trim().length) {
return "";
}
}
}
}
const options = { blockRenderer: { unstyled(block) { if (!block.getText().trim().length) { return ""; } } } }
it didn't support typescript well. i need to put this ugly any there. but its worked