Code Monkey home page Code Monkey logo

Comments (4)

fb55 avatar fb55 commented on June 21, 2024 1

Hi @0x0a0d, thanks for opening this, and sorry for never responding. I agree that the current DOM structure isn't ideal, and I am thinking about how to improve it. You point at real issues with the current types, and I'd like to keep the issue open — hope that's okay!

from domutils.

fb55 avatar fb55 commented on June 21, 2024

Okay, let's address this:

  1. The issue here is el.parent?.name === 'body', as the parent isn't guaranteed to be a tag (it could also be the document). You can work around this with an additional check: el.parent?.type === 'tag' && el.parent.name === 'body'.
  2. getElements is inherited from the original node-htmlparser project and provides filters for any kind of node. For a simple name filter, you can use getElementsByTagName; this will only return elements.
  3. find similarly allows you to get any kind of node, while findAll is limited to elements. Agreed that this is confusing. I have added a documentation comment for now.

from domutils.

0x0a0d avatar 0x0a0d commented on June 21, 2024

I found the correct way to do it

DomUtils.find(el=> el instanceof Element /* && any conditions */, children, false, 10) as Element[]

from domutils.

fb55 avatar fb55 commented on June 21, 2024

I think most of this has been resolved, even though there are still plenty of casts and type checks that are necessary.

from domutils.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.