From 6e7145c022c1a044700a840682a0bd8ee4e7b59a Mon Sep 17 00:00:00 2001 From: Dustin Wilson Date: Fri, 14 Sep 2018 16:05:20 -0500 Subject: [PATCH] More daily TreeBuilder stuff --- lib/TreeBuilder.php | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/TreeBuilder.php b/lib/TreeBuilder.php index 76087f5..3e1ea45 100644 --- a/lib/TreeBuilder.php +++ b/lib/TreeBuilder.php @@ -6,7 +6,7 @@ class TreeBuilder { // The list of active formatting elements, used when elements are improperly nested protected $activeFormattingElementsList; // The DOMDocument that is assembled by this class - public $DOM; + protected $DOM; // The form element pointer points to the last form element that was opened and // whose end tag has not yet been seen. It is used to make form controls associate // with forms in the face of dramatically bad markup, for historical reasons. It is @@ -1094,6 +1094,38 @@ class TreeBuilder { # Insert an HTML element for the token. $this->insertStartTagToken($token); } + # A start tag whose tag name is one of: "pre", "listing" + elseif ($token->name === 'pre' || $token->name === 'listing') { + # If the stack of open elements has a p element in button scope, then close a p + # element. + if ($this->stack->hasElementInButtonScope('p')) { + $this->closePElement(); + } + + # Insert an HTML element for the token. + $this->insertStartTagToken($token); + + # Set the frameset-ok flag to "not ok". + $this->framesetOk = false; + + # If the next token is a U+000A LINE FEED (LF) character token, then ignore that + # token and move on to the next one. (Newlines at the start of pre blocks are + # ignored as an authoring convenience.) + $nextToken = $this->tokenizer->createToken(); + if ($token instanceof CharacterToken) { + // Character tokens in this implementation can have more than one character in + // them. + if (strlen($token->data) === 1 && $token->data === "\n") { + return true; + } elseif (strpos($token->data, "\n") === 0) { + $token->data = substr($token->data, 1); + } + } + + // Process the next token + $token = $nextToken; + continue 2; + } } elseif ($token instanceof EndTagToken) { # An end tag whose tag name is "template"