Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a0309030f6 | |||
| 929b6401cc | |||
| ae97b9e464 | |||
| 692d4c3482 | |||
| 5820d0b350 |
@@ -1,9 +1,9 @@
|
||||
# unmarkdorn
|
||||
# unmarkdown
|
||||
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\\!\\*"
|
||||
```
|
||||
|
||||
@@ -3,10 +3,7 @@
|
||||
"description": "Library for escaping all markdown symbols",
|
||||
"homepage": "https://git.svoboda.works/mirzaev/unmarkdown",
|
||||
"type": "library",
|
||||
"keywords": [
|
||||
"markdown",
|
||||
"escaping"
|
||||
],
|
||||
"keywords": ["markdown", "escaping"],
|
||||
"readme": "README.md",
|
||||
"license": "WTFPL",
|
||||
"authors": [
|
||||
@@ -24,13 +21,6 @@
|
||||
"php": "^8.4"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"mirzaev\\unmarkdown\\": "mirzaev/unmarkdown/system"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"mirzaev\\unmarkdown\\tests\\": "mirzaev/unmarkdown/tests"
|
||||
}
|
||||
"files": ["mirzaev/unmarkdown/system/unmarkdown.php"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace mirzaev\unmarkdown;
|
||||
namespace mirzaev;
|
||||
|
||||
/**
|
||||
* Escape all markdown symbols
|
||||
@@ -13,37 +13,37 @@ namespace mirzaev\unmarkdown;
|
||||
* @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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user