2 Commits
1.0.3 ... 1.0.5

Author SHA1 Message Date
a0309030f6 unmarkdorn 2026-01-14 15:49:12 +05:00
929b6401cc just formatted 2026-01-14 15:28:39 +05:00
2 changed files with 33 additions and 33 deletions

View File

@@ -1,4 +1,4 @@
# unmarkdorn # unmarkdown
Library for escaping all markdown symbols Library for escaping all markdown symbols
```php ```php

View File

@@ -13,37 +13,37 @@ namespace mirzaev;
* @return string Escaped text * @return string Escaped text
*/ */
function unmarkdown(string $text, array $exceptions = []): string function unmarkdown(string $text, array $exceptions = []): string
{ {
// Initializing the registry of characters for escaping // Initializing the registry of characters for escaping
$from = array_diff( $from = array_diff(
[ [
'.', '.',
'#', '#',
'*', '*',
'-', '-',
'_', '_',
'=', '=',
'[', '[',
']', ']',
'{', '{',
'}', '}',
'(', '(',
')', ')',
'>', '>',
'<', '<',
'!', '!',
'`', '`',
'\\\\', '\\\\',
'|', '|',
'+' '+'
], ],
$exceptions $exceptions
); );
// Initializing the registry of escaped characters // Initializing the registry of escaped characters
$to = []; $to = [];
foreach ($from as $symbol) $to[] = "\\$symbol"; foreach ($from as $symbol) $to[] = "\\$symbol";
// Escaping the text and exit (success) // Escaping the text and exit (success)
return str_replace($from, $to, $text); return str_replace($from, $to, $text);
} }