mirror of https://github.com/zulip/zulip.git
check-templates: Complain about stray text.
We disallow this HTML: junk-text-before-open-tag<p> This is a paragraph. </p> We rarely see the above mistake, but we want to eliminate the possibility to be somewhat rigorous, and so that we can eliminate a pretty-printer mis-feature.
This commit is contained in:
parent
1e5866b785
commit
a6ee54d99d
|
@ -442,8 +442,8 @@
|
|||
<li>
|
||||
<div class="list-content">
|
||||
Use topics to manage support workflows, answer
|
||||
questions, and collaborate to investigate issues. <a
|
||||
href="/help/resolve-a-topic">Mark the topic ✓
|
||||
questions, and collaborate to investigate issues.
|
||||
<a href="/help/resolve-a-topic">Mark the topic ✓
|
||||
resolved</a> when done!
|
||||
</div>
|
||||
</li>
|
||||
|
|
|
@ -88,11 +88,9 @@
|
|||
both the app and the website is extremely positive!
|
||||
</blockquote>
|
||||
<div class="author">
|
||||
— <a
|
||||
href="https://www.imperial.ac.uk/people/k.buzzard">Kevin
|
||||
Buzzard</a>, Professor of Pure Mathematics at <a
|
||||
href="https://www.imperial.ac.uk/">Imperial College
|
||||
London</a>
|
||||
— <a href="https://www.imperial.ac.uk/people/k.buzzard">Kevin Buzzard</a>,
|
||||
Professor of Pure Mathematics at
|
||||
<a href="https://www.imperial.ac.uk/">Imperial College London</a>
|
||||
</div>
|
||||
<a class="case-study-link" href="/case-studies/lean/"
|
||||
target="_blank">How the Lean prover
|
||||
|
|
|
@ -223,6 +223,10 @@ HTML_VOID_TAGS = {
|
|||
}
|
||||
|
||||
|
||||
def indent_level(s: str) -> int:
|
||||
return len(s) - len(s.lstrip())
|
||||
|
||||
|
||||
def validate(
|
||||
fn: Optional[str] = None, text: Optional[str] = None, check_indent: bool = True
|
||||
) -> None:
|
||||
|
@ -235,6 +239,8 @@ def validate(
|
|||
with open(fn) as f:
|
||||
text = f.read()
|
||||
|
||||
lines = text.split("\n")
|
||||
|
||||
try:
|
||||
tokens = tokenize(text)
|
||||
except FormattedException as e:
|
||||
|
@ -294,6 +300,15 @@ def validate(
|
|||
elif check_indent and (end_line > start_line + max_lines):
|
||||
if end_col != start_col:
|
||||
problem = "Bad indentation."
|
||||
|
||||
if end_line >= start_line + 2:
|
||||
# We have 3+ lines in the tag's block.
|
||||
start_row_text = lines[start_line - 1]
|
||||
start_indent = indent_level(start_row_text)
|
||||
if start_indent != start_col - 1 and start_row_text[start_indent] not in "<{":
|
||||
junk = start_row_text[start_indent : start_col - 1]
|
||||
problem = f"There is junk before the start tag: {junk}"
|
||||
|
||||
if problem:
|
||||
raise TemplateParserException(
|
||||
f"""
|
||||
|
|
|
@ -106,33 +106,7 @@ GOOD_HTML2 = """
|
|||
</html>
|
||||
"""
|
||||
|
||||
BAD_HTML3 = """
|
||||
<html>
|
||||
<body>
|
||||
{{# foobar area}}
|
||||
foobarfoobar<blockquote>
|
||||
<p>
|
||||
FOOBAR
|
||||
</p>
|
||||
</blockquote>
|
||||
{{/ foobar area}}
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
GOOD_HTML3 = """
|
||||
<html>
|
||||
<body>
|
||||
{{# foobar area}}
|
||||
foobarfoobar<blockquote>
|
||||
<p>
|
||||
FOOBAR
|
||||
</p>
|
||||
</blockquote>
|
||||
{{/ foobar area}}
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
# The old GOOD_HTML3 test was flawed.
|
||||
|
||||
BAD_HTML4 = """
|
||||
<div>
|
||||
|
@ -478,7 +452,6 @@ class TestPrettyPrinter(unittest.TestCase):
|
|||
self.compare(pretty_print_html(BAD_HTML), GOOD_HTML)
|
||||
self.compare(pretty_print_html(BAD_HTML1), GOOD_HTML1)
|
||||
self.compare(pretty_print_html(BAD_HTML2), GOOD_HTML2)
|
||||
self.compare(pretty_print_html(BAD_HTML3), GOOD_HTML3)
|
||||
self.compare(pretty_print_html(BAD_HTML4), GOOD_HTML4)
|
||||
self.compare(pretty_print_html(BAD_HTML5), GOOD_HTML5)
|
||||
self.compare(pretty_print_html(BAD_HTML6), GOOD_HTML6)
|
||||
|
|
Loading…
Reference in New Issue