Knio / dominate

Dominate is a Python library for creating and manipulating HTML documents using an elegant DOM API. It allows you to write HTML pages in pure Python very concisely, which eliminate the need to learn another template language, and to take advantage of the more powerful features of Python.
GNU Lesser General Public License v3.0
1.72k stars 108 forks source link

meta tag issues #116

Closed Aladio closed 4 years ago

Aladio commented 5 years ago

meta tag issues

input with doc.head: meta('content="text/html;charset=utf-8", http-equiv="Content-Type"') meta('content="utf-8", http-equiv="encoding"') output <meta> <meta>

input with doc.head: meta(raw('content="text/html;charset=utf-8" http-equiv="Content-Type"')) meta(raw('content="utf-8" http-equiv="encoding"')) output <meta> <meta>

lachlankidson commented 5 years ago

Try using dictionary unpacking to get around having a hyphen in the keyword:

with doc.head:
    meta(**{'content': 'text/html;charset=utf-8', 'http-equiv': 'Content-Type'})
    meta(**{'content': 'utf-8', 'http-equiv': 'encoding'})

print(doc)

Output

<!DOCTYPE html>
<html>
  <head>
    <title>Dominate your HTML</title>
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
    <meta content="utf-8" http-equiv="encoding">
  </head>
  <body></body>
</html>
lachlankidson commented 5 years ago

meta(content='utf-8', **{'http-equiv': 'encoding'}) is also valid.

Aladio commented 5 years ago

Thank you!!

------ Original Message ------ From: "Lachlan Kidson" notifications@github.com To: "Knio/dominate" dominate@noreply.github.com Cc: "Aladio" faladio@yahoo.com; "Author" author@noreply.github.com Sent: 10/15/2019 8:53:11 AM Subject: Re: [Knio/dominate] meta tag issues (#116)

Try using dictionary unpacking https://docs.python.org/3.7/tutorial/controlflow.html#unpacking-argument-lists to get around having a hyphen in the keyword:

with doc.head: meta({'content': 'text/html;charset=utf-8', 'http-equiv': 'Content-Type'}) meta({'content': 'utf-8', 'http-equiv': 'encoding'})

print(doc)

Output

<!DOCTYPE html>

Dominate your HTML

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Knio/dominate/issues/116?email_source=notifications&email_token=AAYKVBOMMNQ5ZBNG4GGYXUTQOXKNPA5CNFSM4I5YVVKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBJB75A#issuecomment-542253044, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAYKVBLTMNTFEIZTWANER43QOXKNPANCNFSM4I5YVVKA.

golightlyb commented 5 years ago

This is special-cased so you can use an underscore: http_equiv:

from dominate.tags import meta

expected = '<meta content="text/html;charset=utf-8" http-equiv="Content-Type">'

assert meta(content="text/html;charset=utf-8", http_equiv="Content-Type").render() == expected