import re path = '/opt/ai-os/products/ceo/projects/blog/vwg-content/tai-sao-chon-viet-nam/draft_vi_v1.md' with open(path, 'r', encoding='utf-8') as f: text = f.read() base_url = "/files/opt/ai-os/products/ceo/projects/blog/vwg-content/tai-sao-chon-viet-nam/images" def replace_placeholder(match): content = match.group(1) # parse alt, caption, filename parts = [p.strip() for p in content.split('|')] info = {} for p in parts: if ':' in p: k, v = p.split(':', 1) info[k.strip()] = v.strip() alt = info.get('alt', 'Ảnh đám cưới Việt Nam') caption = info.get('caption', '') filename = info.get('tên file gợi ý', 'image.webp') img_url = f"{base_url}/{filename}" return f"![{alt}]({img_url})\n*{caption}*\n\n" new_text = re.sub(r'\[(ẢNH \d+ \| .*?)\]', replace_placeholder, text) with open(path, 'w', encoding='utf-8') as f: f.write(new_text) print("Images integrated successfully!")