question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to render these plugins from raw content state in "readOnly" mode

See original GitHub issue

I made the plugins work under the Editor tag, and I can type inline block like bold, underline,… etc. I also install plugins like Linkify, Mentions and Emoji, it shows correctly in the editing box.

But it just show a plain text when rendering it in HTML for the links and mentions, and some of the Emoji did not show correctly, for the one shows correctly, the CSS looks very different.

What I did is that converting editor state to raw state let rawState = convertToRaw(this.state.editorState.getCurrentContent() then, create a editorState for rendering as follows const blocks = convertFromRaw(rawState); this.state = {editorState: EditorState.createWithContent(blocks)}; and try to rendering it using Editor with readOnly={true}, Defining the rendering component like

render(){
    return <div className="RichEditor-root message-display-root">
            <div className="RichEditor-editor message-display-editor">
                <Editor
                    blockStyleFn={getBlockStyle}
                    customStyleMap={styleMap}
                    editorState = {this.state.editorState}
                    readOnly={true}
                    plugins={plugins}
                    onChange={()=>{}}
                    />
            </div>
    </div>;
}

All the inline style show correctly (Bold, Underline, Blockquote, UL, OL, …etc), just these plugins does not show correctly when trying to render it in HTML. When inspecting the element, some of the class and element shows quite different, like there will be draftJsMentionPlugin__mention__29BEd class for the mention shown in editing box, but not shown in the readOnly part of the HTML page.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

22reactions
mzbaccommented, Nov 7, 2016

it may sounds silly, but draftjs-plugin editor is using onchange to mount the decorators to editorState. so I think even your editor is on readOnly you still need to pass onchange ={ (editorState) => this.setState({editorState}}

5reactions
danieloicommented, Jun 10, 2020

I had to pass the decorators from my plugins to the editor when it was in readOnly mode to make sure my links and mentions rendered properly

const plugins = [mentionPlugin, linkifyPlugin, hashtagPlugin]; const decorators = flattenDeep(plugins.map((plugin) => plugin.decorators)); const decorator = new CompositeDecorator( decorators.filter((decorator, index) => index !== 1) );

and then I create my editor state like so

const content = convertFromRaw(editorContent); const editorState = EditorState.createWithContent(content, decorator);

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Put WordPress in a Read Only Mode (The Easy Way)
In this article, we will show you how you can put your WordPress site in a read only mode for site migrations and...
Read more >
Draft JS, mention plugin renders as plain text - Stack Overflow
Make sure to add mention plugin css file . import 'draft-js-mention-plugin/lib/plugin.css';.
Read more >
Accessibility - React
The Web Content Accessibility Guidelines provides guidelines for creating accessible web sites. The following WCAG checklists provide an overview:.
Read more >
Table | Components - BootstrapVue
See Primary Key, below, for ways to minimize Vue's re-rendering of rows. items array records ... This is <i>escaped</i> content, This is raw...
Read more >
Rendering - Slate
Whether the editor is in "read-only" mode, where all of the rendering is the same, but the user is prevented from editing the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found