8000 introduce </p> handling; </br> handling is now conforming per the spe… · html5lib/html5lib-python@b32b741 · GitHub
[go: up one dir, main page]

Skip to content

Commit b32b741

Browse files
committed
introduce </p> handling; </br> handling is now conforming per the specification
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40829
1 parent df931b2 commit b32b741

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/html5lib/html5parser.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
21
# Differences from the current specification (23 December 2006) are as follows:
32
# * Phases and insertion modes are one concept in parser.py.
43
# * EOF handling is slightly different to make sure <html>, <head> and <body>
54
# always exist.
6-
# * </br> creates a <br> element.
75
#
86
# We haven't updated DOCTYPE handling yet
9-
#
10-
# It should be trivial to add the following cases. However, we should probably
11-
# also look into comment handling and such then...
12-
# * A <p> element end tag creates an empty <p> element when there's no <p>
13-
# element in scope.
7+
148

159
try:
1610
frozenset
@@ -485,7 +479,7 @@ def __init__(self, parser, tree):
485479
self.startTagHandler.default = self.startTagOther
486480

487481
self.endTagHandler = utils.MethodDispatcher([
488-
(("html", "head", "body", "br"), self.endTagImplyHead)
482+
(("html", "head", "body", "br", "p"), self.endTagImplyHead)
489483
])
490484
self.endTagHandler.default = self.endTagOther
491485

@@ -530,7 +524,7 @@ def __init__(self, parser, tree):
530524

531525
self. endTagHandler = utils.MethodDispatcher([
532526
("head", self.endTagHead),
533-
(("html", "body", "br"), self.endTagImplyAfterHead),
527+
(("html", "body", "br", "p"), self.endTagImplyAfterHead),
534528
(("title", "style", "script"), self.endTagTitleStyleScript)
535529
])
536530
self.endTagHandler.default = self.endTagOther
@@ -995,8 +989,12 @@ def endTagP(self, name):
995989
self.tree.generateImpliedEndTags("p")
996990
if self.tree.openElements[-1].name != "p":
997991
self.parser.parseError(_("Unexpected end tag (p)."))
998-
while self.tree.elementInScope("p"):
999-
self.tree.openElements.pop()
992+
if self.tree.elementInScope("p"):
993+
while self.tree.elementInScope("p"):
994+
self.tree.openElements.pop()
995+
else:
996+
self.startTagCloseP("p", {})
997+
self.endTagP("p")
1000998

1001999
def endTagBody(self, name):
10021000
# XXX Need to take open <p> tags into account here. We shouldn't imply

0 commit comments

Comments
 (0)
0