Skip to content

Commit d46179f

Browse files
committed
Document color and <An+B> parsing.
1 parent 1828e3c commit d46179f

File tree

3 files changed

+49
-11
lines changed

3 files changed

+49
-11
lines changed

docs/index.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ some serialization-related functions are available:
4545
.. autofunction:: serialize_identifier
4646

4747

48+
.. module:: tinycss2.color3
49+
50+
Color
51+
=====
52+
53+
.. autofunction:: parse_color
54+
.. autoclass:: RGBA
55+
56+
57+
.. module:: tinycss2.nth
58+
59+
<An+B>
60+
======
61+
62+
.. autofunction:: parse_nth
63+
64+
4865
.. module:: tinycss2.ast
4966

5067
AST nodes

tinycss2/color3.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,42 @@
99
class RGBA(collections.namedtuple('RGBA', ['red', 'green', 'blue', 'alpha'])):
1010
"""An RGBA color.
1111
12-
A tuple of four floats in the 0..1 range: ``(r, g, b, a)``.
13-
Also has :attr:`red`, :attr:`green`, :attr:`blue` and :attr:`alpha`
14-
attributes to access the same values.
12+
A tuple of four floats in the 0..1 range: ``(red, green, blue, alpha)``.
13+
14+
.. attribute:: red
15+
16+
Convenience access to the red channel. Same as ``rgba[0]``.
17+
18+
.. attribute:: green
19+
20+
Convenience access to the green channel. Same as ``rgba[1]``.
21+
22+
.. attribute:: blue
23+
24+
Convenience access to the blue channel. Same as ``rgba[2]``.
25+
26+
.. attribute:: alpha
27+
28+
Convenience access to the alpha channel. Same as ``rgba[3]``.
1529
1630
"""
17-
type = 'rgba'
1831

1932

2033
def parse_color(input):
2134
"""Parse a color value as defined in `CSS Color Level 3
2235
<http://www.w3.org/TR/css3-color/>`_.
2336
24-
:param token:
37+
:param input:
2538
A :term:`string`, or a single :term:`component value`.
2639
:returns:
27-
* :obj:`None` if the token is not a valid CSS 3 color value.
40+
* :obj:`None` if the input is not a valid color value.
2841
(No exception is raised.)
2942
* The string ``'currentColor'`` for the *currentColor* keyword
3043
* Or a :class:`RGBA` object for every other values
3144
(including keywords, HSL and HSLA.)
32-
The alpha channel is clipped to [0, 1], but R, G, or B can be
33-
out of range (eg. ``rgb(-51, 306, 0)`` is represented as
34-
``(-.2, 1.2, 0, 1)``.)
45+
The alpha channel is clipped to [0, 1]
46+
but red, green, or blue can be out of range
47+
(eg. ``rgb(-10%, 120%, 0%)`` is represented as ``(-0.1, 1.2, 0, 1)``.)
3548
3649
"""
3750
if isinstance(input, basestring):

tinycss2/nth.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@
33

44

55
def parse_nth(input):
6-
"""Parse <An+B>, as found in ``:nth-child()`` and related pseudo-classes.
6+
"""Parse `<An+B> <http://dev.w3.org/csswg/css-syntax-3/#anb>`_,
7+
as found in `:nth-child()
8+
<http://dev.w3.org/csswg/selectors/#nth-child-pseudo>`_
9+
and related Selector pseudo-classes.
10+
11+
Although tinycss2 does not include a full Selector parser,
12+
this bit of syntax is included as it is particularly tricky to define
13+
on top of a CSS tokenizer.
714
815
:param input:
916
A :term:`string`, or an iterable yielding :term:`component values`
10-
(eg. the arguments of a functional pseudo-class.)
17+
(eg. the :attr:`~tinycss2.ast.FunctionBlock.arguments`
18+
of a functional pseudo-class.)
1119
:returns:
1220
A ``(a, b)`` tuple of integers, or :obj:`None` if the input is invalid.
1321

0 commit comments

Comments
 (0)