Files
hustoj/web/admin/md_check.php
2024-12-07 17:52:09 +08:00

18 lines
733 B
PHP

<?php
function decodeMarkdownEntities($markdown) {
// Decode HTML entities in code blocks
// $markdown = preg_replace_callback('/(```.*?```|`[^`]*`)/s', function ($matches) {
// return htmlentities($matches[0], ENT_QUOTES, 'UTF-8');
// }, $markdown);
// Remove <br /> tags in code blocks
$markdown = preg_replace_callback('/(```.*?```|`[^`]*`)/s', function ($matches) {
return str_replace('<br />', '', $matches[0]);
}, $markdown);
// Decode HTML entities in inline math and display math
$markdown = preg_replace_callback('/(\$\$.*?\$\$|\$[^$]*\$)/s', function ($matches) {
return htmlentities($matches[0], ENT_QUOTES, 'UTF-8');
}, $markdown);
return $markdown;
}