django-htmlmin icon indicating copy to clipboard operation
django-htmlmin copied to clipboard

Noscript tag stop working in html on adding MarkRequestMiddleware class in django

Open Ajeetlakhani opened this issue 7 years ago • 5 comments

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.

Ajeetlakhani avatar May 16 '17 09:05 Ajeetlakhani

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 avatar Jul 11 '17 20:07 jlariza

@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.

thornycrackers avatar Feb 05 '18 17:02 thornycrackers

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'

ryanbagwell avatar Aug 01 '18 15:08 ryanbagwell

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...

benzkji avatar Nov 20 '18 17:11 benzkji

and....html5lib==1.0.1 solves this problem for me...

benzkji avatar Nov 20 '18 19:11 benzkji