This commit is contained in:
2025-11-09 17:46:01 +07:00
parent 0b97318456
commit 5850475b49
4 changed files with 103 additions and 2 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
!.gitignore
composer.lock
vendor

View File

@@ -1,3 +1,16 @@
# unmarkdown
# unmarkdorn
Library for escaping all markdown symbols
```php
// Library for escaping all markdown symbols
use mirzaev\unmarkdown\unmarkdown;
var_dump(unmarkdown('*Hello!*')); // "\\*Hello\\!\\*"
```
## Installation
```bash
composer require mirzaev/unmarkdown
```
Escaping all markdown symbols

36
composer.json Normal file
View File

@@ -0,0 +1,36 @@
{
"name": "mirzaev/unmarkdown",
"description": "Library for escaping all markdown symbols",
"homepage": "https://git.svoboda.works/mirzaev/unmarkdown",
"type": "library",
"keywords": [
"markdown",
"escaping"
],
"readme": "README.md",
"license": "WTFPL",
"authors": [
{
"name": "Arsen Mirzaev Tatyano-Muradovich",
"email": "arsen@mirzaev.sexy",
"homepage": "https://mirzaev.sexy",
"role": "Creator"
}
],
"support": {
"issues": "https://git.svoboda.works/mirzaev/unmarkdown/issues"
},
"require": {
"php": "^8.4"
},
"autoload": {
"psr-4": {
"mirzaev\\unmarkdown\\": "mirzaev/unmarkdown/system"
}
},
"autoload-dev": {
"psr-4": {
"mirzaev\\unmarkdown\\tests\\": "mirzaev/unmarkdown/tests"
}
}
}

View File

@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
namespace mirzaev\unmarkdown;
/**
* Escape all markdown symbols
*
* @param string $text Text for escaping
* @param array $exception Characters to be excluded from the escape list
*
* @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 escaped characters
$to = [];
foreach ($from as $symbol) $to[] = "\\$symbol";
// Escaping the text and exit (success)
return str_replace($from, $to, $text);
}