react-rte icon indicating copy to clipboard operation
react-rte copied to clipboard

How to render align styles text on react-rte

Open zilkenberg22 opened this issue 4 years ago • 3 comments

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?

zilkenberg22 avatar Feb 18 '21 03:02 zilkenberg22

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}
/>

dgruseck avatar Jun 05 '21 15:06 dgruseck

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

camkon avatar May 29 '23 16:05 camkon

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

gezimra avatar Sep 11 '23 09:09 gezimra