5 Commits
1.0.0 ... 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
ae97b9e464 \\ fix 2025-11-09 18:37:20 +07:00
692d4c3482 use function 2025-11-09 18:30:35 +07:00
5820d0b350 fix composer 2025-11-09 18:22:43 +07:00
3 changed files with 37 additions and 47 deletions

View File

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

View File

@@ -3,10 +3,7 @@
"description": "Library for escaping all markdown symbols", "description": "Library for escaping all markdown symbols",
"homepage": "https://git.svoboda.works/mirzaev/unmarkdown", "homepage": "https://git.svoboda.works/mirzaev/unmarkdown",
"type": "library", "type": "library",
"keywords": [ "keywords": ["markdown", "escaping"],
"markdown",
"escaping"
],
"readme": "README.md", "readme": "README.md",
"license": "WTFPL", "license": "WTFPL",
"authors": [ "authors": [
@@ -24,13 +21,6 @@
"php": "^8.4" "php": "^8.4"
}, },
"autoload": { "autoload": {
"psr-4": { "files": ["mirzaev/unmarkdown/system/unmarkdown.php"]
"mirzaev\\unmarkdown\\": "mirzaev/unmarkdown/system"
}
},
"autoload-dev": {
"psr-4": {
"mirzaev\\unmarkdown\\tests\\": "mirzaev/unmarkdown/tests"
}
} }
} }

View File

@@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace mirzaev\unmarkdown; namespace mirzaev;
/** /**
* Escape all markdown symbols * Escape all markdown symbols
@@ -13,37 +13,37 @@ namespace mirzaev\unmarkdown;
* @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);
} }