Search code examples
ckeditorckeditor4.x

How to make CKEditor insert list into paragraph?


I have some paragraph in CKEditor and I want to insert bulleted list into it.

But it seems like it is impossible: clicking List icon turns my paragraph into list, but does not insert the list into the existing paragraph. So I have to switch to Source mode to do it manually.

How to make CKEditor insert the new list into the existing paragraph?


Solution

  • It's impossible to insert list into paragraph per HTML specification:

    A p element's end tag can be omitted if the p element is immediately followed by an address, article, aside, blockquote, details, div, dl, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6, header, hgroup, hr, main, menu, nav, ol, p, pre, section, table, or ul element

    What's more, browsers replace <p><ul></ul></p> with <p></p><ul></ul><p></p>, so it's really not possible to do that. Therefore CKEditor 4 does not allow it.

    There is also en example inside the specification how to link paragraph with list, in "Note" section:

    <p>For instance, this fantastic sentence has bullets relating to</p>
    <ul>
        <li>wizards,
        <li>faster-than-light travel, and
        <li>telepathy,
    </ul>
    <p>and is further discussed below.</p>