Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

check-templates: Complain about stray text.

Steve Howella6ee54d99dc1
diff --git a/templates/zerver/for-open-source.html b/templates/zerver/for-open-source.html
index 81209601528..91c8f4a6f3d 100644
--- a/templates/zerver/for-open-source.html
+++ b/templates/zerver/for-open-source.html
@@ -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>
diff --git a/templates/zerver/for-research.html b/templates/zerver/for-research.html
index d73d4aad237..7d13b3b1c57 100644
--- a/templates/zerver/for-research.html
+++ b/templates/zerver/for-research.html
@@ -88,11 +88,9 @@
both the app and the website is extremely positive!
</blockquote>
<div class="author">
- &mdash; <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>
+ &mdash; <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
diff --git a/tools/lib/template_parser.py b/tools/lib/template_parser.py
index cf558d7f9df..5d368c471c8 100644
--- a/tools/lib/template_parser.py
+++ b/tools/lib/template_parser.py
@@ -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"""
diff --git a/tools/tests/test_pretty_print.py b/tools/tests/test_pretty_print.py
index 271b84351f9..b1a4e13b545 100644
--- a/tools/tests/test_pretty_print.py
+++ b/tools/tests/test_pretty_print.py
@@ -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)