Commit dcaae821 authored by Fred Drake's avatar Fred Drake

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.
parent 32072aea
...@@ -28,12 +28,14 @@ PARA_LEVEL_HTML_TAGS = [ ...@@ -28,12 +28,14 @@ PARA_LEVEL_HTML_TAGS = [
"h1", "h2", "h3", "h4", "h5", "h6", "p", "h1", "h2", "h3", "h4", "h5", "h6", "p",
] ]
CLOSING_BLOCK_LEVEL_HTML_TAGS = [ BLOCK_CLOSING_TAG_MAP = {
# These are HTML tags that close others in this list, but are not "tr": ("tr", "td", "th"),
# closed by paragraph-level tags. They don't close across other "td": ("td", "th"),
# block-level boundaries. "th": ("td", "th"),
"li", "dt", "dd", "td", "th", "tr", "li": ("li",),
] "dd": ("dd", "dt"),
"dt": ("dd", "dt"),
}
BLOCK_LEVEL_HTML_TAGS = [ BLOCK_LEVEL_HTML_TAGS = [
# List of HTML tags that denote larger sections than paragraphs. # List of HTML tags that denote larger sections than paragraphs.
...@@ -42,7 +44,7 @@ BLOCK_LEVEL_HTML_TAGS = [ ...@@ -42,7 +44,7 @@ BLOCK_LEVEL_HTML_TAGS = [
] ]
TIGHTEN_IMPLICIT_CLOSE_TAGS = (PARA_LEVEL_HTML_TAGS TIGHTEN_IMPLICIT_CLOSE_TAGS = (PARA_LEVEL_HTML_TAGS
+ CLOSING_BLOCK_LEVEL_HTML_TAGS) + BLOCK_CLOSING_TAG_MAP.keys())
class NestingError(Exception): class NestingError(Exception):
...@@ -108,11 +110,12 @@ class HTMLTALParser(SGMLParser): ...@@ -108,11 +110,12 @@ class HTMLTALParser(SGMLParser):
self.scan_xmlns(attrs) self.scan_xmlns(attrs)
if tag in EMPTY_HTML_TAGS: if tag in EMPTY_HTML_TAGS:
self.pop_xmlns() 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 close_to = -1
for i in range(len(self.tagstack)): for i in range(len(self.tagstack)):
t = self.tagstack[i] t = self.tagstack[i]
if t in CLOSING_BLOCK_LEVEL_HTML_TAGS: if t in blocks_to_close:
close_to = i close_to = i
elif t in BLOCK_LEVEL_HTML_TAGS: elif t in BLOCK_LEVEL_HTML_TAGS:
close_to = -1 close_to = -1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment