[ZPT] CVS: Releases/Zope/lib/python/TAL - HTMLTALParser.py:1.30

Evan Simpson evan@zope.com
Mon, 12 Nov 2001 14:24:25 -0500


Update of /cvs-repository/Releases/Zope/lib/python/TAL
In directory cvs.zope.org:/tmp/cvs-serv27742

Modified Files:
	HTMLTALParser.py 
Log Message:
Complain about implicitly closed <hn> tags.


=== Releases/Zope/lib/python/TAL/HTMLTALParser.py 1.29 => 1.30 ===
         HTMLParseError.__init__(self, msg, position)
 
+class OpenTagError(NestingError):
+    """Exception raised when a tag is not allowed in another tag."""
+
+    def __init__(self, tagstack, tag, position=(None, None)):
+        self.tag = tag
+        msg = 'Tag <%s> is not allowed in <%s>' % (tag, tagstack[-1])
+        HTMLParseError.__init__(self, msg, position)
+
 class HTMLTALParser(HTMLParser):
 
     # External API
@@ -239,12 +247,16 @@
                 elif t in BLOCK_LEVEL_HTML_TAGS:
                     close_to = -1
         elif tag in PARA_LEVEL_HTML_TAGS + BLOCK_LEVEL_HTML_TAGS:
-            for i in range(len(self.tagstack)):
-                if self.tagstack[i] in BLOCK_LEVEL_HTML_TAGS:
-                    close_to = -1
-                elif self.tagstack[i] in PARA_LEVEL_HTML_TAGS:
-                    if close_to == -1:
-                        close_to = i
+            i = len(self.tagstack) - 1
+            while i >= 0:
+                closetag = self.tagstack[i]
+                if closetag in BLOCK_LEVEL_HTML_TAGS:
+                    break
+                if closetag in PARA_LEVEL_HTML_TAGS:
+                    if closetag != "p":
+                        raise OpenTagError(self.tagstack, tag, self.getpos())
+                    close_to = i
+                i = i - 1
         if close_to >= 0:
             while len(self.tagstack) > close_to:
                 self.implied_endtag(self.tagstack[-1], 1)