editor icon indicating copy to clipboard operation
editor copied to clipboard

[BUG] Numbered list with sub-list shows wrong numbers

Open shaipetel opened this issue 1 year ago • 6 comments

If you want to ask for support or request features, sponsor the project and contact me over email.

  • [x] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • [x] I have read the documentation and cannot find an answer.

Describe the bug If you have the following numbered list, with a sub list:

1. one
   1. sub 1
   2. sub 2
2. two
3. three

once you go to view source and back to rich text mode, or if you load the editor with this markdown as the current value - the numbered list after the sub list will be wrong, showing 3 instead of 2

Reproduction https://codesandbox.io/p/sandbox/mdx-editor-base-forked-vksdyj?file=%2Fsrc%2FApp.tsx

To Reproduce Steps to reproduce the behavior:

  1. add the above markdown
  2. switch to source and back to rich text
  3. bullet 2 is now 3

Expected behavior After a sub-list, bullets should continue normal numbering

Screenshots On load, or after edit: image

After switching to source and back: image

Desktop (please complete the following information):

  • OS: Windows
  • Browser Edge

Additional context This happens every time after a nested sub list, the next number on the higher level will jump to the next.

shaipetel avatar Jun 27 '24 17:06 shaipetel

I can confirm that this is bug; the weird thing is that it works initially, as there is no difference in the HTML after the toggle. There's probably a CSS-only solution that puts content into the markers or uses before for that purpose.

petyosi avatar Jul 02 '24 06:07 petyosi

Could you elaborate on the CSS only solution? I don't mind trying it.

shaipetel avatar Jul 09 '24 14:07 shaipetel

I found the problem in the generated HTML. MDX produces this html:

<ol>
  <li>Coffee</li>
  <li>Tea</li>
  <li><!-- extra LI element, not needed -->
    <ol>
      <li>Black tea</li>
      <li>Green tea</li>
    </ol>
  </li>
  <li>Milk</li>
</ol>

this is the correct html to nest list items:

<ol>
  <li>Coffee</li>
  <li>Tea
    <ol>
      <li>Black tea</li>
      <li>Green tea</li>
    </ol>
  </li>
  <li>Milk</li>
</ol>

MDX wrap the nested list inside a new LI element, instead of putting it inside the parent LI element

shaipetel avatar Jul 09 '24 14:07 shaipetel

Any update on this one?

natechenette avatar Nov 11 '24 22:11 natechenette

I'm also facing this issue. Any workarounds?

amymc avatar Nov 29 '24 12:11 amymc

I was able to target the marker in css and hide it

"& li:has(> ul)::marker": {
      color: "transparent",
 },

amymc avatar Dec 03 '24 14:12 amymc