Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.

Latest commit

 

History

History
55 lines (40 loc) · 1.69 KB

extending.rst

File metadata and controls

55 lines (40 loc) · 1.69 KB

Extending the parser

Modules such as .page3 extend the CSS 2.1 parser to add support for CSS 3 syntax. They do so by sub-classing .css21.CSS21Parser and overriding/extending some of its methods. If fact, the parser is made of methods in a class (rather than a set of functions) solely to enable this kind of sub-classing.

tinycss is designed to enable you to have parser subclasses outside of tinycss, without monkey-patching. If however the syntax you added is for a W3C specification, consider including your subclass in a new tinycss module and send a pull request: see hacking.

tinycss.css21

Parser methods

In addition to methods of the user API (see parsing), here are the methods of the CSS 2.1 parser that can be overriden or extended:

CSS21Parser.parse_rules

CSS21Parser.read_at_rule

CSS21Parser.parse_at_rule

CSS21Parser.parse_media

CSS21Parser.parse_page_selector

CSS21Parser.parse_declarations_and_at_rules

CSS21Parser.parse_ruleset

CSS21Parser.parse_declaration_list

CSS21Parser.parse_declaration

CSS21Parser.parse_value_priority

Unparsed at-rules

AtRule

tinycss.parsing

Parsing helper functions

The tinycss.parsing module contains helper functions for parsing tokens into a more structured form:

strip_whitespace

split_on_comma

validate_value

validate_block

validate_any