Issue #698Opened January 2, 2018by alimajed930 reactions

editor.getSelected().toHTML() is not consistent

Question

Hi everyone,

I created a new component type, 'html-block', which is a component in which you can add your html code. I added an 'Edit' button to the toolbar, to enable the user editing the added html code. In order to show the html code of the component in the modal, I am using the function 'editor.getSelected().toHTML()';

The problem is that, sometimes the code returned is per example: <div><h1>h1</h1></div> (which is what I need, since I need the exact code that the user added at first), and sometimes it returns something like that: <div id='135'><h1>h1</h1></div> (with an id added automatically). I also tried to use 'editor.getSelected().em.getHtml()' but the same issue occurred.

How can I solve that and retrieve the exact html code that the user entered ?

Thank you in advance.

Answers (3)

artfJanuary 4, 20180 reactions

Inside your html-block component create a new property (eg. custom-code) for user's code and retrieve it with editor.getSelected().get('custom-code')

alimajed93January 4, 20180 reactions

This solved the problem for me. Thank you.

lock[bot]September 18, 20190 reactions

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.