[Zpt] CVS: Packages/TAL - HTMLTALParser.py:1.8

fred@digicool.com fred@digicool.com
Thu, 15 Mar 2001 13:41:51 -0500 (EST)


Update of /cvs-repository/Packages/TAL
In directory korak:/tmp/cvs-serv30104

Modified Files:
	HTMLTALParser.py 
Log Message:

When checking for auto-closure of list- and table-related tags, be sensitive
to the specific tag in hand so that we do not close too many tags.



--- Updated File HTMLTALParser.py in package Packages/TAL --
--- HTMLTALParser.py	2001/03/15 17:38:16	1.7
+++ HTMLTALParser.py	2001/03/15 18:41:50	1.8
@@ -28,12 +28,14 @@
     "h1", "h2", "h3", "h4", "h5", "h6", "p",
     ]
 
-CLOSING_BLOCK_LEVEL_HTML_TAGS = [
-    # These are HTML tags that close others in this list, but are not
-    # closed by paragraph-level tags.  They don't close across other
-    # block-level boundaries.
-    "li", "dt", "dd", "td", "th", "tr",
-    ]
+BLOCK_CLOSING_TAG_MAP = {
+    "tr": ("tr", "td", "th"),
+    "td": ("td", "th"),
+    "th": ("td", "th"),
+    "li": ("li",),
+    "dd": ("dd", "dt"),
+    "dt": ("dd", "dt"),
+    }
 
 BLOCK_LEVEL_HTML_TAGS = [
     # List of HTML tags that denote larger sections than paragraphs.
@@ -42,7 +44,7 @@
     ]
 
 TIGHTEN_IMPLICIT_CLOSE_TAGS = (PARA_LEVEL_HTML_TAGS
-                               + CLOSING_BLOCK_LEVEL_HTML_TAGS)
+                               + BLOCK_CLOSING_TAG_MAP.keys())
 
 
 class NestingError(Exception):
@@ -108,15 +110,16 @@
         self.scan_xmlns(attrs)
         if tag in EMPTY_HTML_TAGS:
             self.pop_xmlns()
-        elif tag in CLOSING_BLOCK_LEVEL_HTML_TAGS:
+        elif BLOCK_CLOSING_TAG_MAP.has_key(tag):
+            blocks_to_close = BLOCK_CLOSING_TAG_MAP[tag]
             close_to = -1
             for i in range(len(self.tagstack)):
                 t = self.tagstack[i]
-                if t in CLOSING_BLOCK_LEVEL_HTML_TAGS:
+                if t in blocks_to_close:
                     close_to = i
                 elif t in BLOCK_LEVEL_HTML_TAGS:
                     close_to = -1
-            self._close_to_level(close_to)
+                    self._close_to_level(close_to)
             self.tagstack.append(tag)
         elif tag in PARA_LEVEL_HTML_TAGS + BLOCK_LEVEL_HTML_TAGS:
             close_to = -1