8000 add some simple <noscript> in <head> support; (scripting 'enabled') · awesome-python/html5lib-python@6867d5e · GitHub
[go: up one dir, main page]

Skip to content

Commit 6867d5e

Browse files
committed
add some simple <noscript> in <head> support; (scripting 'enabled')
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40864
1 parent fdefef3 commit 6867d5e

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/html5lib/html5parser.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def __init__(self, strict = False, tree=simpletree.TreeBuilder, tokenizer=tokeni
5656
"rootElement": RootElementPhase(self, self.tree),
5757
"beforeHead": BeforeHeadPhase(self, self.tree),
5858
"inHead": InHeadPhase(self, self.tree),
59+
# XXX "inHeadNoscript": InHeadNoScriptPhase(self, self.tree),
5960
"afterHead": AfterHeadPhase(self, self.tree),
6061
"inBody": InBodyPhase(self, self.tree),
6162
"inTable": InTablePhase(self, self.tree),
@@ -516,6 +517,7 @@ def __init__(self, parser, tree):
516517
("html", self.startTagHtml),
517518
("title", self.startTagTitle),
518519
("style", self.startTagStyle),
520+
("noscript", self.startTagNoScript),
519521
("script", self.startTagScript),
520522
(("base", "link", "meta"), self.startTagBaseLinkMeta),
521523
("head", self.startTagHead)
@@ -525,7 +527,8 @@ def __init__(self, parser, tree):
525527
self. endTagHandler = utils.MethodDispatcher([
526528
("head", self.endTagHead),
527529
(("html", "body", "br", "p"), self.endTagImplyAfterHead),
528-
(("title", "style", "script"), self.endTagTitleStyleScript)
530+
(("title", "style", "script", "noscript"),
531+
self.endTagTitleStyleScriptNoScript)
529532
])
530533
self.endTagHandler.default = self.endTagOther
531534

@@ -547,7 +550,8 @@ def processEOF(self):
547550
self.parser.phase.processEOF()
548551

549552
def processCharacters(self, data):
550-
if self.tree.openElements[-1].name in ("title", "style", "script"):
553+
if self.tree.openElements[-1].name in\
554+
("title", "style", "script", "noscript"):
551555
self.tree.insertText(data)
552556
else:
553557
self.anythingElse()
@@ -572,6 +576,17 @@ def startTagStyle(self, name, attributes):
572576
self.tree.openElements.append(element)
573577
self.parser.tokenizer.contentModelFlag = contentModelFlags["CDATA"]
574578

579+
def startTagNoScript(self, name, attributes):
580+
# XXX Need to decide whether to implement the scripting disabled case.
581+
element = self.tree.createElement(name, attributes)
582+
if self.tree.headPointer is not None and\
583+
self.parser.phase == self.parser.phases["inHead"]:
584+
self.appendToHead(element)
585+
else:
586+
self.tree.openElements[-1].appendChild(element)
587+
self.tree.openElements.append(element)
588+
self.parser.tokenizer.contentModelFlag = contentModelFlags["CDATA"]
589+
575590
def startTagScript(self, name, attributes):
576591
#XXX Inner HTML case may be wrong
577592
element = self.tree.createElement(name, attributes)
@@ -607,7 +622,7 @@ def endTagImplyAfterHead(self, name):
607622
self.anythingElse()
608623
self.parser.phase.processEndTag(name)
609624

610-
def endTagTitleStyleScript(self, name):
625+
def endTagTitleStyleScriptNoScript(self, name):
611626
if self.tree.openElements[-1].name == name:
612627
self.tree.openElements.pop()
613628
else:
@@ -624,6 +639,11 @@ def anythingElse(self):
624639
else:
625640
self.parser.phase = self.parser.phases["afterHead"]
626641

642+
# XXX If we implement a parser for which scripting is disabled we need to
643+
# implement this phase.
644+
#
645+
# class InHeadNoScriptPhase(Phase):
646+
627647
class AfterHeadPhase(Phase):
628648
def __init__(self, parser, tree):
629649
Phase.__init__(self, parser, tree)

0 commit comments

Comments
 (0)
0