sstur / react-rte

Pure React rich text WYSIWYG editor based on draft-js.
https://react-rte.org
ISC License
2.86k stars 430 forks source link

How to render align styles text on react-rte #402

Open zilkenberg22 opened 3 years ago

zilkenberg22 commented 3 years ago

The text-value has the style <p style="text-align: center"> but the styles are lost after RichTextEditor.createValueFromString(props.text, 'html'). Is there a way I can retain the styles from the saved text-values inside the editor?

dgruseck commented 3 years ago

Hi,

3 things you need to do for display, saving and importing:

import RichTextEditor, {
  getTextAlignClassName,
  getTextAlignStyles,
  getTextAlignBlockMetadata,
} from 'react-rte';

// create value from html
RichTextEditor.createValueFromString(
  text,
  'html',
  {
    customBlockFn: getTextAlignBlockMetadata,
  }
)

// save html
this.state.text.toString(
  'html',
  {
     blockStyleFn: getTextAlignStyles,
  })

// render TextEditor
<RichTextEditor
  value={this.state.text}
  blockStyleFn={getTextAlignClassName}
/>
camkon commented 1 year ago

Thanks. This works just fine. Also, is there a way with this around markdown format?

gezimra commented 1 year ago

Hello, I'm using version "^0.16.5" and I cannot find { getTextAlignClassName, getTextAlignStyles, getTextAlignBlockMetadata } exported from 'react-rte'.