Files
jiamu 5579c7e70a 🎉 gzh-design-skill · 甲木 × 摸鱼小李 联名首发
微信公众号排版技能:把 Markdown 一键排成可直接粘进公众号编辑器的精致 HTML。
- 6 套精选厚主题(摸鱼绿/红白/石墨极简/留白禅意/摸鱼票据/橄榄手记)+ 主题生成器
- 文章类型→配方表装配、关键词下划线、全角标点、图片自适应
- 双关卡质量校验(component_lint + validate_gzh_html)
- 一键复制预览页,样式粘贴不掉
- AGPL-3.0 · 欢迎 AI Agent / 模型厂商共创

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-08 09:41:17 +08:00

45 lines
1.7 KiB
Python
Executable File
Raw Permalink 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
"""把已校验的公众号正文片段(纯 <section>)包成带「复制」按钮的浏览器预览页。
用户打开预览页 → 点右上角「复制到公众号」→ 按钮选中并复制里面渲染后的富文本
(等价手动 Ctrl+A/Ctrl+C,样式全保留)→ 到公众号编辑器 Ctrl+V 粘贴即可。
按钮和 JS 只存在于预览外壳里,**不在被复制的 section 内**,所以粘进公众号的
仍是干净合规的正文,不含 <script>/<button>。校验请对原始 section 文件跑
validate_gzh_html.py(本预览页含 script/style,不参与校验)。
用法:
wrap_preview.py <section.html> [output.html]
默认输出 <section去扩展名>_预览.html
"""
import os
import sys
def main():
if len(sys.argv) < 2:
print("用法: wrap_preview.py <section.html> [output.html]")
sys.exit(1)
src = sys.argv[1]
if not os.path.isfile(src):
print(f"✗ 找不到文件: {src}")
sys.exit(1)
content = open(src, encoding="utf-8").read().strip()
tpl_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"..", "assets", "preview-template.html")
tpl = open(tpl_path, encoding="utf-8").read()
title = os.path.splitext(os.path.basename(src))[0]
out_html = tpl.replace("{{TITLE}}", title).replace("<!--GZH_CONTENT-->", content)
out = sys.argv[2] if len(sys.argv) > 2 else os.path.splitext(src)[0] + "_预览.html"
open(out, "w", encoding="utf-8").write(out_html)
print(f"✓ 已生成带「复制」按钮的预览页: {out}")
print(" 用浏览器打开它,点右上角「复制到公众号」,再去公众号编辑器 Ctrl/⌘+V 粘贴。")
if __name__ == "__main__":
main()