$1', $text); $text = preg_replace('/^## (.*$)/m', '

$1

', $text); $text = preg_replace('/^# (.*$)/m', '

$1

', $text); // 粗体和斜体 $text = preg_replace('/\*\*(.+?)\*\*/', '$1', $text); $text = preg_replace('/\*(.+?)\*/', '$1', $text); // 代码块 $text = preg_replace('/```(\w*)\n(.*?)```/s', '
$2
', $text); $text = preg_replace('/`(.+?)`/', '$1', $text); // 链接 $text = preg_replace('/\[(.+?)\]\((.+?)\)/', '$1', $text); // 列表 $text = preg_replace('/^- (.*$)/m', '
  • $1
  • ', $text); $text = preg_replace('/(
  • .*<\/li>\n?)+/', '', $text); // 段落 $text = preg_replace('/\n\n/', '

    ', $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) : ''; ?> <?php echo htmlspecialchars($displayName); ?> - 知识库
    ← 返回列表

    📁