Commit 32dacb00 authored by Michael Murtaugh's avatar Michael Murtaugh
Browse files

added meta viewport to dhtml output

parent 7599c70b
......@@ -43,7 +43,8 @@ def pluralize (x):
else:
return (x,)
def html5tidy (doc, charset="utf-8", title=None, scripts=None, links=None, indent=False):
def html5tidy (doc, charset="utf-8", title=None, scripts=None, links=None, indent=False, viewport_meta=None):
if scripts:
script_srcs = [x.attrib.get("src") for x in doc.findall(".//script")]
for src in pluralize(scripts):
......@@ -74,6 +75,14 @@ def html5tidy (doc, charset="utf-8", title=None, scripts=None, links=None, inden
if not meta_charsets:
meta = ET.SubElement(doc.find(".//head"), "meta", charset=charset)
# to add:
# <meta name="viewport" content="width=device-width,initial-scale=1">
# use viewport_meta="width=device-width,initial-scale=1"
if viewport_meta:
meta_viewports = [x.attrib.get("content") for x in doc.findall(".//meta") if x.attrib.get("name") == "viewport"]
if not meta_viewports:
meta = ET.SubElement(doc.find(".//head"), "meta", name="viewport", content=viewport_meta)
if title != None:
titleelt = doc.find(".//title")
if not titleelt:
......
......@@ -221,7 +221,7 @@ def main (args):
ver["url"] = quote(ver["path"])
# doc = html5lib.parse(html, treebuilder="etree", override_encoding="utf-8", namespaceHTMLElements=False)
doc = html5lib.parse(html, treebuilder="etree", namespaceHTMLElements=False)
html5tidy(doc, indent=True, title=padid, scripts=args.script, links=links)
html5tidy(doc, indent=True, title=padid, scripts=args.script, links=links, viewport_meta="width=device-width,initial-scale=1")
with open(ver["path"], "w") as f:
# f.write(html.encode("utf-8"))
print(ET.tostring(doc, method="html", encoding="unicode"), file=f)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment