Code Monkey home page Code Monkey logo

Comments (4)

fb55 avatar fb55 commented on June 17, 2024

Added docs!

from domutils.

brewern avatar brewern commented on June 17, 2024

Can we get examples for how to use some of these utils?

I'm having trouble getting the following to work:

const handler = new DomHandler(function(err, dom) {
  const elements = findAll((elem) => (elem.type === "tag" && getAttributeValue(elem, 'data-epub-custom')), dom);
  const shortcode = parseDOM('<div>test</div>');
  elements.forEach((element) => replaceElement(element, shortcode));
});

I'm trying to get elements based on a data attribute, then replace each matching element. I'm returning elements, but it's mutating dom in anyway. I'm sure I'm missing how this is suppose to work.

from domutils.

fb55 avatar fb55 commented on June 17, 2024

@brewern Your snippet is currently not passing data to DomHandler. You could use parseDOM to get a DOM tree to manipulate later on (it is using DomHandler under the hood).

from domutils.

ilan-schemoul avatar ilan-schemoul commented on June 17, 2024

Added docs!

Maybe, it would be great to have in the readme a complete example of loading an HTML string and then appending etc. A month ago I decided to use cheerio instead of this package now I realised that it takes 1 second per document when I want to generate 700 html (SSR, I generate HTML on build time) and I would also be interested by knowing the performance differences between this package and cheerio :)
Oh in src there are some .spec files. They are super helpful (espacially the "makedom" in utils)

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.