增加一个函数统一处理markdown的问题

This commit is contained in:
2024-12-07 17:39:58 +08:00
parent 6f20a9ef73
commit b011e37b4d
3 changed files with 29 additions and 41 deletions

17
web/admin/md_check.php Normal file
View File

@@ -0,0 +1,17 @@
<?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);
// 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);
// 特殊转义
$markdown = str_replace("<p>", "", $markdown);
$markdown = str_replace("</p>", "\n\n", $markdown);
$markdown = str_replace("<br />", "\n\n", $markdown);
return $markdown;
}