<commit_before><?php
namespace WordpressLib\Posts;

abstract class ContentObjectElements extends ContentObjects {

	abstract protected function createItemFromElement($el);

	protected function getHtmlElements($doc) {
		return $doc->childNodes;
	}

	public function transformTags() {
		if ($this->count() && ($html = implode('', $this->getArrayCopy()))) {
			$doc = new \DOMDocument();
			$doc->loadXML($html);
			foreach ($this->getHtmlElements($doc) as $el) {
				$items[] = $this->createItemFromElement($el);
			}
		}
		$this->exchangeArray(isset($items) ? $items : []);
	}

}
<commit_msg>Recursive content extraction<commit_after><?php
namespace WordpressLib\Posts;

abstract class ContentObjectElements extends ContentObjects {

	abstract protected function createItemFromElement($el);
	abstract protected function isObjectElement($el);

	protected function recursiveNodeWalk($node) {
		foreach ($node->childNodes as $child) {
			if ($this->isObjectElement($child)) $this->append($this->createItemFromElement($child));
			if ($child->childNodes) $this->recursiveNodeWalk($child);
		}
	}

	public function transformTags() {
		if ($this->count() && ($html = implode('', $this->getArrayCopy()))) {
			$doc = new \DOMDocument();
			$doc->loadXML('<p>'.$html.'</p>');
			$this->exchangeArray([]);
			$this->recursiveNodeWalk($doc);
			$this->exchangeArray(array_unique($this->getArrayCopy()));
		}
	}

}

{'fraction_non_alphanumeric': 0.17320028510334998, 'fraction_numerical': 0.0, 'mean_word_length': 5.530232558139535, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5432105', 'n_tokens_mistral': 468, 'n_tokens_neox': 420, 'n_words': 83}