$1', $text); $text = preg_replace('/^## (.*$)/m', '
$2', $text);
$text = preg_replace('/`(.+?)`/', '$1', $text);
// 链接
$text = preg_replace('/\[(.+?)\]\((.+?)\)/', '$1', $text);
// 列表
$text = preg_replace('/^- (.*$)/m', '', $text); $text = '
' . $text . '
'; return $text; } // 高亮搜索词 function highlightSearch($text, $search) { if (empty($search)) return $text; return preg_replace('/(' . preg_quote($search, '/') . ')/i', '$1', $text); } $htmlContent = markdownToHtml(htmlspecialchars($content)); if ($search) { $htmlContent = highlightSearch($htmlContent, $search); } // 获取文件名(不含路径) $displayName = basename($file); $folder = dirname($file) !== '.' ? dirname($file) : ''; ?>