diff --git a/etherdump/commands/html5tidy.py b/etherdump/commands/html5tidy.py index 0b31e57..fa02b15 100644 --- a/etherdump/commands/html5tidy.py +++ b/etherdump/commands/html5tidy.py @@ -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: + # + # 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: diff --git a/etherdump/commands/pull.py b/etherdump/commands/pull.py index 31847dd..15a9b04 100644 --- a/etherdump/commands/pull.py +++ b/etherdump/commands/pull.py @@ -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)