|
| 1 | +html5lib |
| 2 | +======== |
| 3 | + |
| 4 | +html5lib is a pure-python library for parsing HTML. It is designed to |
| 5 | +conform to the HTML specification, which has formalized the error |
| 6 | +handling algorithms of legacy web browsers, and is now implemented by |
| 7 | +all major web browsers. |
| 8 | + |
| 9 | + |
| 10 | +Requirements |
| 11 | +------------ |
| 12 | + |
| 13 | +Python 2.6 and above (including 3) are supported. Implementations |
| 14 | +known to work are CPython (as the reference implementation) and |
| 15 | +PyPy. Jython is known *not* to work due to various bugs in its |
| 16 | +implementation of the language. Others such as IronPython may or may |
| 17 | +not work; if you wish to try, you are strongly recommended to run the |
| 18 | +testsuite and report back! |
| 19 | + |
| 20 | +The only required library dependency is ``six``, this can be found |
| 21 | +packaged in PyPi. |
| 22 | + |
| 23 | +Optionally: |
| 24 | + |
| 25 | + - ``datrie`` can be used to improve parsing performance (though in |
| 26 | + almost all cases the improvement is trivial); |
| 27 | + |
| 28 | + - ``lxml`` is supported as a tree format (for both building and |
| 29 | + walking) under CPython (but *not* PyPy where it is known to cause |
| 30 | + segfaults); |
| 31 | + |
| 32 | + - ``genshi`` has a treewalker (but not builder); and |
| 33 | + |
| 34 | + - ``chardet`` (note currently this is only packaged on PyPi for |
| 35 | + Python 2, though several package managers include unofficial ports |
| 36 | + to Python 3) can be used as a fallback when character encoding |
| 37 | + cannot be determined. |
| 38 | + |
| 39 | + |
| 40 | +Installation |
| 41 | +------------ |
| 42 | + |
| 43 | +html5lib is packaged with distutils. To install it use:: |
| 44 | + |
| 45 | + $ python setup.py install |
| 46 | + |
| 47 | + |
| 48 | +Usage |
| 49 | +----- |
| 50 | + |
| 51 | +Simple usage follows this pattern:: |
| 52 | + |
| 53 | + import html5lib |
| 54 | + with open("mydocument.html", "r") as fp: |
| 55 | + document = html5lib.parse(f) |
| 56 | + |
| 57 | +or:: |
| 58 | + |
| 59 | + import html5lib |
| 60 | + document = html5lib.parse("<p>Hello World!") |
| 61 | + |
| 62 | +More documentation is available in the docstrings. |
| 63 | + |
| 64 | + |
| 65 | +Bugs |
| 66 | +---- |
| 67 | + |
| 68 | +Please report any bugs on the `issue tracker |
| 69 | +<https://github.com/html5lib/html5lib-python/issues>`_. |
| 70 | + |
| 71 | + |
| 72 | +Tests |
| 73 | +----- |
| 74 | + |
| 75 | +These are nowadays contained in the html5lib-tests repository and |
| 76 | +included as a submodule, thus for git checkouts they must be |
| 77 | +initialized (for release tarballs this is unneeded):: |
| 78 | + |
| 79 | + $ git submodule init |
| 80 | + $ git submodule update |
| 81 | + |
| 82 | +And then they can be run once ``nose`` has been installed with |
| 83 | +``nosetests``. All should pass. |
| 84 | + |
| 85 | + |
| 86 | +Contributing |
| 87 | +------------ |
| 88 | + |
| 89 | +Pull requests are more than welcome — both to the library and to the |
| 90 | +documentation. Some useful information: |
| 91 | + |
| 92 | + - We aim to follow PEP 8 in the library, but ignoring the |
| 93 | + 79-character-per-line limit, instead following a soft limit of 99, |
| 94 | + but allowing lines over this where it is the readable thing to do. |
| 95 | + |
| 96 | + - We keep pyflakes reporting no errors or warnings at all times. |
| 97 | + |
| 98 | + - We keep the master branch passing all tests at all times on all |
| 99 | + supported versions. |
| 100 | + |
| 101 | +Travis CI is run against all pull requests and should enforce all of |
| 102 | +the above. |
| 103 | + |
| 104 | +We also use an external code-review tool, which uses your GitHub login |
| 105 | +to authenticate. You'll get emails for changes on the review. |
| 106 | + |
| 107 | + |
| 108 | +Questions? |
| 109 | +---------- |
| 110 | + |
| 111 | +There's a mailing list available for support on Google Groups, |
| 112 | +`html5lib-discuss <http://groups.google.com/group/html5lib-discuss>`_, |
| 113 | +though you may have more success (and get a far quicker response) |
| 114 | +asking on IRC in #whatwg on irc.freenode.net. |
0 commit comments