Skip to content

Commit

Permalink
Document and use parse_blocks_contents everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Mar 17, 2024
1 parent 6398302 commit 309ad43
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/api_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ functions.
.. autofunction:: parse_stylesheet
.. autofunction:: parse_rule_list
.. autofunction:: parse_one_rule
.. autofunction:: parse_blocks_contents
.. autofunction:: parse_declaration_list
.. autofunction:: parse_one_declaration
.. autofunction:: parse_component_value_list
Expand Down
8 changes: 4 additions & 4 deletions docs/common_use_cases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ Parsing a list of declarations is possible from a list of tokens (given by the
string (given by the ``style`` attribute of an HTML element, for example).

The high-level function used to parse declarations is
:func:`tinycss2.parse_declaration_list`.
:func:`tinycss2.parse_blocks_contents`.

.. code-block:: python
rules = tinycss2.parse_stylesheet('body div {width: 50%;height: 50%}')
tinycss2.parse_declaration_list(rules[0].content)
tinycss2.parse_blocks_contents(rules[0].content)
# [<Declaration width: …>, <Declaration height: …>]
tinycss2.parse_declaration_list('width: 50%;height: 50%')
tinycss2.parse_blocks_contents('width: 50%;height: 50%')
# [<Declaration width: …>, <Declaration height: …>]
You can then get the name and value of each declaration:

.. code-block:: python
declarations = tinycss2.parse_declaration_list('width: 50%;height: 50%')
declarations = tinycss2.parse_blocks_contents('width: 50%;height: 50%')
declarations[0].name, declarations[0].value
# ('width', [<WhitespaceToken>, <PercentageToken 50%>])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tinycss2.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def test_serialize_rules():

def test_serialize_declarations():
source = 'color: #123; /**/ @top-left {} width:7px !important;'
rules = parse_declaration_list(source)
rules = parse_blocks_contents(source)
assert serialize(rules) == source


Expand Down

0 comments on commit 309ad43

Please sign in to comment.