/** * @param DataObjectInterface $dataObject * * @return $this */ public function changeLineType(DataObjectInterface $dataObject) { $nextLineNumber = $this->lineNumber + 1; if (!$dataObject->hasLine($nextLineNumber)) { return $this; } $nextLineObject = $dataObject->getLine($nextLineNumber); if (!is_a($nextLineObject, static::class)) { $this->setContent($this->clearBlockQuoteMarkup($this->getContent())); return $this; } $changeNextLine = true; $max = $dataObject->count(); $updatedLines = []; for ($i = $this->lineNumber; $i < $max; $i++) { $currentLineObject = $dataObject->getLine($i); $updatedLines[] = $this->clearBlockQuoteMarkup($currentLineObject->getContent()); $nextLineObject = $dataObject->getLine($i + 1); $nextSecondLineObject = $dataObject->getLine($i + 2); if (!$this->lineIsObjectOf($nextLineObject, static::class) && !$this->lineIsObjectOf($nextSecondLineObject, static::class)) { $changeNextLine = false; } $changedContent = $this->factory->create(BlockTypes::BLOCK_SKIP); $dataObject->updateLine($i, $changedContent); if ($changeNextLine === false) { break; } } $this->parseSubBlock($dataObject, $updatedLines); }
/** * @param DataObjectInterface $dataObject * * @return $this */ public function changeLineType(DataObjectInterface $dataObject) { $nextLineNumber = $this->lineNumber + 1; if (!$dataObject->hasLine($nextLineNumber)) { return $this; } $max = $dataObject->count(); $changeNextLine = true; $htmlCotent = []; for ($i = $this->lineNumber; $i < $max; $i++) { $currentLineObject = $dataObject->getLine($i); $htmlCotent[] = $currentLineObject->getContent(); $nextLineObject = $dataObject->getLine($i + 1); if (!$this->lineIsObjectOf($nextLineObject, BlockTypes::BLOCK_PARAGRAPH)) { $changeNextLine = false; } $this->createSkipLine($dataObject, $i); if ($changeNextLine === false) { break; } } $newLineObject = $this->factory->create(BlockTypes::BLOCK_PARAGRAPH); $newLineObject->setContent(implode(' ', $htmlCotent))->setLineNumber($this->lineNumber); $dataObject->updateLine($this->lineNumber, $newLineObject); return $this; }