mr-li-writer
Verified面向中文内容创作的编辑判断、研究、策划、写作与平台原生交付工作流。根据标题、素材、参考资料、核心想法或模糊灵感,先识别读者任务、材料条件和创新必要性,再按需完成语境扫描、可写性判断与方向校准,并区分发布平台与内容目标,进行事实检索、观点设计、平台原生正文写作、标题策划和对应交付。适用于公众号文章、知乎回答、小红书原生笔记、官网/网页、个人博客、行业解读、实用指南和基于素材的扩展研究写作。
scripts/component_lint.py
View on GitHub#!/usr/bin/env python3
"""组件库源头检查器 —— 可验证循环的第一道关。
扫描 references/ 下所有组件库 .md 里的 ```html 代码块,检测会导致
排版问题的反模式。只看真实组件 HTML,不被说明文字干扰(grep 做不到)。
与 validate_gzh_html.py 配合构成闭环:
改组件库 → component_lint.py 扫源头 → 生成产物 → validate_gzh_html.py 扫产物 → 修 → 重复
用法:
component_lint.py [skill-dir] # 默认当前目录
退出码:1 = 有 ERROR,0 = 通过。
"""
import glob
import os
import re
import sys
CJK = re.compile(r"[一-鿿㐀-䶿]")
# (正则, 级别, 说明) —— 在每个 ```html 组件块内检查
CHECKS = [
(re.compile(r"white-space\s*:\s*pre", re.I), "ERROR",
"用了 white-space:pre —— 会把 HTML 源码缩进/换行渲染成大左缩进+空行;"
"代码块改成每行一个不换行 <p style=\"margin:0\">,空格编码为 "),
(re.compile(r"</?div[\s>]", re.I), "ERROR", "出现 <div>,应用 <section>"),
(re.compile(r"\sclass\s*=", re.I), "ERROR", "出现 class 属性(会被公众号剥离)"),
(re.compile(r"\sid\s*=", re.I), "ERROR", "出现 id 属性"),
(re.compile(r"<style[\s>]", re.I), "ERROR", "出现 <style> 标签"),
(re.compile(r"position\s*:\s*(fixed|absolute|sticky)", re.I), "ERROR",
"position fixed/absolute/sticky 不被支持"),
(re.compile(r"display\s*:\s*grid", re.I), "ERROR", "display:grid 不被支持"),
(re.compile(r"var\s*\(\s*--", re.I), "ERROR", "用了 CSS 变量 var(--x)"),
(re.compile(r"@(media|keyframes|import)", re.I), "ERROR", "@media/@keyframes/@import 不被支持"),
(re.compile(r"(?:width|min-width|max-width)\s*:\s*\d+(?:\.\d+)?vw", re.I), "ERROR",
"用了 vw 卡片宽度 —— 公众号发布容器与浏览器视口不同,应使用百分比或 flex 自适应"),
]
# 四周虚线框:border: ... dashed(不含方向,如 border-left dashed 不算)
FOURSIDE_DASHED = re.compile(r"border\s*:\s*[^;{}]*dashed", re.I)
CENTERED = re.compile(r"text-align\s*:\s*center", re.I)
COMPONENT_BLOCK = re.compile(
r"^##\s+组件\s+\d+\s+(.+?)\n(.*?)(?=^##\s+组件\s+\d+\s+|^##\s+完整文章模板骨架|\Z)",
re.M | re.S,
)
PUBLIC_PROCESS_LABEL = re.compile(r"公众号排版|深度文章|中文内容创作\s*Skill|信息祛魅|信息去魅", re.I)
NARROW_FIXED_CARD = re.compile(r"width\s*:\s*(?:[6-9]\d|1[01]\d|120)px", re.I)
ADAPTIVE_CARD_COMPONENT = re.compile(
r"数据|要点卡|对比|布局组件|flow-cards|three-col|ticket-cover|票据封面",
re.I,
)
def lint_file(path):
with open(path, encoding="utf-8", errors="replace") as source:
text = source.read()
name = os.path.basename(path).replace("公众号排版组件库 —— ", "").replace(".md", "")
found = [] # (level, msg)
seen = set()
def add(level, msg):
if msg not in seen:
seen.add(msg)
found.append((level, msg))
for m in re.finditer(r"```html\s*\n(.*?)```", text, re.S):
html = m.group(1)
for rx, level, msg in CHECKS:
if rx.search(html):
add(level, msg)
if re.search(r"overflow-x\s*:\s*auto", html, re.I):
table_style = re.search(r"<table\b[^>]*style=\"([^\"]*)\"", html, re.I)
style = table_style.group(1) if table_style else ""
min_match = re.search(r"min-width\s*:\s*(\d+)px", style, re.I)
max_match = re.search(r"max-width\s*:\s*(\d+)px", style, re.I)
min_width = int(min_match.group(1)) if min_match else 0
max_width = int(max_match.group(1)) if max_match else 0
bounded = 320 <= min_width <= 680 and min_width <= max_width <= 680
valid_table = bool(
table_style
and bounded
and re.search(r"table-layout\s*:\s*fixed", style, re.I)
)
scroll_section = re.search(
r"<section\b[^>]*style=\"([^\"]*overflow-x\s*:\s*auto[^\"]*)\"",
html,
re.I,
)
code_line = re.search(
r"<p\b[^>]*style=\"[^\"]*(?:monospace|consolas|sf mono)[^\"]*"
r"white-space\s*:\s*nowrap[^\"]*word-break\s*:\s*normal[^\"]*"
r"overflow-wrap\s*:\s*normal[^\"]*\"",
html,
re.I,
)
valid_code = bool(
scroll_section
and re.search(r"max-width\s*:\s*100%", scroll_section.group(1), re.I)
and code_line
)
if not valid_table and not valid_code:
add("ERROR", "横向滚动仅允许用于有宽度上限的语义化表格或不换行代码容器")
if re.search(r"<table[\s>]", html, re.I):
if not re.search(r"table-layout\s*:\s*fixed", html, re.I):
add("ERROR", "语义化表格缺少 table-layout:fixed,窄屏可能被内容撑宽")
if "overflow-wrap:anywhere" not in html or not re.search(r"white-space\s*:\s*normal", html, re.I):
add("ERROR", "语义化表格缺少单元格长文本换行兜底")
if re.search(r"<table\b.*?word-break\s*:\s*keep-all.*?</table>", html, re.I | re.S):
add("ERROR", "语义化表格使用 word-break:keep-all,会阻止手机端单元格自然换行")
# 原 gzh-design 主题中部分引用框、亮点卡和素材占位会刻意使用
# 四周虚线作为设计语言;这里不把 dashed 本身视为源头问题。
for match in COMPONENT_BLOCK.finditer(text):
title, body = match.group(1), match.group(2)
snippets = re.findall(r"```html\s*\n(.*?)```", body, re.S)
html = "\n".join(snippets)
if re.search(r"章节标题|section-title|chapter-title", title, re.I):
if "{{编号}}" not in html:
add("ERROR", "章节标题组件未使用 {{编号}} 动态占位,容易让所有章节都保留 01")
if re.search(r"目录|导读|toc", title, re.I):
if NARROW_FIXED_CARD.search(html) and "overflow-wrap:anywhere" not in html:
add("ERROR", "目录/导读含窄固定宽度卡片但没有长文本换行兜底")
if ADAPTIVE_CARD_COMPONENT.search(title) and "flex:1" in html:
if "min-width:0" not in html or "overflow-wrap:anywhere" not in html:
add("ERROR", "多列卡片缺少 min-width:0 或 overflow-wrap:anywhere,长文本可能溢出")
if PUBLIC_PROCESS_LABEL.search(html):
add("ERROR", "组件可见文本含公众号排版/深度文章/内容创作 Skill/信息祛魅等生产标签")
return name, found
def main():
root = sys.argv[1] if len(sys.argv) > 1 else "."
candidate_dirs = [
os.path.join(root, "assets", "gzh-design", "references"),
os.path.join(root, "references"),
]
ref_dir = next((d for d in candidate_dirs if os.path.isdir(d)), candidate_dirs[0])
refs = sorted(
p for p in glob.glob(os.path.join(ref_dir, "*.md"))
if (
os.path.basename(p) == "common-components.md"
or (
os.path.basename(p).startswith("theme-")
and os.path.basename(p) not in {"theme-index.md", "theme-generator.md"}
)
)
)
if not refs:
print(f"未找到公众号主题组件库: {ref_dir}/*.md")
sys.exit(1)
total_err = total_warn = clean = 0
print(f"📐 组件库源头检查:{len(refs)} 个库\n")
for path in refs:
name, found = lint_file(path)
if not found:
clean += 1
continue
errs = [m for lv, m in found if lv == "ERROR"]
warns = [m for lv, m in found if lv == "WARN"]
total_err += len(errs)
total_warn += len(warns)
print(f"── {name} ──")
for m in errs:
print(f" ❌ {m}")
for m in warns:
print(f" ⚠️ {m}")
print(f"\n汇总:{clean}/{len(refs)} 个库干净,ERROR×{total_err},WARN×{total_warn}")
if total_err == 0 and total_warn == 0:
print("✅ 全部组件库源头无反模式")
sys.exit(1 if total_err else 0)
if __name__ == "__main__":
main()
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |