PHP
Markdown sang PHP
(Hướng dẫn từ ChatGPT)
- Tải thư viện Vào trang web Parsedown tải thư viện coppy vào dự án
- Tạo các file theo cấu trúc
project/ ├─ index.php ├─ libs/ │ └─ Parsedown.php ├─ docs/ ├─ huongdan.md ├─ caidat.md └─ trogiup.md -
Code index.php
<?php require_once __DIR__ . '/libs/Parsedown.php'; $Parsedown = new Parsedown(); // Thư mục chứa file markdown $docsDir = __DIR__ . '/docs'; // Lấy danh sách file .md trong thư mục docs $files = array_filter(scandir($docsDir), function($f) { return pathinfo($f, PATHINFO_EXTENSION) === 'md'; }); // Xác định file cần hiển thị $currentFile = $_GET['file'] ?? $files[0] ?? null; $content = ''; if ($currentFile && file_exists("$docsDir/$currentFile")) { $markdown = file_get_contents("$docsDir/$currentFile"); $content = $Parsedown->text($markdown); } ?> <!DOCTYPE html> <html lang="vi"> <head> <meta charset="UTF-8"> <title>Tài liệu</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"> <style> body { display: flex; } .sidebar { width: 250px; height: 100vh; border-right: 1px solid #ddd; padding: 1rem; } .content { flex: 1; padding: 2rem; } .sidebar a { display: block; padding: .5rem 0; text-decoration: none; } .sidebar a.active { font-weight: bold; color: #0d6efd; } </style> </head> <body> <!-- Sidebar --> <div class="sidebar"> <h4>📚 Docs</h4> <?php foreach ($files as $f): ?> <a href="?file=<?=$f?>" class="<?=($f === $currentFile ? 'active' : '')?>"> <?=ucfirst(pathinfo($f, PATHINFO_FILENAME))?> </a> <?php endforeach; ?> </div> <!-- Nội dung --> <div class="content"> <?=$content ?: '<p>Chưa có tài liệu.</p>'?> </div> </body> </html>
4. Viết file Markdown (ví dụ docs/huongdan.md)
## Cài đặt
Tải về phần mềm
Chạy setup.exe
## Ghi chú
Yêu cầu Windows
Cần kết nối mạng
<h1 id="java">Java
</h1>
<h1 id="css">CSS</h1>