@php /** * Ambil isi slot (aman untuk HtmlString & string biasa) */ $code = $slot instanceof \Illuminate\Support\HtmlString ? $slot->toHtml() : (string) $slot; /** * 1. Hapus newline kosong di awal & akhir */ $code = preg_replace('/^\s*\n|\n\s*$/', '', $code); /** * 2. Normalisasi indent * Cari indent terkecil lalu hapus dari semua baris */ $lines = preg_split("/\r\n|\n|\r/", $code); $minIndent = null; foreach ($lines as $line) { if (trim($line) === '') { continue; } preg_match('/^\s*/', $line, $match); $indent = strlen($match[0]); if ($minIndent === null || $indent < $minIndent) { $minIndent = $indent; } } if ($minIndent && $minIndent > 0) { $lines = array_map(function ($line) use ($minIndent) { return preg_replace('/^\s{0,' . $minIndent . '}/', '', $line); }, $lines); } $code = implode("\n", $lines); @endphp
{{-- ================= Header ================= --}}
Blade Example
{{-- Copy Button --}} {{-- Window Dots --}}
{{-- ================= Code ================= --}}
{{ $code }}