created
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
!.gitignore
|
||||
composer.lock
|
||||
vendor
|
||||
17
README.md
17
README.md
@@ -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
36
composer.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
49
mirzaev/unmarkdown/system/unmarkdown.php
Normal file
49
mirzaev/unmarkdown/system/unmarkdown.php
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user