draft-js icon indicating copy to clipboard operation
draft-js copied to clipboard

Support custom inline styles when importing from HTML?

Open coopy opened this issue 8 years ago • 24 comments

The docs mention that you can define map CSS styles to arbitrary styles. I need to serialize my editorState to HTML and from during and between editing sessions.

I know from looking at other Issues that serializing to and rehydrating from HTML should be avoided, but I think there are lots of use cases where you want to frequently initialize the Draft editor from some external state and have the editorState truthfully represent what's given to the editor.

Looking at the source code, only a handful of inline elements are supported:

  • b: 'BOLD'
  • code: 'CODE'
  • del: 'STRIKETHROUGH'
  • em: 'ITALIC'
  • i: 'ITALIC'
  • s: 'STRIKETHROUGH'
  • strike: 'STRIKETHROUGH'
  • strong: 'BOLD'
  • u: 'UNDERLINE'

I'd like to convert from more inline styles to the style strings that I use with RichUtils.toggleInlineStyle; notably superscript <sup/> and subscript <sub>.

The only way to support them today that I can see (without forking the draft-js source) is to choose other styles that I don't use (say, strikethrough and underline) to represent the styles that I want. Is there a different way?

How would one go about implementing support for custom inline tags for the HTML conversion? As far as I can tell, it doesn't have access to props passed to <Editor/>.

Thanks!

coopy avatar Apr 08 '16 21:04 coopy

I am working on a PR to make that configurable will be similar to https://github.com/facebook/draft-js/pull/205, it was going to be part of that PR but it got way to large so got split over. Just waiting it to be merged into master. At the moment it has already being imported

mitermayer avatar Apr 08 '16 21:04 mitermayer

@mitermayer that's cool. In the meantime, I might just add the inline tags that I need to a fork of draft-js.

coopy avatar Apr 08 '16 23:04 coopy

@coopy @mitermayer Hello, guys. Do you have any news?

milushov avatar Sep 05 '16 10:09 milushov

@mitermayer I did not find your PR here

milushov avatar Sep 05 '16 10:09 milushov

I'm also in need of this feature. Any word on this?

MrDarkHorse avatar Oct 11 '16 15:10 MrDarkHorse

Hi guys, I am back working at draft-js will post the PR soon.

mitermayer avatar Oct 19 '16 06:10 mitermayer

Looking forward to this!

coinfork avatar Oct 19 '16 21:10 coinfork

Got something ready for this, I believe however that maybe the converter to html could be split from draft itself into a separate module, we could then create an API to allow user specific converters. Example would be allowing user to paste markdown content, this however can be discussed on another issue. In the meantime will write some tests do a bit of refactoring and open a PR for this

mitermayer avatar Oct 24 '16 21:10 mitermayer

Hi - need to support superscript and subscript style on HTML import. Where do we stand from support perspective for these extra styles ?

andpor avatar Mar 24 '17 19:03 andpor

Is this implemented?

taylorstine avatar Mar 31 '17 03:03 taylorstine

I am also wondering if superscript and subscripts are supported yet.

tsboom avatar Sep 12 '17 20:09 tsboom

Any news on this?

joafeldmann avatar Apr 25 '18 15:04 joafeldmann

Still no news ?

Drewsov avatar Jun 15 '18 18:06 Drewsov

@coopy I too was looking into adding more custom buttons support,

In https://github.com/draft-js-plugins/draft-js-plugins/tree/master/draft-js-buttons, they have injected the <sub> and <sup> tags in. I am studying their code to see how they did it.

williamli avatar Sep 18 '18 01:09 williamli

Any news on this?

flycj avatar Oct 31 '19 11:10 flycj

Hi guys, I am back working at draft-js will post the PR soon.

Any news on this?

flycj avatar Oct 31 '19 11:10 flycj

Any update on this? :)

VivekNeel avatar Mar 11 '20 14:03 VivekNeel

aa

VivekNeel avatar Mar 11 '20 14:03 VivekNeel

+1

jkevingutierrez avatar Jul 05 '20 19:07 jkevingutierrez

Any update?

BiancaArtola avatar Jan 13 '21 14:01 BiancaArtola

any update ?

Nassimadebeo avatar May 06 '21 10:05 Nassimadebeo

Hello, please give me a sign if this is implemented 👍🏾 ;)

ks-krimi avatar Aug 16 '22 17:08 ks-krimi

any update?

Hipposhark avatar Oct 23 '22 07:10 Hipposhark

if anyone is still looking for a solution, i eventually settled on the package draft-convert (https://www.npmjs.com/package/draft-convert). it is able to convert the draft state to html and back to draft state, and you can declare all of the inline styles you want such as colors and links.

Hipposhark avatar Oct 28 '22 21:10 Hipposhark