import re import json import uuid def make_span(text, marks=None): return { "_key": uuid.uuid4().hex[:8], "_type": "span", "marks": marks or [], "text": text } def make_block(text, style="normal", list_item=None, level=None): # Parse bold and italic marks if present spans = [] # simple span for now spans.append(make_span(text)) block = { "_key": uuid.uuid4().hex[:8], "_type": "block", "style": style, "markDefs": [], "children": spans } if list_item: block["listItem"] = list_item block["level"] = level or 1 return block def parse_markdown(md_path): with open(md_path, "r", encoding="utf-8") as f: content = f.read() lines = content.split("\n") blocks = [] in_schema = False in_table = False for line in lines: stripped = line.strip() # Skip empty lines if not stripped: continue # Skip metadata header if at top if stripped.startswith("Tiêu đề SEO:") or stripped.startswith("Mô tả meta:") or stripped.startswith("Từ khóa chính:"): continue # Detect schema blocks if "" in stripped: in_schema = False continue if in_schema: continue # Detect markdown images img_match = re.match(r'!\[(.*?)\]\((.*?)\)', stripped) if img_match: alt = img_match.group(1) src = img_match.group(2) blocks.append({ "_type": "image_placeholder", "alt": alt, "src": src }) continue # Skip comment metadata or caption lines right after image if stripped.startswith("