Http-equiv meta tag


where the <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> came from in the Plone pages? We would like to drop it and use <meta charset="utf-8" />.

That's interesting, the meta header in main_template was already changed in 2017, but that was on master:

Plone 5.2.x branch still has the content attribute as well:

If you render a page in Plone 6, you will see the http-equiv meta tag. It is not in the main_template, I suppose.

This is coming from the theme: plonetheme.barceloneta/index.html at a0df3545a5d6c2dd0198fe30ceea96e9eddf5db9 · plone/plonetheme.barceloneta · GitHub

It was changed 3 months ago.

If you try to remove it or do a custom theme, it is still there.

The page above is a demo, the real index is this: and I'm running it. If you render the page, http-equiv get in. Maybe it came from Zope 5.3.0?

It is really strange, if you grep 'http-equiv' it is read and used in just one zmi template and something else in read, but nowhere else. It does not appear anywhere in Plone.

I've found this:

tostring(doc, pretty_print=False, include_meta_content_type=False, encoding=None, method=' html ', with_tail=True, doctype=None) source code

Return an HTML string representation of the document.

Note: if include_meta_content_type is true this will create a <meta http-equiv="Content-Type" ...> tag in the head; regardless of the value of include_meta_content_type any existing <meta http-equiv="Content-Type" ...> tag will be removed

but the default seems False. But maybe worth a check?

but the default seems False. But maybe worth a check?

Sigh. That could very well be true and valuable to check. I thought quickly about Diazo when replying but left it out in my first respone.

I had an issue years ago where <!DOCTYPE html> appeared twice in the html or conflicted with the html4/xhtml version, which was also added by lxml.

[edit: fix escaping of html in the text]

1 Like

@yurj pointed me here, as I wrote an issue as it seems doctype and namespace don't match...

1 Like

ok little digging: HTML html xmlns Attribute

"The xmlns attribute is required in XHTML, invalid in HTML 4.01, and optional in HTML5."
"This is because the namespace "xmlns=" is default, and will be added to the <html> tag even if you do not include it."

so its ok to have it there even in html5 - I'll close my ticket :wink:

1 Like

Well ... some investigations on the http-equiv meta tag:

I finally landed via plone.transformchain in the module repoze.xmliter.serialize where a lxml.etree object simply gets stringified (repoze.xmliter/ at master · repoze/repoze.xmliter · GitHub) ... before this the results of [e.attrib for e in self.tree.xpath("//meta")] is:

    {'charset': 'utf-8'},
    {'name': 'viewport', 'content': 'width=device-width, initial-scale=1.0'},
    {'name': 'generator', 'content': 'Plone -'}

after str(self.tree) the result startswith:

'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" class="h-100" lang="de" xml:lang="de">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

so the http-equiv was added to the tree ... now googling about this the only result I've found was this comment on stackoverflow python - Not to escape attribute contents in lxml (python3)? - Stack Overflow where it says:

...The str(result) approach does work but has several problems:
(1) It automatically adds <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> (NOT a valid xhtml) just after the <head> tag;...

wow ... but I do not really know how to get rid of this. I think I file an issue on the lxml repository and look what's the response :face_with_monocle:

1 Like