mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 23:13:25 +00:00
check-templates: Be stricter about singleton tags.
We now forbid tags of the form `<foo ... />` in most
places, and we also forbid it even for several void
tags.
We make exceptions for tags that are already formatted
in two different ways in our codebase. This is mostly
svg tags, plus these common cases:
- br
- hr
- img
- input
It would be nice to lock down a convention for these,
even though the HTML specification is unopinionated
on these. We'll probably want to stay flexible for
svg tags, since they are sometimes copy/pasted from
other sources (although it's probably rare enough for
them that we can tolerate just doing minor edits as
needed).
This commit is contained in:
@@ -301,7 +301,21 @@ def validate(fn: Optional[str] = None, text: Optional[str] = None, check_indent:
|
||||
def is_special_html_tag(s: str, tag: str) -> bool:
|
||||
return tag in ['link', 'meta', '!DOCTYPE']
|
||||
|
||||
OPTIONAL_CLOSING_TAGS = [
|
||||
'br',
|
||||
'circle',
|
||||
'hr',
|
||||
'img',
|
||||
'input',
|
||||
'path',
|
||||
'polygon',
|
||||
]
|
||||
|
||||
def is_self_closing_html_tag(s: Text, tag: Text) -> bool:
|
||||
if s.endswith('/>'):
|
||||
if tag in OPTIONAL_CLOSING_TAGS:
|
||||
return True
|
||||
raise TokenizationException('Singleton tag not allowed', tag)
|
||||
self_closing_tag = tag in [
|
||||
'area',
|
||||
'base',
|
||||
@@ -316,8 +330,9 @@ def is_self_closing_html_tag(s: Text, tag: Text) -> bool:
|
||||
'track',
|
||||
'wbr',
|
||||
]
|
||||
singleton_tag = s.endswith('/>')
|
||||
return self_closing_tag or singleton_tag
|
||||
if self_closing_tag:
|
||||
return True
|
||||
return False
|
||||
|
||||
def is_django_block_tag(tag: str) -> bool:
|
||||
return tag in [
|
||||
|
||||
Reference in New Issue
Block a user