'strip', 'allow_unsafe_links' => false, ]); // 萃取 TOC (簡單的正則表達式抓取 ## 標題) preg_match_all('/^##\s+(.+)$/m', $markdown, $matches); $toc = collect($matches[1])->map(function ($text) { return [ 'id' => Illuminate\Support\Str::slug($text), 'text' => $text, ]; }); // 替換內容中的 ## 標題以加入 ID 錨點 (讓左側導覽能跳轉) foreach ($toc as $item) { $content = str_replace("