private static function get_edge_textnode( callable $get_textnode, \DOMNode $node = null, $recursive = false, $reverse = false ) {
		if ( ! isset( $node ) ) {
			return null;
		}

		if ( $node instanceof \DOMText ) {
			return $node;
		} elseif ( ! $node instanceof \DOMElement || $recursive && self::is_block_tag( $node ) ) {
			// Return null if $node is neither \DOMText nor \DOMElement or
			// when we are recursing and already at the block level.
			return null;
		}

		$edge_textnode = null;

		if ( $node->hasChildNodes() ) {
			$children    = $node->childNodes;
			$max         = $children->length;
			$index       = $reverse ? $max - 1 : 0;
			$incrementor = $reverse ? -1 : +1;

			while ( $index >= 0 && $index < $max && null === $edge_textnode ) {
				$edge_textnode = $get_textnode( $children->item( $index ), true );
				$index        += $incrementor;
			}
		}

		return $edge_textnode;
	}