Files
romanov_btg_rag/andreev_manual/gen_sources.py
T
anorandClaude Opus 4.8 b35b73bd52 feat: локальный HTML-мануал «Генератор Андреева» (намотка/замеры/настройка)
- andreev_manual/ — самодостаточный офлайн-сайт (17 страниц, единый стиль, сайдбар):
  принцип, статус, сердечник, обмотки-намотка, конденсаторы, ОС/cosφ, сборка,
  замеры, настройка, безопасность, переделка SOLA, смежные, источники
- интерактивный калькулятор контура (порт andreev_calc.py на JS; на данных Андреева
  L=35.6мГн, V_C=313В, S=8.76кВА — совпадает с python)
- схемы перерисованы в SVG (контур, разрез намотки, метод ВАХ) — единый вид
- первоисточники Андреева и Осетрова приведены к единому HTML-виду (gen_sources.py)
- build_manual.py (генератор md→html) + check.py (валидатор: целостность ссылок,
  офлайн-самодостаточность — нет внешних css/js/img); рендер проверен в браузере

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-16 14:43:17 +10:00

84 lines
3.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""Конвертирует txt-первоисточники в content/*.html единого вида (для build_manual).
Эвристика: пустая строка — разделитель абзацев; короткая строка без концевой пунктуации —
подзаголовок (<h3>); строки с «•»/«-» в начале — пункты списка; остальное — абзацы.
HTML экранируется. Запуск: python3 gen_sources.py
"""
import html
import re
from pathlib import Path
ROOT = Path(__file__).resolve().parent
SRC = Path("/Users/alchemist/Python_projects/polyakov_ether_base/единая_теория_эфира")
JOBS = [
{
"txt": SRC / "источник_Андреев_сборка_настройка.txt",
"out": ROOT / "content" / "src_andreev.html",
"h1": "Первоисточник: Андреев — о работе схемы, сборке и настройке",
"note": "Прямые слова автора (его docx). Самый детальный источник по сборке. "
"Текст приведён к единому виду без изменения смысла.",
},
{
"txt": SRC / "источник_Осетров_трансформатор.txt",
"out": ROOT / "content" / "src_osetrov.html",
"h1": "Первоисточник: Осетров — «Трансформатор Андреева»",
"note": "Статья-стенограмма (sergey-osetrov.narod.ru). Расширенный разбор линии "
"Громов / Андреев / Степанов. Приведено к единому виду.",
},
]
def is_heading(line: str) -> bool:
s = line.strip()
if not s or len(s) > 64:
return False
if s[0] in "•-–*0123456789":
return False
return s[-1] not in ".,:;!?)»\""
def to_html(text: str) -> str:
out = []
in_ul = False
for raw in text.splitlines():
line = raw.rstrip()
s = line.strip()
if not s:
if in_ul:
out.append("</ul>"); in_ul = False
continue
if s[0] in "•–*" or (s[0] == "-" and len(s) > 1 and s[1] == " "):
if not in_ul:
out.append("<ul>"); in_ul = True
out.append(f"<li>{html.escape(s.lstrip('•–*- '))}</li>")
continue
if in_ul:
out.append("</ul>"); in_ul = False
if is_heading(s):
out.append(f"<h3>{html.escape(s)}</h3>")
else:
out.append(f"<p>{html.escape(s)}</p>")
if in_ul:
out.append("</ul>")
return "\n".join(out)
def main() -> int:
for j in JOBS:
text = j["txt"].read_text(encoding="utf-8")
body = (
f"<h1>{html.escape(j['h1'])}</h1>\n"
f'<div class="callout note">{html.escape(j["note"])} '
f'Назад к списку: <a href="sources.html">Источники</a>.</div>\n'
+ to_html(text)
)
j["out"].write_text(body, encoding="utf-8")
print(f"→ {j['out'].name} ({len(body)} симв.)")
return 0
if __name__ == "__main__":
raise SystemExit(main())