1<?php 2 3/* 4 * This file is part of the league/commonmark package. 5 * 6 * (c) Colin O'Dell <colinodell@gmail.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12declare(strict_types=1); 13 14namespace League\CommonMark\Normalizer; 15 16/*** 17 * Normalize text input using the steps given by the CommonMark spec to normalize labels 18 * 19 * @see https://spec.commonmark.org/0.29/#matches 20 * 21 * @psalm-immutable 22 */ 23final class TextNormalizer implements TextNormalizerInterface 24{ 25 /** 26 * {@inheritDoc} 27 * 28 * @psalm-pure 29 */ 30 public function normalize(string $text, array $context = []): string 31 { 32 // Collapse internal whitespace to single space and remove 33 // leading/trailing whitespace 34 $text = \preg_replace('/[ \t\r\n]+/', ' ', \trim($text)); 35 \assert(\is_string($text)); 36 37 return \mb_convert_case($text, \MB_CASE_FOLD, 'UTF-8'); 38 } 39} 40