• Модуль: landing
  • Путь к файлу: ~/bitrix/modules/landing/lib/note/source/parser.php
  • Класс: BitrixLandingNoteSourceParser
  • Вызов: Parser::textToBlocks
static function textToBlocks(string $text, array $params = []): array
{
	$count = -1;
	$blocks = [];

	$dom = new DOMDocument;
	$text = self::convertText($text);
	$dom->loadHTML($text);

	foreach ($dom->getChildNodesArray() as $child)
	{
		$bewBlock = self::getBlockFromNode($child, $params);
		if ($bewBlock)
		{
			if (
				$blocks &&
				$bewBlock['type'] == 'text' &&
				$blocks[$count]['type'] == 'text'
			)
			{
				$blocks[$count]['content'] .= $bewBlock['content'];
			}
			else
			{
				$count++;
				$blocks[] = $bewBlock;
			}
		}
	}

	// trim block content
	foreach ($blocks as $key => $item)
	{
		if ($item['type'] == 'text')
		{
			if (!trim(str_replace(['
', '
'], '', $item['content']))) { unset($blocks[$key]); } } } return array_values($blocks); }