/
ArtKAtMan
/
arbat
Обзор
Документация
Войти
/
ArtKAtMan
/
arbat
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
scripts/fix-faq-inline.py
76 строк
2 KB
Mavis (M3)
fix: article markdown — bold/FAQ rendering, wider container, related grid 4-col
10 июл 2026, 18:41
10 июл 2026, 18:41
a416f50
Код
Авторство
О чём код?
"""Second pass: split a giant H2 that runs into **Q1?** A1. **Q2?** A2. ... content. Targets patterns like: ## FAQ**Вопрос 1?** Ответ 1.** Вопрос 2?** Ответ 2. And turns them into: ## FAQ ** Вопрос 1? ** Ответ 1. ** Вопрос 2? ** Ответ 2. """ import re from pathlib import Path CONTENT_DIR = Path('src/content/articles') # Match `## FAQ` followed immediately by `**...?**` # Then we split the rest by `**...?**` markers. # Be permissive: the H2 line can end with anything. # We assume the H2 occupies the first line that starts with `##` and contains FAQ. FAQ_INLINE = re.compile( r'^(##\s*FAQ[^\n]*?)\*\*([^*]+?\?)\*\*([\s\S]*?)(?=^##\s|\Z)', re.MULTILINE, ) def fix_inline_faq(body: str) -> str: def repl(m: re.Match) -> str: h2 = m.group(1).rstrip() # `## FAQ` (might have a trailing space) # normalize: drop everything after the heading keyword if not h2.rstrip().endswith('FAQ'): h2 = '## FAQ' first_q_inner = m.group(2).strip() rest = m.group(3) out = [h2, '', f'** {first_q_inner} **', ''] # rest is `A1.** Q2?** A2.** Q3?** A3....` # Split on the bold markers parts = re.split(r'\*\*([^*]+?)\*\*', rest) # parts: [a1, q2, a2, q3, a3, ...] i = 1 a = parts[0].strip() if a: out.append(a) out.append('') while i < len(parts) - 1: q = parts[i].strip() a_next = parts[i + 1].strip() if i + 1 < len(parts) else '' out.append(f'** {q} **') if a_next: out.append('') out.append(a_next) out.append('') i += 2 return '\n'.join(out).rstrip() + '\n\n' return FAQ_INLINE.sub(repl, body) def main(): for f in sorted(CONTENT_DIR.glob('*.md')): text = f.read_text(encoding='utf-8') if '## FAQ' not in text: continue new = fix_inline_faq(text) if new != text: f.write_text(new, encoding='utf-8') print(f'faq-split: {f.name}') else: print(f'no change: {f.name}') if __name__ == '__main__': main()