diff --git a/src/Components/Blocks/Comment.php b/src/Components/Blocks/Comment.php deleted file mode 100644 index 6ffedc4..0000000 --- a/src/Components/Blocks/Comment.php +++ /dev/null @@ -1,88 +0,0 @@ -html = $html; - $this->isClosed = $isClosed; - } - - /** - * @param Context $Context - * @param Block|null $Block - * @param State|null $State - * @return static|null - */ - public static function build( - Context $Context, - Block $Block = null, - State $State = null - ) { - if (\strpos($Context->line()->text(), '') !== false - ); - } - - return null; - } - - /** - * @param Context $Context - * @return self|null - */ - public function advance(Context $Context) - { - if ($this->isClosed) { - return null; - } - - return new self( - $this->html . "\n" . $Context->line()->rawLine(), - \strpos($Context->line()->text(), '-->') !== false - ); - } - - /** - * @return Handler - */ - public function stateRenderable() - { - return new Handler( - /** @return Text|RawHtml */ - function (State $State) { - if ($State->get(SafeMode::class)->isEnabled()) { - return new Text($this->html); - } else { - return new RawHtml($this->html); - } - } - ); - } -} diff --git a/src/Components/Blocks/Markup.php b/src/Components/Blocks/Markup.php index bdb5576..6d5a471 100644 --- a/src/Components/Blocks/Markup.php +++ b/src/Components/Blocks/Markup.php @@ -19,15 +19,33 @@ final class Markup implements ContinuableBlock const REGEX_HTML_ATTRIBUTE = '[a-zA-Z_:][\w:.-]*+(?:\s*+=\s*+(?:[^"\'=<>`\s]+|"[^"]*+"|\'[^\']*+\'))?+'; + /** @var array{2: string, 3: string, 4: string, 5: string} */ + private static $simpleContainsEndConditions = [ + 2 => '-->', + 3 => '?>', + 4 => '>', + 5 => ']]>' + ]; + /** @var string */ private $html; + /** @var 1|2|3|4|5|6|7 */ + private $type; + + /** @var bool */ + private $closed; + /** * @param string $html + * @param 1|2|3|4|5|6|7 $type + * @param bool $closed */ - public function __construct($html) + private function __construct($html, $type, $closed = false) { $this->html = $html; + $this->type = $type; + $this->closed = $closed; } /** @@ -41,15 +59,40 @@ final class Markup implements ContinuableBlock Block $Block = null, State $State = null ) { - if (\preg_match('/^<[\/]?+(\w*)(?:[ ]*+'.self::REGEX_HTML_ATTRIBUTE.')*+[ ]*+(\/)?>/', $Context->line()->text(), $matches)) { + $text = $Context->line()->text(); + $rawLine = $Context->line()->rawLine(); + + if (\preg_match('/^<(?:script|pre|style)(?:\s++|>|$)/i', $text)) { + return new self($rawLine, 1, self::closes12345TypeMarkup(1, $text)); + } + + if (\substr($text, 0, 4) === '