syntax-tree / hast-util-select

utility to add `querySelector`, `querySelectorAll`, and `matches` support for hast

Home Page:https://unifiedjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Non-elements between adjacent and general sibling combinators should be skipped

wooorm opened this issue · comments

commented

This does not work:

    st.deepEqual(
      select(
        'h1 + p',
        u('root', [
          u('text', '\n'),
          h('p', 'Alpha'),
          u('text', '\n'),
          h('h1', 'Bravo'),
          u('text', '\n'),
          h('p', 'Charlie'),
          u('text', '\n'),
          h('p', 'Delta'),
          u('text', '\n'),
          h('div', [h('p', 'Echo')])
        ])
      ),
      h('p', 'Charlie'),
      'should return adjacent sibling (whitespace)'
    )

It does work if there is no inter-element whitespace.

Affects +, but probably also ~ and >

commented

To clarify, all non-element siblings are skipped:

<style>
  #a a + b {
    color: red;
  }
  #b a ~ b {
    color: red;
  }
</style>
<div id=a>
  <a>Lorem</a> ipsum <b>dolor</b> sit <i>amet</i> sed <b>do</b> eiusmod <i>tempor</i>.
</div>
<div id=b>
  <a>Lorem</a> ipsum <b>dolor</b> sit <i>amet</i> sed <b>do</b> eiusmod <i>tempor</i>.
</div>

Screenshot 2020-02-27 at 2 29 09 pm