1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Hyde\Foundation\Concerns; |
6
|
|
|
|
7
|
|
|
use Hyde\Framework\Services\MarkdownService; |
8
|
|
|
use Hyde\Markdown\Models\Markdown; |
9
|
|
|
use Illuminate\Support\HtmlString; |
10
|
|
|
use Illuminate\Support\Str; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @internal Single-use trait for the HydeKernel class. |
14
|
|
|
* |
15
|
|
|
* @see \Hyde\Foundation\HydeKernel |
16
|
|
|
*/ |
17
|
|
|
trait ImplementsStringHelpers |
18
|
|
|
{ |
19
|
|
|
public static function makeTitle(string $value): string |
20
|
|
|
{ |
21
|
|
|
$alwaysLowercase = ['a', 'an', 'the', 'in', 'on', 'by', 'with', 'of', 'and', 'or', 'but']; |
22
|
|
|
|
23
|
|
|
return ucfirst(str_ireplace( |
|
|
|
|
24
|
|
|
$alwaysLowercase, |
25
|
|
|
$alwaysLowercase, |
26
|
|
|
Str::headline($value) |
27
|
|
|
)); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public static function normalizeNewlines(string $string): string |
31
|
|
|
{ |
32
|
|
|
return str_replace("\r\n", "\n", $string); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public static function stripNewlines(string $string): string |
36
|
|
|
{ |
37
|
|
|
return str_replace(["\r\n", "\n"], '', $string); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public static function trimSlashes(string $string): string |
41
|
|
|
{ |
42
|
|
|
return trim($string, '/\\'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public static function markdown(string $text, bool $normalizeIndentation = false): HtmlString |
46
|
|
|
{ |
47
|
|
|
if ($normalizeIndentation) { |
48
|
|
|
$text = MarkdownService::normalizeIndentationLevel($text); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return new HtmlString(Markdown::render($text)); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|