Skip to content

ZJU-REAL/Easel / skills/builtin/gzh-design

gzh-design

Verified

微信公众号文章排版引擎:把 Markdown / Word(.docx) / PDF / 纯文本转成可直接粘贴进公众号编辑器的 HTML,自动章节编号、关键词标记、引言卡、目录、代码块、图片/GIF、作者签名;主题从 references/theme-index.md 组件库按题材推荐,支持"一键自动排版"与按描述/参考图生成自定义主题。触发:用户提到"公众号排版/微信排版/gzh"、想把文章(md/docx/pdf/纯文本)转成公众号 HTML、说"自动排版/一键排版"公众号内容。不用于普通网页/落地页/PPT。

FileKindSize
CONTRIBUTING.mdmarkdown2.0 KB
EASEL-META.mdmarkdown1.1 KB
LICENSEother34.2 KB
README.en.mdmarkdown15.6 KB
README.mdmarkdown19.8 KB
SKILL.mdskill md17.8 KB
archive/gallery-v1/cardnote.htmlother18.7 KB
archive/gallery-v1/cream.htmlother18.2 KB
archive/gallery-v1/datainfo.htmlother29.8 KB
archive/gallery-v1/dianlan.htmlother17.7 KB
archive/gallery-v1/graphite.htmlother19.7 KB
archive/gallery-v1/heibaihui.htmlother17.6 KB
archive/gallery-v1/heikeji.htmlother23.0 KB
archive/gallery-v1/hongbai.htmlother17.2 KB
archive/gallery-v1/hupo.htmlother17.1 KB
archive/gallery-v1/jiaotang.htmlother17.6 KB
archive/gallery-v1/lvkeji.htmlother21.0 KB
archive/gallery-v1/magfeature.htmlother22.5 KB
archive/gallery-v1/meigui.htmlother17.2 KB
archive/gallery-v1/mistblue.htmlother20.4 KB
archive/gallery-v1/qingshiban.htmlother17.0 KB
archive/gallery-v1/rich_hongbai.htmlother14.5 KB
archive/gallery-v1/rich_morandi.htmlother15.2 KB
archive/gallery-v1/rich_terminal.htmlother17.5 KB
archive/gallery-v1/rich_zen.htmlother13.3 KB
archive/gallery-v1/tianlan.htmlother16.3 KB
archive/gallery-v1/zise.htmlother17.7 KB
archive/themes-v1/theme-amber-orange.mdmarkdown22.0 KB
archive/themes-v1/theme-caramel-brown.mdmarkdown23.1 KB
archive/themes-v1/theme-card-notes.mdmarkdown33.9 KB
archive/themes-v1/theme-cream-warmth.mdmarkdown22.1 KB
archive/themes-v1/theme-data-infographic.mdmarkdown34.9 KB
archive/themes-v1/theme-editorial-feature.mdmarkdown25.7 KB
archive/themes-v1/theme-elegant-purple.mdmarkdown20.9 KB
archive/themes-v1/theme-emerald-tech.mdmarkdown23.7 KB
archive/themes-v1/theme-indigo-business.mdmarkdown20.9 KB
archive/themes-v1/theme-mist-blue.mdmarkdown25.5 KB
archive/themes-v1/theme-mono-black.mdmarkdown19.7 KB
archive/themes-v1/theme-morandi.mdmarkdown25.0 KB
archive/themes-v1/theme-rose-pink.mdmarkdown23.4 KB
archive/themes-v1/theme-sky-blue.mdmarkdown14.0 KB
archive/themes-v1/theme-slate-minimal.mdmarkdown22.2 KB
archive/themes-v1/theme-terminal.mdmarkdown27.6 KB
archive/themes-v1/theme-terracotta-tech.mdmarkdown21.2 KB
assets/preview-template.htmlother4.0 KB
assets/sample-article.mdmarkdown2.7 KB
assets/theme-previews/theme-mono-blue-editorial.htmlother45.0 KB
docs/all-themes.mdmarkdown1.9 KB
docs/gallery/graphite-minimal.htmlother18.4 KB
docs/gallery/index.htmlother2.9 KB
docs/gallery/moyu-green.htmlother24.8 KB
docs/gallery/moyu-ticket.htmlother22.4 KB
docs/gallery/olive-journal.htmlother26.3 KB
docs/gallery/red-white.htmlother18.7 KB
docs/gallery/sample-article.mdmarkdown2.7 KB
docs/gallery/zen-whitespace.htmlother16.9 KB
references/common-components.mdmarkdown11.3 KB
references/eval-cases.mdmarkdown5.6 KB
references/format-normalize.mdmarkdown4.4 KB
references/theme-generator.mdmarkdown25.3 KB
references/theme-graphite-minimal.mdmarkdown32.7 KB
references/theme-index.mdmarkdown3.1 KB
references/theme-moyu-green.mdmarkdown43.1 KB
references/theme-moyu-ticket.mdmarkdown23.5 KB
references/theme-olive-journal.mdmarkdown55.4 KB
references/theme-red-white.mdmarkdown28.4 KB
references/theme-zen-whitespace.mdmarkdown23.3 KB
scripts/component_lint.pyexecutablescript3.8 KB
scripts/extract_docx.pyscript6.2 KB
scripts/validate_gzh_html.pyexecutablescript7.0 KB
scripts/wrap_preview.pyexecutablescript3.4 KB

scripts/extract_docx.py

View on GitHub
#!/usr/bin/env python3
"""Word .docx → Markdown 提取器(零外部依赖)。

格式归一化层的确定性组件:把 docx 的标题层级 / 粗体 / 列表 / 图片
转成本 skill 排版流程认识的 Markdown。

用法:
    extract_docx.py 文章.docx [-o 输出.md]
    # 内嵌图片解包到 输出.md 同目录的 images/ 下,md 里用相对路径引用

退出码:0 成功;1 失败(文件不存在 / 不是合法 docx)。
提取不了的复杂结构(表格、文本框)会以「[表格:…]」占位并在 stderr 提示。
"""

import argparse
import os
import re
import sys
import zipfile
import xml.etree.ElementTree as ET

W = "{http://schemas.openxmlformats.org/wordprocessingml/2006/main}"
R = "{http://schemas.openxmlformats.org/officeDocument/2006/relationships}"
A = "{http://schemas.openxmlformats.org/drawingml/2006/main}"


def load_styles(z):
    """styleId → 标题级别(1/2/3…);非标题样式不入表。"""
    levels = {}
    try:
        root = ET.fromstring(z.read("word/styles.xml"))
    except KeyError:
        return levels
    for st in root.iter(f"{W}style"):
        sid = st.get(f"{W}styleId") or ""
        name_el = st.find(f"{W}name")
        name = (name_el.get(f"{W}val") if name_el is not None else "") or ""
        m = re.search(r"(?:heading|标题)\s*([1-6])", name, re.I) \
            or re.fullmatch(r"([1-6])", sid)
        if m:
            levels[sid] = int(m.group(1))
    return levels


def load_rels(z):
    """rId → 媒体文件路径(word/media/...)。"""
    rels = {}
    try:
        root = ET.fromstring(z.read("word/_rels/document.xml.rels"))
    except KeyError:
        return rels
    for rel in root:
        target = rel.get("Target") or ""
        if "media/" in target:
            rels[rel.get("Id")] = "word/" + target.lstrip("/").replace("../", "")
    return rels


def para_text(p):
    """段内 run → 行内 Markdown(粗体→**、下划线→<u>)。"""
    out = []
    for r_el in p.iter(f"{W}r"):
        rpr = r_el.find(f"{W}rPr")
        bold = rpr is not None and rpr.find(f"{W}b") is not None \
            and (rpr.find(f"{W}b").get(f"{W}val") or "1") not in ("0", "false")
        ul = rpr is not None and rpr.find(f"{W}u") is not None
        text = "".join(t.text or "" for t in r_el.iter(f"{W}t"))
        if not text:
            continue
        if bold:
            text = f"**{text}**"
        if ul:
            text = f"<u>{text}</u>"
        out.append(text)
    s = "".join(out)
    return re.sub(r"\*\*\*\*", "", s)  # 相邻粗体 run 合并的空标记


def extract(docx_path, out_md):
    try:
        z = zipfile.ZipFile(docx_path)
        doc = ET.fromstring(z.read("word/document.xml"))
    except (zipfile.BadZipFile, KeyError) as e:
        print(f"✗ 不是合法 docx:{e}", file=sys.stderr)
        return 1

    heading_of = load_styles(z)
    media_of = load_rels(z)
    out_dir = os.path.dirname(os.path.abspath(out_md)) or "."
    img_dir = os.path.join(out_dir, "images")
    lines, img_n, skipped = [], 0, 0

    body = doc.find(f"{W}body")
    for el in body:
        tag = el.tag
        if tag == f"{W}tbl":
            # 表格 → Markdown 表格,保住行列结构(合并单元格按普通格处理)
            rows = []
            for tr in el.findall(f"{W}tr"):
                cells = ["".join(t.text or "" for t in tc.iter(f"{W}t"))
                         .strip().replace("|", "\\|") or " "
                         for tc in tr.findall(f"{W}tc")]
                rows.append("| " + " | ".join(cells) + " |")
            if rows:
                lines.append(rows[0])
                ncols = rows[0].count("|") - 1
                lines.append("|" + "---|" * ncols)
                lines.extend(rows[1:])
                lines.append("")
                skipped += 1  # 计数改为"转换的表格数"
            continue
        if tag != f"{W}p":
            continue
        p = el
        # 图片
        for blip in p.iter(f"{A}blip"):
            rid = blip.get(f"{R}embed")
            src = media_of.get(rid)
            if not src:
                continue
            os.makedirs(img_dir, exist_ok=True)
            img_n += 1
            fname = f"{img_n:02d}-" + os.path.basename(src)
            with open(os.path.join(img_dir, fname), "wb") as f:
                f.write(z.read(src))
            lines.append(f"![](images/{fname})")
            lines.append("")
        text = para_text(p).strip()
        if not text:
            continue
        ppr = p.find(f"{W}pPr")
        style_el = ppr.find(f"{W}pStyle") if ppr is not None else None
        sid = style_el.get(f"{W}val") if style_el is not None else ""
        lvl = heading_of.get(sid)
        # 列表识别:直接编号(numPr) 或 列表类段落样式(List Bullet/Number/Paragraph/中文"列表")
        is_list = (ppr is not None and ppr.find(f"{W}numPr") is not None) \
            or bool(re.search(r"list|列表", sid or "", re.I))
        if lvl:
            text_clean = re.sub(r"^\*\*(.*)\*\*$", r"\1", text)  # 标题不需要再加粗
            lines.append("#" * min(lvl + 0, 6) + " " + text_clean)
        elif is_list:
            lines.append("- " + text)
        else:
            lines.append(text)
        lines.append("")

    md = "\n".join(lines).rstrip() + "\n"
    with open(out_md, "w", encoding="utf-8") as f:
        f.write(md)
    print(f"✓ {os.path.basename(docx_path)} → {out_md}")
    print(f"  段落 {sum(1 for l in lines if l and not l.startswith(('#','-','![')))} · "
          f"标题 {sum(1 for l in lines if l.startswith('#'))} · "
          f"列表 {sum(1 for l in lines if l.startswith('- '))} · 图片 {img_n}"
          + (f" · 表格 {skipped}(已转 Markdown 表格)" if skipped else ""))
    return 0


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("docx")
    ap.add_argument("-o", "--out", help="输出 md 路径(默认同名 .md)")
    args = ap.parse_args()
    if not os.path.isfile(args.docx):
        print(f"✗ 文件不存在: {args.docx}", file=sys.stderr)
        sys.exit(1)
    out = args.out or re.sub(r"\.docx$", "", args.docx, flags=re.I) + ".md"
    sys.exit(extract(args.docx, out))


if __name__ == "__main__":
    main()
canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill.Stars: 198kUpdated Claude CodeCodexVerifiedInstall