_render_readme.py 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. """Render README.md as a standalone HTML preview (GitHub-ish style)."""
  2. import markdown
  3. from pathlib import Path
  4. root = Path(r"D:\workspace\Agi\zrd-nb666")
  5. md_text = (root / "README.md").read_text(encoding="utf-8")
  6. body = markdown.markdown(md_text, extensions=["fenced_code", "tables", "toc"])
  7. html = f"""<!doctype html>
  8. <html><head><meta charset="utf-8">
  9. <title>zrd-nb666 README preview</title>
  10. <style>
  11. body {{ font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  12. max-width: 900px; margin: 40px auto; padding: 0 24px;
  13. color: #1f2328; line-height: 1.6; }}
  14. h1 {{ border-bottom: 1px solid #d1d9e0; padding-bottom: .3em; }}
  15. h2 {{ border-bottom: 1px solid #d1d9e0; padding-bottom: .3em; margin-top: 2em; }}
  16. code {{ background: #f6f8fa; padding: .2em .4em; border-radius: 6px; font-size: 90%; }}
  17. pre {{ background: #f6f8fa; padding: 16px; border-radius: 6px; overflow: auto; }}
  18. pre code {{ background: transparent; padding: 0; }}
  19. table {{ border-collapse: collapse; width: 100%; margin: 1em 0; }}
  20. th, td {{ border: 1px solid #d1d9e0; padding: 6px 13px; }}
  21. th {{ background: #f6f8fa; }}
  22. blockquote {{ color: #59636e; border-left: 4px solid #d1d9e0; margin: 0; padding: 0 1em; }}
  23. img {{ max-width: 100%; }}
  24. </style></head>
  25. <body>{body}</body></html>"""
  26. out = root / "_readme_preview.html"
  27. out.write_text(html, encoding="utf-8")
  28. print(out)