mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
template_parser: Add parsing support for self closing tags as per HTML5.
In this commit we add support for some tags which are also called void-elements according to http://w3c.github.io/html/syntax.html#void-elements to be parsed by our template parser and get tagged as singleton_html_tags. Fixes: #8387.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from typing import Callable, List, Optional
|
||||
from typing import Callable, List, Optional, Text
|
||||
|
||||
class TemplateParserException(Exception):
|
||||
def __init__(self, message):
|
||||
@@ -112,7 +112,7 @@ def tokenize(text):
|
||||
|
||||
if is_special_html_tag(s, tag):
|
||||
kind = 'html_special'
|
||||
elif s.endswith('/>'):
|
||||
elif is_self_closing_html_tag(s, tag):
|
||||
kind = 'html_singleton'
|
||||
else:
|
||||
kind = 'html_start'
|
||||
@@ -272,6 +272,24 @@ def is_special_html_tag(s, tag):
|
||||
# type: (str, str) -> bool
|
||||
return tag in ['link', 'meta', '!DOCTYPE']
|
||||
|
||||
def is_self_closing_html_tag(s: Text, tag: Text) -> bool:
|
||||
self_closing_tag = tag in [
|
||||
'area',
|
||||
'base',
|
||||
'br',
|
||||
'col',
|
||||
'embed',
|
||||
'hr',
|
||||
'img',
|
||||
'input',
|
||||
'param',
|
||||
'source',
|
||||
'track',
|
||||
'wbr',
|
||||
]
|
||||
singleton_tag = s.endswith('/>')
|
||||
return self_closing_tag or singleton_tag
|
||||
|
||||
def is_django_block_tag(tag):
|
||||
# type: (str) -> bool
|
||||
return tag in [
|
||||
|
||||
Reference in New Issue
Block a user