GetmeUK / ContentTools

A JS library for building WYSIWYG editors for HTML content.
http://getcontenttools.com
MIT License
3.95k stars 393 forks source link

ContentTools does not work with child element #496

Closed anhducbkhn closed 6 years ago

anhducbkhn commented 6 years ago

My Env:

this is my index.html:

<div  data-editable data-name="main-content">
<blockquote>
   <ul>
            <li> test 1</li>
            <li> test 2</li>
          </ul>
   </blockquote>
</div>

This is my editor.js:

window.addEventListener('load', function() {
  var editor;

  editor = ContentTools.EditorApp.get();
  editor.init('*[data-editable]', 'data-name');

It works.

But when i changed my index.html:

<div data-editable data-name="main-content">
   <div>    
    <blockquote>
         <ul>
            <li> test 1</li>
            <li> test 2</li>
          </ul>
   </blockquote>
  </div>
</div>

it does not working anymore, seems it cannot detect the ul element inside a div.

Please help!

anthonyjb commented 6 years ago

This is the expect behaviour. ContentTools converts any element type that doesn't directly map to an editable element (in this case a div tag) to a static (non-editable) element.

Likewise I'm surprised that you can edit the list within the blockquote tag initially as blockquotes are converted to text elements which can't have block level children, I suspect this is working purely because the content is being converted to a contenteditable format, that is the ul is not being edited using CT but the native browser functionality.

anhducbkhn commented 6 years ago

yes thanks @anthonyjb