import { file, write, Glob } from "bun"; import path from "node:path"; const rootDir = path.join(import.meta.dir, '..'); const targetFolders = [ "gaya-hidup", "jejak-sejarah", "lainnya", "olah-media", "opini-sosial", "sistem-terbuka", "warta-tekno" ]; // Signature — skip jika artikel sudah pernah diproses const MD_SIGNATURE = "markdown_oleh_Fakhrul_Rijal"; // Boundary karakter yang TIDAK perlu tambah spasi (sudah aman untuk markdown.js) // Kalau karakter sesudah marker bukan salah satu ini → tambah spasi const SAFE_AFTER = /[\s.,!?;:<)'"\/\]]/; // Kalau karakter sebelum marker bukan salah satu ini → tambah spasi const SAFE_BEFORE = /[\s(>'"\/\[]/; interface Stats { processed: number; changed: number; skipped: number; totalBefore: number; totalAfter: number; } let stats: Stats = { processed: 0, changed: 0, skipped: 0, totalBefore: 0, totalAfter: 0 }; /** * Konversi tag HTML ke markdown syntax. * Auto-tambah spasi sebelum/sesudah marker kalau tidak ada boundary. * Berlaku untuk: ** (bold), * (italic), ~~ (strikethrough), ` (inline code) */ function convertTag( tag: string, // regex match lengkap before: string, // karakter sebelum tag (dari capture group) inner: string, // isi tag after: string, // karakter sesudah tag (dari capture group) open: string, // marker pembuka mis: ** close: string // marker penutup mis: ** ): string { const needSpaceBefore = before && !SAFE_BEFORE.test(before); const needSpaceAfter = after && !SAFE_AFTER.test(after); const prefix = needSpaceBefore ? ' ' : ''; const suffix = needSpaceAfter ? ' ' : ''; return `${before}${prefix}${open}${inner}${close}${suffix}${after}`; } function cleanHTML(html: string): string { const vault: string[] = []; const protect = (s: string) => { const id = `__VAULT_${vault.length}__`; vault.push(s); return id; }; // PERBAIKAN 1: Gunakan arrow function () => v agar karakter $ di dalam