修复md格式错误的问题

This commit is contained in:
2024-12-07 17:50:09 +08:00
parent fea3ec456d
commit c5600b7244
2 changed files with 6 additions and 8 deletions

View File

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