Giter Club home page Giter Club logo

Comments (5)

Swaagie avatar Swaagie commented on August 20, 2024

Yeah this is a tricky one, consider the following: <strong>hello</strong> world and/or <a href=#>hello</a> world.

Currently the logic is if inline element and followed by text than remove additional spaces but keep one. The only thing I can think of to fix this is using the original input as reference. If text was originally concatenated then do not add a space, depends on references htmparser2 keeps though. If you have another way of fixing this, I'd like to hear it :)

from minimize.

tomByrer avatar tomByrer commented on August 20, 2024

Could the whitespace reduction not be ran until the (next to) last step? Then the whitespace routine will remove only adjacent whitespaces but still keep one inside block-level elements?

from minimize.

Swaagie avatar Swaagie commented on August 20, 2024

You might be on to something there, hopefully that information still resides in htmparser output somewhere. I'll check asap.

from minimize.

dskrepps avatar dskrepps commented on August 20, 2024

Well, htmlparser2 was updated between versions 3.3.0 and 3.4.0 such that text elements now have next and prev properties. Here's what I came up with: https://github.com/DSKrepps/minimize/commit/75ba00e0c1c43237b1340b3952290ee6dc95d02e

I've changed the behavior so now, instead of trimming all whitespace before adding it in certain cases, it checks for inline elements and collapses whitespace down to a space next to them. The text and tag functions were simplified. A few tests were updated, removed, and added to reflect the new behavior.

As far as I can tell, no changes in whitespace visible in the browser occur with this update, except Hello<a> <i>Erroneous</i> </a>World comes out as one word. This was present beforehand also.

Hope this helps.

from minimize.

Swaagie avatar Swaagie commented on August 20, 2024

Hello<a> <i>Erroneous</i> </a>World messes with my OCD anyways, the workaround is easy ofc ;)

from minimize.

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.