• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/Service/Timeline/Layout/Body/ContentBlock/ContentBlockFactory.php
  • Класс: Bitrix\Crm\Service\Timeline\Layout\Body\ContentBlock\ContentBlockFactory
  • Вызов: ContentBlockFactory::createFromHtmlString
static function createFromHtmlString(string $html, $idPrefix = ''): LineOfTextBlocks
{
	$lineOfTextBlocks = new LineOfTextBlocks();
	preg_match_all('/<([^\s>]+)(.*?)>((.*?)<\/\1>)?|(?<=^|>)(.+?)(?=$|<)/i',$html,$result);
	// assign the result to the variable
	foreach ($result[0] as $index => $text)
	{
		$block = null;
		$isHtmlTag = (substr($text, 0, 1) === '<');
		if ($isHtmlTag)
		{
			$tag = mb_strtolower($result[1][$index]);
			if ($tag === 'a')
			{
				$block = (new Link())
					->setValue(strip_tags($text))
				;

				preg_match('/href=["\']?([^"\'>]+)["\']?/', $text, $href);
				$url = isset($href[1]) ? new Uri($href[1]) : null;

				if ($url)
				{
					$block->setAction(
						new Action\Redirect($url)
					);
				}
			}
			else
			{
				$block = (new Text())
					->setValue(strip_tags($text))
					->setIsBold($tag === 'b')
				;
			}
		}
		else
		{
			$block = (new Text())->setValue($text);
		}

		$lineOfTextBlocks->addContentBlock($idPrefix . $index, $block);
	}

	return $lineOfTextBlocks;
}