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

Unexpected list element hoisting #168

Closed
4 tasks done
geoffgscott opened this issue Mar 19, 2024 · 2 comments
Closed
4 tasks done

Unexpected list element hoisting #168

geoffgscott opened this issue Mar 19, 2024 · 2 comments
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on

Comments

@geoffgscott
Copy link

geoffgscott commented Mar 19, 2024

Initial checklist

Affected packages and versions

rehype-parse@9.0.0

Link to runnable example

https://codesandbox.io/p/devbox/loving-borg-9p5c5q?file=%2Fsrc%2Findex.ts%3A11%2C7

Steps to reproduce

When using <li> elements inside of tags that are not <ul> the nested children get hoisted out. In the codepen I have used the custom tag <custom_list> but the same behavior occurs with standard <div> tags.

Input:

<custom_list>
  <li>
    <p>Text</p>
  </li>
  <li>
    <custom_list>
      <li><p>Nested Text</p></li>
    </custom_list>
  </li>
</custom_list>

Output:

<custom_list>
  <li>
    <p>Text</p>
  </li>
  <li>
    <custom_list>
    </custom_list>
  </li>
  <li><p>Nested Text</p></li>
</custom_list>

Expected behavior

The nested list item should be maintained as child of element inside the <li> tag

Actual behavior

The child of the element inside the <li> tag is hoisted up 1 level.

Runtime

Other (please specify in steps to reproduce)

Package manager

pnpm

OS

Linux

Build and bundle tools

Vite

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Mar 19, 2024
@wooorm
Copy link
Member

wooorm commented Mar 20, 2024

Hey Geoff!

This is how HTML works.

let x = `<div>
  <custom_list>
    <li>
      <p>Text</p>
    </li>
    <li>
      <custom_list>
        <li><p>Nested Text</p></li>
      </custom_list>
    </li>
  </custom_list>
</div>
`

const y = document.createElement('div');
y.innerHTML = x
console.log(y.innerHTML)
<div>
  <custom_list>
    <li>
      <p>Text</p>
    </li>
    <li>
      <custom_list>
        </custom_list></li><li><p>Nested Text</p></li>
      </custom_list>
    
  
</div>

You need to stick with the rules of the HTML language. You can’t have lis in random elements.
(and if you want custom elements, use - instead of _ in the name.)

@wooorm wooorm closed this as not planned Won't fix, can't repro, duplicate, stale Mar 20, 2024
@wooorm wooorm added the 🙋 no/question This does not need any changes label Mar 20, 2024

This comment has been minimized.

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants