3 Commits
1.0.1 ... 1.0.4

Author SHA1 Message Date
929b6401cc just formatted 2026-01-14 15:28:39 +05:00
ae97b9e464 \\ fix 2025-11-09 18:37:20 +07:00
692d4c3482 use function 2025-11-09 18:30:35 +07:00
2 changed files with 33 additions and 33 deletions

View File

@@ -3,7 +3,7 @@ Library for escaping all markdown symbols
```php
// Library for escaping all markdown symbols
use mirzaev\unmarkdown\unmarkdown;
use function mirzaev\unmarkdown;
var_dump(unmarkdown('*Hello!*')); // "\\*Hello\\!\\*"
```

View File

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