holtwick / zeed-dom

🌱 Lightweight offline DOM
MIT License
33 stars 5 forks source link

Descendant CSS selector type not supported #10

Open haydenbleasel opened 4 months ago

haydenbleasel commented 4 months ago

Hi! Wanted to cross-reference a bug I'm investigating in Tiptap: https://github.com/ueberdosis/tiptap/issues/4089

Currently when parsing the following HTML:

<div data-youtube-video>
        <iframe src="https://www.youtube.com/watch?v=cqHqLQgVCgY"></iframe>
</div>

It results in:

Unknown CSS selector type descendant div[data-youtube-video] iframe [
  { type: 'tag', name: 'div', namespace: null },
  {
    type: 'attribute',
    name: 'data-youtube-video',
    action: 'exists',
    value: '',
    namespace: null,
    ignoreCase: null
  },
  { type: 'descendant' },
  { type: 'tag', name: 'iframe', namespace: null }
]

Looks like descendant support is in the code but commented out, either:

  1. Here: https://github.com/holtwick/zeed-dom/blob/6a2d6694ed879da9444d9b7c1826cef4b23c8a17/src/vcss.ts#L103
  2. or here: https://github.com/holtwick/zeed-dom/blob/6a2d6694ed879da9444d9b7c1826cef4b23c8a17/src/vcss.ts#L106

I'll keep digging and hopefully open a PR if I can manage to fix it.

holtwick commented 4 months ago

It's true, descendants are currently not supported. It would indeed be nice to have such a feature.

It might require some recursive calls. The code is already prepared quite well for such an extension.

If you could contribute a PR, I would be more than happy to merge it. Thanks.