summaryrefslogtreecommitdiff
path: root/vendor/league/commonmark/src/Normalizer/SlugNormalizer.php
diff options
context:
space:
mode:
authorGreg Roach <greg@subaqua.co.uk>2020-06-27 11:39:49 +0100
committerGreg Roach <greg@subaqua.co.uk>2020-06-27 11:39:49 +0100
commitbd0ff478da33656c3ba72eace965e6c0a71a0435 (patch)
tree31568744134c5a7d5835166bab1f640bd24e9651 /vendor/league/commonmark/src/Normalizer/SlugNormalizer.php
parent1b7bacc801fa6671beced176a48a0fb537951f25 (diff)
downloadwebtrees-bd0ff478da33656c3ba72eace965e6c0a71a0435.tar.gz
webtrees-bd0ff478da33656c3ba72eace965e6c0a71a0435.tar.bz2
webtrees-bd0ff478da33656c3ba72eace965e6c0a71a0435.zip
Update vendor dependencies
Diffstat (limited to 'vendor/league/commonmark/src/Normalizer/SlugNormalizer.php')
-rw-r--r--vendor/league/commonmark/src/Normalizer/SlugNormalizer.php37
1 files changed, 37 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;
+ }
+}