feat(wip): Add code syntax highlighting

This commit is contained in:
2026-01-20 04:17:03 +03:00
parent 6e8c3f911d
commit 5df865ee3b
5 changed files with 511 additions and 105 deletions

View File

@@ -9,6 +9,7 @@ import remarkGfm from 'remark-gfm';
import remarkRehype from 'remark-rehype';
import rehypeRaw from 'rehype-raw';
import rehypeStringify from 'rehype-stringify';
import rehypePrism from 'rehype-prism-plus';
const postsDirectory = path.join(process.cwd(), 'posts');
@@ -64,12 +65,16 @@ export async function getPostData(slug: string): Promise<PostData | null> {
const fileContents = fs.readFileSync(fullPath, 'utf8');
const matterResult = matter(fileContents);
// Используем unified pipeline для более полной поддержки Markdown
// Используем unified pipeline с подсветкой синтаксиса
const processedContent = await unified()
.use(remarkParse) // парсим Markdown
.use(remarkGfm) // добавляем поддержку GFM (таблицы, задачи и т.д.)
.use(remarkRehype, { allowDangerousHtml: true }) // конвертируем в HTML
.use(rehypeRaw) // разрешаем raw HTML
.use(remarkGfm) // добавляем поддержку GFM (таблицы и т.д.)
.use(remarkRehype) // конвертируем в HTML AST
.use(rehypePrism, {
// Настройки подсветки
showLineNumbers: true, // показывать номера строк
ignoreMissing: true, // игнорировать неизвестные языки
})
.use(rehypeStringify) // сериализуем в строку
.process(matterResult.content || '');
@@ -87,4 +92,4 @@ export async function getPostData(slug: string): Promise<PostData | null> {
console.error(`Ошибка при загрузке поста ${slug}:`, error);
return null;
}
}
}