diff --git a/tools/lib/template_parser.py b/tools/lib/template_parser.py
index e51181f2a3..2c08d01b68 100644
--- a/tools/lib/template_parser.py
+++ b/tools/lib/template_parser.py
@@ -154,6 +154,8 @@ def validate(fn=None, text=None, check_indent=True):
             end_col = end_token.col
 
             problem = None
+            if (start_tag == 'code') and (end_line == start_line + 1):
+                problem = 'Code tag is split across two lines.'
             if start_tag != end_tag:
                 problem = 'Mismatched tag.'
             elif check_indent and end_line > start_line + 1 and end_col != start_col:
diff --git a/tools/tests/test_template_parser.py b/tools/tests/test_template_parser.py
index 630524eca7..29ef752976 100644
--- a/tools/tests/test_template_parser.py
+++ b/tools/tests/test_template_parser.py
@@ -54,6 +54,31 @@ class ParserTest(unittest.TestCase):
             '''
         validate(text=my_html)
 
+    def test_code_blocks(self):
+        # type: () -> None
+
+        # This is fine.
+        my_html = '''
+            
+                x = 5
+                y = x + 1
+            '''
+        validate(text=my_html)
+
+        # This is also fine.
+        my_html = "process_widgets()"
+        validate(text=my_html)
+
+        # This is illegal.
+        my_html = '''
+            x =
+            5
+            '''
+        # See https://github.com/python/typeshed/issues/372
+        # for why we have to ingore types here.
+        with self.assertRaisesRegexp(Exception, 'split across two lines'): # type: ignore
+            validate(text=my_html)
+
     def test_tokenize(self):
         # type: () -> None
         tag = 'bla'