Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

White spaces removed after <span>, <a>, <b>, etc #4

Closed
dalescher opened this issue Nov 11, 2020 · 9 comments
Closed

White spaces removed after <span>, <a>, <b>, etc #4

dalescher opened this issue Nov 11, 2020 · 9 comments
Assignees
Labels

Comments

@dalescher
Copy link

dalescher commented Nov 11, 2020

Thank you for this middleware. It's working better than django-htmlmin regarding per-view caching. However, the minifed code removes the white spaces after some tags (<span>, <a>, <b>, etc.).
Is there a way to do it in a more clever way so we do not need to hardcode &nbsp; each time we use such tags?

@xfenix
Copy link
Owner

xfenix commented Nov 15, 2020

Thank you for feedback!

Can you specify more information?
Are you talking about something like this: <span>something</span> going here ==> <span>something</span>going here?

Hmm. It may be because of https://github.com/xfenix/django-hmin/blob/master/hmin/base.py#L15 bad regular expression, where i lost closing slash exclusion (so it intents to do no harm, suppose to clean spaces after open tags, not closing). I may patch it up with more clever regexp, because it obviously a bug.

@xfenix xfenix self-assigned this Nov 15, 2020
@xfenix
Copy link
Owner

xfenix commented Nov 15, 2020

Yeap, i found that my fixtures all filled with this behaviour. No doubt — it is bug.

@xfenix xfenix added the bug label Nov 15, 2020
@dalescher
Copy link
Author

dalescher commented Nov 15, 2020

I found a workaround. I hard installed hmin in my django project and commented out the following in base.py:
# data_input = RE_LEFT_SPACE_AFTER_OPEN_TAG.sub(r"\1", data_input)
Still have the minification but no more problem with spaces :)

I do not know if it's a good way though.

xfenix added a commit that referenced this issue Nov 15, 2020
…tion middleware, light refactoring. Regress test addded.
@xfenix
Copy link
Owner

xfenix commented Nov 15, 2020

In those case you get some extra spaces, but it was legit for situation.

Now i fixed this. You can install new 0.5.4 version, it has no this bug. Also i added python 3.9 tests and slightly optimize middleware.
Thanks for bugreport! It helps a lot!

@xfenix
Copy link
Owner

xfenix commented Nov 15, 2020

Please, let me know, if you experience another issues or this issue will strike back in other scenarios.

@dalescher
Copy link
Author

hum, I still have the same issue with the new modifications. I still have to comment out

data_input = RE_LEFT_SPACE_AFTER_OPEN_TAG.sub(r"\1", data_input)

to make it works, am I missing something? I just modified all the following files by copy pasting your new versions:
base.py
middleware.py

@xfenix
Copy link
Owner

xfenix commented Nov 15, 2020

It's better to install from pypi.

('<span> good text </span> for all people', '<span>good text</span> for all people'),
also please check regression test, it checks your case.
If you still have this issue, please provide example (before/after minifcation). Don't forget to clean caches, it may be because of them.

@xfenix xfenix closed this as completed Dec 4, 2020
@Dheirya
Copy link

Dheirya commented Jun 26, 2021

I'm still having this issue, and I cleaned the caches. I also tried using the # data_input = RE_LEFT_SPACE_AFTER_OPEN_TAG.sub(r"\1", data_input)

Which doesn't work.

@xfenix
Copy link
Owner

xfenix commented Jun 27, 2021

Do you have installed version 0.5.4?
If you do, please, provide some examples of wrong behaviour

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants