mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
[css][bugfix] CSS tokens can now have digits in their names
...excepted for their first char of course
This commit is contained in:
@@ -461,25 +461,10 @@ class StylesBuilder:
|
||||
def process_color(self, name: str, tokens: list[Token]) -> None:
|
||||
"""Processes a simple color declaration."""
|
||||
name = name.replace("-", "_")
|
||||
token_indexes_to_skip = []
|
||||
for i, token in enumerate(tokens):
|
||||
if i in token_indexes_to_skip:
|
||||
continue
|
||||
for token in tokens:
|
||||
if token.name in ("color", "token"):
|
||||
value = token.value
|
||||
# Color names can include digits (e.g. "turquoise4"): if the next token is a number
|
||||
# we should consider it part of the color name:
|
||||
next_token = tokens[i + 1] if len(tokens) > (i + 1) else None
|
||||
if (
|
||||
next_token
|
||||
and next_token.name == "number"
|
||||
and next_token.location[1] == token.location[1] + len(value)
|
||||
):
|
||||
value = value + next_token.value
|
||||
# skip next token, as we included it in this one's value:
|
||||
token_indexes_to_skip.append(i + 1)
|
||||
try:
|
||||
self.styles._rules[name] = Color.parse(value)
|
||||
self.styles._rules[name] = Color.parse(token.value)
|
||||
except Exception as error:
|
||||
self.error(
|
||||
name, token, f"failed to parse color {token.value!r}; {error}"
|
||||
|
||||
@@ -11,7 +11,7 @@ DURATION = r"\d+\.?\d*(?:ms|s)"
|
||||
NUMBER = r"\-?\d+\.?\d*"
|
||||
COLOR = r"\#[0-9a-fA-F]{8}|\#[0-9a-fA-F]{6}|rgb\(\-?\d+\.?\d*,\-?\d+\.?\d*,\-?\d+\.?\d*\)|rgba\(\-?\d+\.?\d*,\-?\d+\.?\d*,\-?\d+\.?\d*,\-?\d+\.?\d*\)"
|
||||
KEY_VALUE = r"[a-zA-Z_-][a-zA-Z0-9_-]*=[0-9a-zA-Z_\-\/]+"
|
||||
TOKEN = "[a-zA-Z_-]+"
|
||||
TOKEN = "[a-zA-Z][a-zA-Z0-9_-]*"
|
||||
STRING = r"\".*?\""
|
||||
VARIABLE_REF = r"\$[a-zA-Z0-9_\-]+"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user