========== Quickstart ========== Installation ============ From PyPI: .. code-block:: sh # with pip pip install hyccup # with poetry poetry add hyccup Overview ======== Use the :hy:func:`html ` core function to render a data structure into an HTML string: .. tab:: Hy .. code-block:: clj => (import hyccup [html]) => (html ["p" {"id" "an-id" "class" "a-class"} "Lorem Hypsum"]) "

Lorem Hypsum

" .. tab:: Python .. code-block:: >>> from hyccup.core import html >>> html(['p', {'id': 'an-id', 'class': 'a-class'}, 'Python Ipsum']) '

Python Ipsum

' The :hy:func:`html ` function takes lists as positional arguments. The first elmement of each list must be the tag name of the element to render. It can be a string or a Hy symbol. .. tab:: Hy .. code-block:: clj => (html ["p"]) "

" => (html ["br"]) "
" .. tab:: Python .. code-block:: >>> html(['p']) '

' >>> html(['br']) '
' The attributes of the element must be represented in a dictionary as the second element of the list. .. tab:: Hy .. code-block:: clj => (html ["input" {"type" "password" "name" "password"}]) "" => (html ["p" "Attributes dict can be omitted"]) "

Attributes dict can be omitted

" .. tab:: Python .. code-block:: >>> html(['input', {'type': 'password', 'name': 'password'}]) '' >>> html(['p', 'Attributes dict can be omitted']) '

Attributes dict can be omitted

' The other elements provided in the list are considered as the children of the element. If an element is an iterator, it is expanded. .. tab:: Hy .. code-block:: clj => (setv items-generator (gfor x (range 5) ["li" f"Item #{x}"])) => (html ["ol" items-generator]) "
  1. Item #0
  2. Item #1
  3. Item #2
  4. Item #3
  5. Item #4
" => (setv items-list (lfor x (range 5) ["li" f"Item #{x}"])) => (html ["p" "For other collections use unpacking or iter:"] ... ["ul" #* items-list (iter items-list)]) "

For other collections use unpacking or iter:

" .. tab:: Python .. code-block:: >>> items_generator = (['li', f'Item #{x}'] for x in range(5)) >>> html(['ol', items_generator]) '
  1. Item #0
  2. Item #1
  3. Item #2
  4. Item #3
  5. Item #4
' >>> items_list = [['li', f'Item #{x}'] for x in range(5)] >>> html(['p', 'For other collections use unpacking or iter:'], ... ['ul', *items_list, iter(items_list)]) '

For other collections use unpacking or iter:

' CSS selectors syntax for classes and id can be used as a shortcut (first the id, followed by the classes): .. tab:: Hy .. code-block:: clj => (html ["div#guido.bdfl"]) "
" .. tab:: Python .. code-block:: >>> html(['div#guido.bdfl']) '
'