Skip to main content

A derivation of Nicolas Bessi's trivial port of Hiccup to Python

Project description

pyccup 0.1

Python version of clojure hiccup https://github.com/weavejester/hiccup Original concept by James Reeves

Pyccup is derived from nbessi's Pyhiccup library, and makes only incremental in python compatibility.

Pyccup is a library for representing HTML in Python. It uses list or tuple to represent elements, and dict to represent an element's attributes. Supports Python versions 3.4 and later.

Install

pip install pyccup

Syntax

Here is a basic example of pyccup syntax.

>>> from pyccup.core import html
>>> data = [
>>>    ['div',
>>>     {'class': 'a-class', 'data-y': '23'},
>>>     ['span', 'my-text',
>>>      ['ul', [['li', x] for x in ['café', 'milk', 'sugar']]]]]
>>> ]
>>> html(data)
u'<!DOCTYPE html><html lang="en" xml:lang="en" dir="rtl"><div data-y="23" class="a-class"><span>my-text<ul><li>café<li>milk<li>sugar</ul></span></div></html>'

The html function supports different default type html5, html4, xhtml-strict, xhtml-transitional

>>> from pyccup.core import html
>>> data = []
>>> html(data, etype='xhtml-strict')
>>> u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html lang="en" xml:lang="en" dir="rtl" xmlns="http://www.w3.org/1999/xhtml"/>'

You can pass arbitrary keyword arguments to the html they will be transformed into html tag attributes

>>> from pyccup.core import html
>>> data = []
>>> html(data, etype='xhtml-strict', an-attr='foo')
u'... <html an-attr="foo" lang="en" xml:lang="en" dir="rtl" xmlns="http://www.w3.org/1999/xhtml"/>'

Pyccup also provides a function to represent XML. Arbitrary keyword arguments are also supported.

>>> from pyccup.core import xml
>>> data = ['form-desc',
>>>         ['field', {'name': 'a_name'}],
>>>         ['field', {'name': 'a_other_name'}]]
>>> conv = xml(data, 'foo-ns', bar='an_attr')
u'<?xml version="1.0" encoding="UTF-8"?><foo-ns bar="an_attr"><form-desc><field name="a_name"/><field name="a_other_name"/></form-desc></foo-ns>'

Some time you want to be able to create XML/HTML chunk out of a namespace. The core.convert is made for this.

>>> from pyccup.core import convert
>>> from pyccup.element import link_to
>>> convert(link_to('http://github.com/inaimathi/pyccup', 'pyccup'))
u'<a href="http://github.com/inaimathi/pyccup">pyccup</a>'

Helpers are available on the elements namespace. The will help you to add hyperlink, images etc.

>>> from pyccup.element import link_to
>>> link_to(u'https://github.com/inaimathi/pyccup', u'pyccup' )
[u'a', {u'href': u'https://github.com/inaimathi/pyccup'}, u'pyccup']

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyccup-0.0.1.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyccup-0.0.1-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file pyccup-0.0.1.tar.gz.

File metadata

  • Download URL: pyccup-0.0.1.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for pyccup-0.0.1.tar.gz
Algorithm Hash digest
SHA256 714df21caa580d392fbd6dd3e664d4aa48bebf643075ea8af96dd35b45a25a3f
MD5 8dc6500e2f4041352623f6d7e843aac3
BLAKE2b-256 42c5392cbf41e3e960b885e91af6d6eb232e960c71cbe2d99b7c65b59212c4b2

See more details on using hashes here.

File details

Details for the file pyccup-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pyccup-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for pyccup-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1edec458428f1029444fb553decf7ab8e892f797b3599c7e15a55031c49eae86
MD5 26465d06cf14e7c1372d88980bcd814a
BLAKE2b-256 c4781ceeb23b13227ec15e67bad1af017fa681ed7974526116f805045fb0436a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page