{ "info": { "author": "Dan McDougall", "author_email": "daniel.mcdougall@liftoffsoftware.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable" ], "description": "The htmltag module\r\n==================\r\n.. note::\r\n\r\n The latest, complete documentation of htmltag can be found here:\r\n http://liftoff.github.io/htmltag/\r\n\r\n The latest version of this module can be obtained from Github:\r\n https://github.com/LiftoffSoftware/htmltag\r\n\r\nhtmltag.py - A Python (2 *and* 3) module for wrapping whatever strings you want\r\nin HTML tags. Example::\r\n\r\n >>> from htmltag import strong\r\n >>> print(strong(\"SO STRONG!\"))\r\n SO STRONG!\r\n\r\nWhat tags are supported? All of them! An important facet of modern web\r\nprogramming is the ability to use your own custom tags. For example::\r\n\r\n >>> from htmltag import foobar\r\n >>> foobar('Custom tag example')\r\n 'Custom tag example'\r\n\r\nTo add attributes inside your tag just pass them as keyword arguments::\r\n\r\n >>> from htmltag import a\r\n >>> print(a('awesome software', href='http://liftoffsoftware.com/'))\r\n awesome software\r\n\r\nTo work around the problem of reserved words as keyword arguments (i.e. can't\r\nhave 'class=\"foo\"') just prefix the keyword with an underscore like so::\r\n\r\n >>> from htmltag import div\r\n >>> print(div(\"example\", _class=\"someclass\"))\r\n
example
\r\n\r\nAnother option--which is useful for things like 'data-\\*' attributes--is to pass\r\nkeyword arguments as a dict using the `\\*\\* operator\r\n`_\r\nlike so::\r\n\r\n >>> from htmltag import li\r\n >>> print(li(\"CEO\", **{\"class\": \"user\", \"data-name\": \"Dan McDougall\"}))\r\n
  • CEO
  • \r\n\r\nIf you want to use upper-case tags just import them in caps:\r\n\r\n >>> from htmltag import STRONG\r\n >>> print(STRONG('whatever'))\r\n whatever\r\n\r\nCombining Tags and Content\r\n--------------------------\r\nYou can combine multiple tags to create a larger HTML string like so::\r\n\r\n >>> from htmltag import table, tr, td\r\n >>> print(table(\r\n ... tr(td('100'), td('200'), id=\"row1\"),\r\n ... tr(td('150'), td('250'), id=\"row2\"),\r\n ... ))\r\n
    100200
    150250
    \r\n\r\n**NOTE:** If you're going to do something like the above please use a *real*\r\ntemplate language/module instead of `htmltag`. You're *probably* \"doing it\r\nwrong\" if you end up with something like the above in your code. For example,\r\ntry `Tornado's template engine\r\n`_.\r\n\r\nSpecial Characters\r\n------------------\r\nSpecial characters that cause trouble like, '<', '>', and '&' will be\r\nautomatically converted into HTML entities. If you don't want that to happen\r\njust wrap your string in :class:`htmltag.HTML` like so::\r\n\r\n >>> from htmltag import HTML, a\r\n >>> txt = HTML(\"I am already HTML. Don't escape me!\")\r\n >>> a(txt, href=\"http://liftoffsoftware.com/\")\r\n 'I am already HTML. Don\\'t escape me!'\r\n\r\nSince Python doesn't allow modules to have dashes (-) in their names, if you\r\nneed to create a tag like that just use an underscore and change its 'tagname'\r\nattribute::\r\n\r\n >>> from htmltag import foo_bar\r\n >>> print(foo_bar('baz')) # Before\r\n 'baz'\r\n >>> foo_bar.tagname = 'foo-bar'\r\n >>> print(foo_bar('baz')) # Before\r\n 'baz'\r\n\r\nBy default self-closing HTML tags like '' will not include an ending slash.\r\nTo change this behavior (i.e. for XHTML) just set 'ending_slash' to `True`::\r\n\r\n >>> from htmltag import img\r\n >>> img.ending_slash = True\r\n >>> img(src=\"http://somehost/images/image.png\")\r\n ''\r\n >>> img.ending_slash = False # Reset for later doctests\r\n\r\nProtections Against Cross-Site Scripting (XSS)\r\n----------------------------------------------\r\nBy default all unsafe (XSS) content in HTML tags will be removed::\r\n\r\n >>> from htmltag import a, img\r\n >>> a(img(src=\"javascript:alert('pwned!')\"), href=\"http://hacker/\")\r\n '(removed)'\r\n\r\nIf you want to change this behavior set the tag's 'safe_mode' attribute like\r\nso::\r\n\r\n >>> from htmltag import a, img\r\n >>> a.safe_mode = False\r\n >>> img.safe_mode = False\r\n >>> a(img(src=\"javascript:alert('pwned!')\"), href=\"http://hacker/\")\r\n ''\r\n >>> a.safe_mode = True # Reset for later doctests\r\n >>> img.safe_mode = True # Ditto\r\n\r\nYou may also change the replacement text if you like::\r\n\r\n >>> from htmltag import a, img\r\n >>> img.replacement = \"No no no!\"\r\n >>> a(img(src=\"javascript:alert('pwned!')\"), href=\"http://hacker/\")\r\n 'No no no!'\r\n\r\nIf you set 'replacement' to 'entities' the rejected HTML will be converted to\r\ncharacter entities like so::\r\n\r\n >>> from htmltag import a, img\r\n >>> a.replacement = \"entities\"\r\n >>> img.replacement = \"entities\"\r\n >>> a(img(src=\"javascript:alert('pwned!')\"), href=\"http://hacker/\")\r\n '<img src=\"javascript:alert(\\'pwned!\\')\">'\r\n\r\nIt is also possible to create a whitelist of allowed tags. All other tags\r\ncontained therein will automatically be replaced::\r\n\r\n >>> from htmltag import span\r\n >>> whitelist = ['span', 'b', 'i', 'strong']\r\n >>> span.whitelist = whitelist\r\n >>> span(HTML('This is bold new lib is '))\r\n 'This is bold new lib is (removed)awesome();(removed)'\r\n\r\nLastly, all strings returned by `htmltag` are actually a subclass of `str`:\r\n`~htmltag.HTML`. It has a useful `escaped` property:\r\n\r\n >>> from htmltag import address\r\n >>> address.safe_mode = False # Turn off so we have a dangerous example ;)\r\n >>> html = address('1 Hacker Ln., Nowhere, USA')\r\n >>> print(html)\r\n
    1 Hacker Ln., Nowhere, USA
    \r\n >>> print(html.escaped)\r\n <address>1 Hacker Ln., Nowhere, USA</address>\r\n\r\nThis can be extremely useful if you want to be double-sure that no executable\r\nstuff ends up in your program's output.\r\n\r\n\r\nFunctions and Classes\r\n=====================", "description_content_type": null, "docs_url": "https://pythonhosted.org/htmltag/", "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/LiftoffSoftware/htmltag", "keywords": "html5 html", "license": "Apache 2.0", "maintainer": "Dan McDougall", "maintainer_email": "daniel.mcdougall@liftoffsoftware.com", "name": "htmltag", "package_url": "https://pypi.org/project/htmltag/", "platform": "Any", "project_url": "https://pypi.org/project/htmltag/", "project_urls": { "Homepage": "https://github.com/LiftoffSoftware/htmltag" }, "release_url": "https://pypi.org/project/htmltag/1.7/", "requires_dist": null, "requires_python": null, "summary": "Python HTML tag interface", "version": "1.7" }, "last_serial": 1193973, "releases": { "1.7": [ { "comment_text": "", "digests": { "md5": "d3a4b810df9877ebf0239d642ee3c3bb", "sha256": "858d5ed06674a04650e07ea2cc66e834e878512f5289de20f5a1605d260f8bd3" }, "downloads": -1, "filename": "htmltag-1.7.tar.gz", "has_sig": false, "md5_digest": "d3a4b810df9877ebf0239d642ee3c3bb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12329, "upload_time": "2014-08-07T20:13:35", "url": "https://files.pythonhosted.org/packages/a6/34/a11d2ee1d7c85dde287a875566dc744dec675d651517859ffd5e71b9b2b3/htmltag-1.7.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d3a4b810df9877ebf0239d642ee3c3bb", "sha256": "858d5ed06674a04650e07ea2cc66e834e878512f5289de20f5a1605d260f8bd3" }, "downloads": -1, "filename": "htmltag-1.7.tar.gz", "has_sig": false, "md5_digest": "d3a4b810df9877ebf0239d642ee3c3bb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12329, "upload_time": "2014-08-07T20:13:35", "url": "https://files.pythonhosted.org/packages/a6/34/a11d2ee1d7c85dde287a875566dc744dec675d651517859ffd5e71b9b2b3/htmltag-1.7.tar.gz" } ] }