public function process(TextDocument $doc) { $changes = false; $textBlocks = $doc->getTextBlocks(); foreach ($textBlocks as $tb) { if (!$tb->isContent() && ($this->labelToKeep == null || !$tb->hasLabel($this->labelToKeep))) { $doc->removeTextBlock($tb); $changes = true; } } return $changes; }
public function process(TextDocument $doc) { $textBlocks = $doc->getTextBlocks(); if (count($textBlocks) < 2) { return false; } $changes = false; $offset = 0; if ($this->contentOnly) { $prevBlock = null; foreach ($textBlocks as $tb) { $offset++; if ($tb->isContent()) { $prevBlock = $tb; break; } } } else { $prevBlock = $textBlocks[0]; $offset = 1; } for ($i = $offset, $l = count($textBlocks); $i < $l; $i++) { $tb = $textBlocks[$i]; if (!$tb->isContent()) { continue; } $diffBlocks = $tb->getStartOffset() - $prevBlock->getEndOffset() - 1; if ($diffBlocks <= $this->maxBlocksDistance) { $ok = true; if ($this->contentOnly) { if (!$prevBlock->isContent() || !$tb->isContent()) { $ok = false; } } if ($ok && $this->sameTagLevelOnly && $prevBlock->getLevel() != $tb->getLevel()) { $ok = false; } if ($ok) { $prevBlock->mergeNext($tb); $doc->removeTextBlock($tb); $changes = true; } else { $prevBlock = $tb; } } else { $prevBlock = $tb; } } return $changes; }