Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextEditor: nested lists not semantically returned #7524

Open
maximlt opened this issue Nov 26, 2024 · 0 comments
Open

TextEditor: nested lists not semantically returned #7524

maximlt opened this issue Nov 26, 2024 · 0 comments
Labels
type: bug Something isn't correct or isn't working

Comments

@maximlt
Copy link
Member

maximlt commented Nov 26, 2024

Nested lists entered in the TextEditor aren't returned semantically nested on the value parameter. Instead, they're returned flattened and with some custom classes (ql-indent-<level>) that Quill, the Javascript library used to implement the editor, uses in the editor to visually indent the items.

import panel as pn

pn.extension('texteditor')

nested_bullets = """
<h2>A Nested List</h2>
<p>Lists can be nested (list inside list):</p>

<ul>
  <li>Coffee</li>
  <li>Tea
    <ul>
      <li>Black tea</li>
      <li>Green tea</li>
    </ul>
  </li>
  <li>Milk</li>
</ul>
"""

editor = pn.widgets.TextEditor(value=nested_bullets)
html = pn.pane.HTML(w.param.value)

pn.Row(editor, html).servable()

Image
Image

This is apparently a pretty old issue in the Quill (slab/quill#979) . In Panel, we get the content of the editor in the front-end using innerHTML (

this.model.text = this._editor.innerHTML
) ), so we get the “incorrect” HTML that library uses. Potential solutions:

  1. Update the TextEditor to use getSemanticHTML instead of innerHTML that was added in Quill 2.0 (https://quilljs.com/docs/api#getsemantichtml):
    • We are is still using Quill 1 (intention was to update Quill when it would officially support being rendered in the Virtual DOM which isn’t yet the case), so that needs to be updated first
    • Check whether getSemanticHTML is really a good fit (e.g. search related issues) and doesn't introduce other discrepancies.
  2. Look for other alternatives like Fix for Quill.js issue with list indent (use of css class instead of pure HTML) or https://github.com/nozer/quill-delta-to-html
  3. Implement the conversion of nested lists in Python

Preference for option 1.

@maximlt maximlt added the type: bug Something isn't correct or isn't working label Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

No branches or pull requests

1 participant