Skip to content

Commit

Permalink
Add DOCTYPE support in README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Bessi committed Sep 30, 2014
1 parent ced93ab commit bdc1f9e
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,41 @@ Syntax
Here is a basic example of pyhiccup syntax:

```python
>>> from pyhiccup.core import html5
>>> from pyhiccup.core import html
>>> data = [
['div',
{'class': 'a-class', 'data-y': '23'},
['span', 'my-text',
['ul', [['li', x] for x in ['coffe', 'milk', 'sugar']]]]]
]
>>> html5(data)
>>>"<!DOCTYPE html>
<html><div data-y="23" class="a-class"><span>my-text<ul><li>coffe</li><li>milk</li><li>sugar</li></ul></span></div></html>"
>>> 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`

```python
>>> from pyhiccup.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

```python
>>> from pyhiccup.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"/>'
```
Pyhiccup also provides a function to represent arbitrary XML. Arbitrary keyword arguments are also supported.

```python
>>> from pyhiccup.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>'
```

0 comments on commit bdc1f9e

Please sign in to comment.