HubSpot / draft-convert

Extensibly serialize & deserialize Draft.js ContentState with HTML.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

convertToHTML returns empty <p></p> when editor has no content...how do I get it to return empty string?

hgezim opened this issue · comments

Currently, if editor has no content, convertToHTML returns an empty <p></p>. How do I get it to return an empty string?

Makes no sense to have a bunch of <p></p>s in the database.

Thoughts?

Not sure if you already fixed this. But you can try this for solving it:

    blockToHTML: (block: ContentBlock) => {
      if (block.type === 'unstyled') {
        return {
          start: '',
          end: '',
        };
      }
      return undefined;
    },

But this way it won't preserve spaces when parsing back, i'm trying to solve that.