mirror of
https://github.com/wrabit/django-cotton.git
synced 2025-07-16 14:05:00 +00:00
handle attributes containing quoted spaces
This commit is contained in:
parent
072342fae0
commit
12d64ede25
4 changed files with 90 additions and 5 deletions
|
@ -7,7 +7,22 @@ class Tag:
|
|||
r"<(/?)c-([^\s/>]+)((?:\s+[^\s/>\"'=<>`]+(?:\s*=\s*(?:\"[^\"]*\"|'[^']*'|\S+))?)*)\s*(/?)\s*>",
|
||||
re.DOTALL,
|
||||
)
|
||||
attr_pattern = re.compile(r'([^\s/>\"\'=<>`]+)(?:\s*=\s*(?:(["\'])(.*?)\2|(\S+)))?', re.DOTALL)
|
||||
# attr_pattern = re.compile(r'([^\s/>\"\'=<>`]+)(?:\s*=\s*(?:(["\'])(.*?)\2|(\S+)))?', re.DOTALL)
|
||||
|
||||
attr_pattern = re.compile(
|
||||
r"""([^\s/>\"\'=<>`]+) # Attribute name
|
||||
(?: # Optional group for value
|
||||
\s*=\s* # Equals with optional whitespace
|
||||
(?:
|
||||
(["\']) # Quote character
|
||||
((?:(?!\2)|.)*?) # Any character that's not the quote character
|
||||
\2 # Matching quote
|
||||
| # OR
|
||||
(\S+) # Non-quoted value without spaces
|
||||
)
|
||||
)?""",
|
||||
re.VERBOSE | re.DOTALL,
|
||||
)
|
||||
|
||||
def __init__(self, match: re.Match):
|
||||
self.html = match.group(0)
|
||||
|
@ -130,7 +145,7 @@ class CottonCompiler:
|
|||
|
||||
if len(matches) > 1:
|
||||
raise ValueError(
|
||||
f"Multiple c-vars tags found in component template. Only one c-vars tag is allowed per template."
|
||||
"Multiple c-vars tags found in component template. Only one c-vars tag is allowed per template."
|
||||
)
|
||||
|
||||
# Process single c-vars tag if present
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue