diff options
| author | Greg Roach <greg@subaqua.co.uk> | 2020-06-27 11:39:49 +0100 |
|---|---|---|
| committer | Greg Roach <greg@subaqua.co.uk> | 2020-06-27 11:39:49 +0100 |
| commit | bd0ff478da33656c3ba72eace965e6c0a71a0435 (patch) | |
| tree | 31568744134c5a7d5835166bab1f640bd24e9651 /vendor/league/commonmark/src/Normalizer | |
| parent | 1b7bacc801fa6671beced176a48a0fb537951f25 (diff) | |
| download | webtrees-bd0ff478da33656c3ba72eace965e6c0a71a0435.tar.gz webtrees-bd0ff478da33656c3ba72eace965e6c0a71a0435.tar.bz2 webtrees-bd0ff478da33656c3ba72eace965e6c0a71a0435.zip | |
Update vendor dependencies
Diffstat (limited to 'vendor/league/commonmark/src/Normalizer')
3 files changed, 114 insertions, 0 deletions
diff --git a/vendor/league/commonmark/src/Normalizer/SlugNormalizer.php b/vendor/league/commonmark/src/Normalizer/SlugNormalizer.php new file mode 100644 index 0000000000..3b6a06a64c --- /dev/null +++ b/vendor/league/commonmark/src/Normalizer/SlugNormalizer.php @@ -0,0 +1,37 @@ +<?php + +declare(strict_types=1); + +/* + * This file is part of the league/commonmark package. + * + * (c) Colin O'Dell <colinodell@gmail.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace League\CommonMark\Normalizer; + +/** + * Creates URL-friendly strings based on the given string input + */ +final class SlugNormalizer implements TextNormalizerInterface +{ + /** + * {@inheritdoc} + */ + public function normalize(string $text, $context = null): string + { + // Trim whitespace + $slug = \trim($text); + // Convert to lowercase + $slug = \mb_strtolower($slug); + // Try replacing whitespace with a dash + $slug = \preg_replace('/\s+/u', '-', $slug) ?? $slug; + // Try removing characters other than letters, numbers, and marks. + $slug = \preg_replace('/[^\p{L}\p{Nd}\p{Nl}\p{M}-]+/u', '', $slug) ?? $slug; + + return $slug; + } +} diff --git a/vendor/league/commonmark/src/Normalizer/TextNormalizer.php b/vendor/league/commonmark/src/Normalizer/TextNormalizer.php new file mode 100644 index 0000000000..e662600faa --- /dev/null +++ b/vendor/league/commonmark/src/Normalizer/TextNormalizer.php @@ -0,0 +1,51 @@ +<?php + +/* + * This file is part of the league/commonmark package. + * + * (c) Colin O'Dell <colinodell@gmail.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace League\CommonMark\Normalizer; + +/*** + * Normalize text input using the steps given by the CommonMark spec to normalize labels + * + * @see https://spec.commonmark.org/0.29/#matches + */ +final class TextNormalizer implements TextNormalizerInterface +{ + /** + * @var array<int, array<int, string>> + * + * Source: https://github.com/symfony/polyfill-mbstring/blob/master/Mbstring.php + */ + private const CASE_FOLD = [ + ['µ', 'ſ', "\xCD\x85", 'ς', "\xCF\x90", "\xCF\x91", "\xCF\x95", "\xCF\x96", "\xCF\xB0", "\xCF\xB1", "\xCF\xB5", "\xE1\xBA\x9B", "\xE1\xBE\xBE", "\xC3\x9F", "\xE1\xBA\x9E"], + ['μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "\xE1\xB9\xA1", 'ι', 'ss', 'ss'], + ]; + + /** + * {@inheritdoc} + */ + public function normalize(string $text, $context = null): string + { + // Collapse internal whitespace to single space and remove + // leading/trailing whitespace + $text = \preg_replace('/\s+/', ' ', \trim($text)); + + if (!\defined('MB_CASE_FOLD')) { + // We're not on a version of PHP (7.3+) which has this feature + $text = \str_replace(self::CASE_FOLD[0], self::CASE_FOLD[1], $text); + + return \mb_strtolower($text, 'UTF-8'); + } + + return \mb_convert_case($text, \MB_CASE_FOLD, 'UTF-8'); + } +} diff --git a/vendor/league/commonmark/src/Normalizer/TextNormalizerInterface.php b/vendor/league/commonmark/src/Normalizer/TextNormalizerInterface.php new file mode 100644 index 0000000000..c1a9eb12c4 --- /dev/null +++ b/vendor/league/commonmark/src/Normalizer/TextNormalizerInterface.php @@ -0,0 +1,26 @@ +<?php + +declare(strict_types=1); + +/* + * This file is part of the league/commonmark package. + * + * (c) Colin O'Dell <colinodell@gmail.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace League\CommonMark\Normalizer; + +/** + * Creates a normalized version of the given input text + */ +interface TextNormalizerInterface +{ + /** + * @param string $text The text to normalize + * @param mixed $context Additional context about the text being normalized (optional) + */ + public function normalize(string $text, $context = null): string; +} |
