django-htmlmin
django-htmlmin copied to clipboard
Noscript tag stop working in html on adding MarkRequestMiddleware class in django
I want to use style tag inside noscript tag to add a fallback message but style tag inside noscript tag gets minified and rendered as string.
I am getting the same issue; and it is very problematic when trying to use amp because the "
It may be related with https://github.com/html5lib/html5lib-python/issues/104 But I am not sure.
Thank you,
@jlariza You are correct, the issue is with html5lib
. To circumvent this issue I just changed the parser inside of django-htmlmin/blob/master/htmlmin/minify.py (Line 52)
def html_minify(html_code, ignore_comments=True, parser="html5lib"):
html_code = force_text(html_code)
# soup = bs4.BeautifulSoup(html_code, 'html.parser')
soup = bs4.BeautifulSoup(html_code, parser)
mini_soup = space_minify(soup, ignore_comments)
The comment is my changed line. I changed it to mirror the Quickstart documentation from BeautifulSoup:
https://www.crummy.com/software/BeautifulSoup/bs4/doc/index.html
after that my issues went away.
There's an undocumented html5 parser setting that you can use to specify the parser. So just add the following to your django settings:
HTML_MIN_PARSER = 'html.parser'
as far as I know, there are other issues when not using html5lib? any experiences? maybe @andrewsmedina has some insights to share?
I am using html.parser
for now, and it seems to work well...
and....html5lib==1.0.1 solves this problem for me...