Skip to content

Commit 866a2a7

Browse files
committed
introduce </br> and make it possible to add </p> and maybe others later
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40746
1 parent 0883df6 commit 866a2a7

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

src/html5parser.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
# * Phases and insertion modes are one concept in parser.py.
44
# * EOF handling is slightly different to make sure <html>, <head> and <body>
55
# always exist.
6-
# * We also deal with content when there's no DOCTYPE.
7-
# It is expected that the specification will catch up with us in due course ;-)
6+
# * </br> creates a <br> element.
7+
#
8+
# We haven't updated DOCTYPE and entity handling yet.
89
#
910
# It should be trivial to add the following cases. However, we should probably
1011
# also look into comment handling and such then...
1112
# * A <p> element end tag creates an empty <p> element when there's no <p>
1213
# element in scope.
13-
# * A <br> element end tag creates an empty <br> element.
1414

1515
try:
1616
frozenset
@@ -395,7 +395,8 @@ def __init__(self, parser, tree):
395395
self.startTagHandler.default = self.startTagOther
396396

397397
self.endTagHandler = utils.MethodDispatcher([
398-
("html", self.endTagHtml)
398+
("html", self.endTagHtml),
399+
("br", self.endTagEmptyElement)
399400
])
400401
self.endTagHandler.default = self.endTagOther
401402

@@ -420,6 +421,10 @@ def endTagHtml(self, name):
420421
self.startTagHead("head", {})
421422
self.parser.phase.processEndTag(name)
422423

424+
def endTagEmptyElement(self, name):
425+
self.startTagHead("head", {})
426+
self.parser.phase.processEndTag(name)
427+
423428
def endTagOther(self, name):
424429
self.parser.parseError(_("Unexpected end tag (" + name +\
425430
") after the (implied) root element."))
@@ -441,6 +446,7 @@ def __init__(self, parser, tree):
441446
self. endTagHandler = utils.MethodDispatcher([
442447
("head", self.endTagHead),
443448
("html", self.endTagHtml),
449+
("br", self.endTagEmptyElement),
444450
(("title", "style", "script"), self.endTagTitleStyleScript)
445451
])
446452
self.endTagHandler.default = self.endTagOther
@@ -526,6 +532,10 @@ def endTagTitleStyleScript(self, name):
526532
self.parser.parseError(_(u"Unexpected end tag (" + name +\
527533
"). Ignored."))
528534

535+
def endTagEmptyElement(self, name):
536+
self.anythingElse()
537+
self.parser.phase.processEndTag(name)
538+
529539
def endTagOther(self, name):
530540
self.parser.parseError(_(u"Unexpected end tag (" + name +\
531541
"). Ignored."))
@@ -645,7 +655,8 @@ def __init__(self, parser, tree):
645655
(("head", "frameset", "select", "optgroup", "option", "table",
646656
"caption", "colgroup", "col", "thead", "tfoot", "tbody", "tr",
647657
"td", "th"), self.endTagMisplaced),
648-
(("area", "basefont", "bgsound", "br", "embed", "hr", "image",
658+
("br", self.endTagBr),
659+
(("area", "basefont", "bgsound", "embed", "hr", "image",
649660
"img", "input", "isindex", "param", "spacer", "wbr", "frame"),
650661
self.endTagNone),
651662
(("noframes", "noscript", "noembed", "textarea", "xmp", "iframe"),
@@ -1097,6 +1108,12 @@ def endTagMisplaced(self, name):
10971108
self.parser.parseError(_(u"Unexpected end tag (" + name +\
10981109
u"). Ignored."))
10991110

1111+
def endTagBr(self, name):
1112+
self.parser.parseError(_(u"Unexpected end tag (br). Treated as br element."))
1113+
self.tree.reconstructActiveFormattingElements()
1114+
self.tree.insertElement(name, {})
1115+
self.tree.openElements.pop()
1116+
11001117
def endTagNone(self, name):
11011118
# This handles elements with no end tag.
11021119
self.parser.parseError(_(u"This tag (" + name + u") has no end tag"))
@@ -1239,10 +1256,10 @@ def endTagOther(self, name):
12391256
self.parser.parseError(_(u"Unexpected end tag (" + name + u") in "
12401257
u"table context caused voodoo mode."))
12411258
# Make all the special element rearranging voodoo kick in
1242-
self.parser.insertFromTable = True
1259+
self.tree.insertFromTable = True
12431260
# Process the end tag in the "in body" mode
12441261
self.parser.phases["inBody"].processEndTag(name)
1245-
self.parser.insertFromTable = False
1262+
self.tree.insertFromTable = False
12461263

12471264

12481265
class InCaptionPhase(Phase):

0 commit comments

Comments
 (0)