Metadata-Version: 2.4
Name: tinycss2-core-attributes
Version: 1.5.1.0
Summary: Provides the set of core attributes for each tinycss AST Node
Author-email: Petr Viktorin <encukou@gmail.com>
Project-URL: Homepage, https://github.com/encukou/tinycss2-core-attributes
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENCE.CC0
Requires-Dist: tinycss2==1.5.1
Dynamic: license-file

# tinycss2_core_attributes

This is a companion to the [`tinycss2` project][tinycss2] that provides
a list of "core attribute" names for every tinycss `Node` class.
This allows you to traverse the parse tree or print out information
(for example, for debugging), all without special-casing *every* node type.

[tinycss2]: https://doc.courtbouillon.org/tinycss2/stable/index.html

For example:

```pycon
>>> import tinycss2
>>> from tinycss2_core_attributes import get_core_attrs

>>> decl = tinycss2.parse_one_declaration('width: 100%;')
>>> decl
<Declaration width: …>
>>> get_core_attrs(decl)
['name', 'value', 'important']

>>> for attr_name in get_core_attrs(decl):
...     print(f'{attr_name}: {getattr(decl, attr_name)}')
...
name: width
value: [<WhitespaceToken>, <PercentageToken 100%>, <LiteralToken ;>]
important: False
```

The "core attributes" are ones that contain information about the individual
node. This excludes:
- attributes common to all nodes, like [`type`][node-type] and
  [`source_line`][node-source_line]
- attributes that can be trivially computed from other core attributes,
  like [`lower_at_keyword`][node-lower_at_keyword] (which you can compute from
  `at_keyword`
- the undocumented `representation` of string and URL tokens (which can't
  always be computed from `value`)

[node-type]: https://doc.courtbouillon.org/tinycss2/stable/api_reference.html#tinycss2.ast.Node.type
[node-source_line]: https://doc.courtbouillon.org/tinycss2/stable/api_reference.html#tinycss2.ast.Node.source_line
[node-lower_at_keyword]: https://doc.courtbouillon.org/tinycss2/stable/api_reference.html#tinycss2.ast.AtRule.lower_at_keyword

The purpose of this project is to show that this concept of "core attributes"
is useful. Perhaps it could be [added to `tinycss2` itself][tinycss2-issue].

[tinycss2-issue]: https://github.com/Kozea/tinycss2/issues/66

## API

The project provides a single function:

### `get_core_attrs`

```text
get_core_attrs(node)
```

Takes a `tinycss2.ast.Node` instance or subclass, and returns a list of
names of its "core attributes".

## CLI interface

There's a demo!
Run `python -m tinycss2_core_attributes FILE.css` to parse `FILE.css` and
display a colorized dump of the AST.
Use `--help` to see all options.

## Versioning

This project is tightly tied to `tinycss2`, and uses the `tinycss2` version
it is compatible with plus a change counter at the end.

Thus, `tinycss2_core_attributes` 1.5.1.0 requires `tinycss2` 1.5.1.

## Licence

To the extent possible under law, the author(s) have dedicated all copyright
and related and neighboring rights to this work to the public domain worldwide.
This work is distributed without any warranty.

See the CC0 Public Domain Dedication:
http://creativecommons.org/publicdomain/zero/1.0/
