Skip to content

ZJU-REAL/Easel / skills/builtin/skill-wechat-publisher

skill-wechat-publisher

Verified

微信公众号文章自动创作与发布工具。给定参考文章、文字或文档,自动搜索整理全网相关信息、生成图文并茂的公众号文章,并发布到微信公众号草稿箱。特别强调反 AI 检测写作。 触发场景(沾边就用):用户提到"公众号 / 微信文章 / 推文 / 公号 / 发文 / mp / 草稿箱 / 群发",或要求把话题/文档/笔记写成公众号文章并发布到微信。

FileKindSize
EASEL-META.mdmarkdown2.6 KB
SKILL.mdskill md11.4 KB
assets/image-styles/README.mdmarkdown29.5 KB
assets/image-styles/blue.jsonconfig3.0 KB
assets/image-styles/data-chart.jsonconfig2.4 KB
assets/image-styles/flat-editorial.jsonconfig4.9 KB
assets/image-styles/hand-drawn-blue.jsonconfig2.3 KB
assets/image-styles/illustrated-warm.jsonconfig3.3 KB
assets/image-styles/infographic-blue.jsonconfig5.2 KB
assets/image-styles/infographic-dark.jsonconfig5.4 KB
assets/image-styles/infographic-mint.jsonconfig5.2 KB
assets/image-styles/infographic-warm.jsonconfig5.4 KB
assets/image-styles/knowledge-card.jsonconfig2.3 KB
assets/image-styles/magazine-editorial.jsonconfig2.3 KB
assets/image-styles/marker-coral.jsonconfig6.4 KB
assets/image-styles/marker-lime.jsonconfig6.6 KB
assets/image-styles/marker-pink.jsonconfig6.4 KB
assets/image-styles/marker-sky.jsonconfig6.4 KB
assets/image-styles/marker-violet.jsonconfig6.4 KB
assets/image-styles/meme-illustration.jsonconfig2.3 KB
assets/image-styles/mint.jsonconfig3.1 KB
assets/image-styles/morandi.jsonconfig3.4 KB
assets/image-styles/previews/blue.webpbinary104.0 KB
assets/image-styles/previews/data-chart.webpbinary16.4 KB
assets/image-styles/previews/flat-editorial.webpbinary109.7 KB
assets/image-styles/previews/hand-drawn-blue.webpbinary17.9 KB
assets/image-styles/previews/illustrated-warm.webpbinary31.2 KB
assets/image-styles/previews/infographic-blue.webpbinary160.4 KB
assets/image-styles/previews/infographic-dark.webpbinary142.1 KB
assets/image-styles/previews/infographic-mint.webpbinary150.2 KB
assets/image-styles/previews/infographic-warm.webpbinary162.5 KB
assets/image-styles/previews/knowledge-card.webpbinary22.4 KB
assets/image-styles/previews/magazine-editorial.webpbinary14.0 KB
assets/image-styles/previews/marker-coral.webpbinary41.2 KB
assets/image-styles/previews/marker-lime-template.webpbinary34.3 KB
assets/image-styles/previews/marker-lime.webpbinary39.3 KB
assets/image-styles/previews/marker-pink.webpbinary37.5 KB
assets/image-styles/previews/marker-sky.webpbinary47.9 KB
assets/image-styles/previews/marker-violet.webpbinary42.8 KB
assets/image-styles/previews/meme-illustration.webpbinary35.5 KB
assets/image-styles/previews/mint.webpbinary95.7 KB
assets/image-styles/previews/morandi.webpbinary82.0 KB
assets/image-styles/previews/slice-of-life.webpbinary46.3 KB
assets/image-styles/previews/warm-handdrawn.webpbinary79.0 KB
assets/image-styles/previews/xiaohongshu-colorful.webpbinary24.3 KB
assets/image-styles/slice-of-life.jsonconfig4.9 KB
assets/image-styles/warm-handdrawn.jsonconfig4.4 KB
assets/image-styles/xiaohongshu-colorful.jsonconfig2.3 KB
assets/theme-previews/README.mdmarkdown1.7 KB
assets/theme-previews/academic-paper.htmlother13.5 KB
assets/theme-previews/business-navy.htmlother13.6 KB
assets/theme-previews/elegant-ink.htmlother13.0 KB
assets/theme-previews/girly-pink.htmlother13.2 KB
assets/theme-previews/index.htmlother26.6 KB
assets/theme-previews/ink-wash.htmlother13.5 KB
assets/theme-previews/magazine-grid.htmlother13.0 KB
assets/theme-previews/minimal-bw.htmlother13.6 KB
assets/theme-previews/minimal-mono.htmlother12.7 KB
assets/theme-previews/mint-fresh.htmlother14.0 KB
assets/theme-previews/news-bold.htmlother13.3 KB
assets/theme-previews/refined-blue.htmlother15.1 KB
assets/theme-previews/sage-premium.htmlother13.6 KB
assets/theme-previews/sample.mdmarkdown2.6 KB
assets/theme-previews/screenshots/ink-wash.webpbinary27.8 KB
assets/theme-previews/screenshots/minimal-mono.webpbinary34.8 KB
assets/theme-previews/screenshots/news-bold.webpbinary32.5 KB
assets/theme-previews/screenshots/refined-blue.webpbinary34.3 KB
assets/theme-previews/screenshots/theme-overview.webpbinary229.8 KB
assets/theme-previews/sunset-coral.htmlother14.8 KB
assets/theme-previews/warm-editorial.htmlother12.8 KB
assets/theme-previews/warm-orange.htmlother12.3 KB
assets/themes/academic-paper.jsonconfig5.2 KB
assets/themes/business-navy.jsonconfig5.2 KB
assets/themes/elegant-ink.jsonconfig5.1 KB
assets/themes/girly-pink.jsonconfig5.3 KB
assets/themes/ink-wash.jsonconfig5.1 KB
assets/themes/magazine-grid.jsonconfig5.1 KB
assets/themes/minimal-bw.jsonconfig5.2 KB
assets/themes/minimal-mono.jsonconfig5.0 KB
assets/themes/mint-fresh.jsonconfig5.3 KB
assets/themes/news-bold.jsonconfig5.1 KB
assets/themes/refined-blue.jsonconfig5.6 KB
assets/themes/sage-premium.jsonconfig5.3 KB
assets/themes/sunset-coral.jsonconfig5.5 KB
assets/themes/warm-editorial.jsonconfig4.9 KB
assets/themes/warm-orange.jsonconfig5.0 KB
assets/typeset-card/template.htmlother3.5 KB
brief.md.exampleother2.3 KB
references/anti-ai-checklist.mdmarkdown3.4 KB
references/api_reference.mdmarkdown3.2 KB
references/article-structures.mdmarkdown3.2 KB
references/errors.mdmarkdown1.1 KB
references/image-styles-guide.mdmarkdown3.5 KB
references/inline-markup.mdmarkdown1.7 KB
references/multi-platform-sync.mdmarkdown2.6 KB
references/newspic-mode.mdmarkdown5.7 KB
references/themes.mdmarkdown1.8 KB
references/typeset-card.mdmarkdown4.3 KB
scripts/ai_score.pyexecutablescript15.2 KB
scripts/api.pyexecutablescript13.3 KB
scripts/baoyu_image_gen.tsexecutablescript5.5 KB
scripts/baoyu_image_gen_core.tsscript11.5 KB
scripts/config.pyexecutablescript11.7 KB
scripts/generate_image.pyexecutablescript4.3 KB
scripts/html_converter.pyexecutablescript23.3 KB
scripts/image_handler.pyexecutablescript17.5 KB
scripts/multi_publish.pyexecutablescript14.2 KB
scripts/newspic_build.pyexecutablescript14.0 KB
scripts/publish.pyexecutablescript35.7 KB
scripts/sync_pages.shexecutablescript994 B
scripts/wechat_api.pyexecutablescript6.0 KB
scripts/wechat_token.pyexecutablescript5.1 KB
tests/__init__.pyscript0 B
tests/conftest.pyscript4.1 KB
tests/test_ai_score.pyscript8.1 KB
tests/test_config.pyscript7.4 KB
tests/test_config_integration.pyscript9.7 KB
tests/test_draft_submission.pyscript3.1 KB
tests/test_html_converter.pyscript10.2 KB
wechat-publisher.yaml.exampleother1.8 KB

tests/test_html_converter.py

View on GitHub
"""
Tests for scripts/html_converter.py.

Focus:
- Plain markdown → HTML roundtrip sanity
- #5 fix: HTML-escaping of raw <script>/<style> and sanitization of javascript: URLs
- #23 fix: unclosed code blocks don't silently drop content
- Inline highlight markers (**, ==, ++) each produce styled output
"""

from __future__ import annotations

import pytest

from html_converter import convert_markdown_to_wechat_html, load_theme


# Shared theme fixture — every test needs the four tuples from load_theme.
@pytest.fixture(scope="module")
def theme():
    styles, highlights, divider, list_style = load_theme(theme_name="refined-blue")
    return styles, highlights, divider, list_style


def _convert(md: str, theme_tuple) -> str:
    styles, highlights, divider, list_style = theme_tuple
    return convert_markdown_to_wechat_html(md, styles, highlights, divider, list_style)


# ---------------------------------------------------------------------------
# Basic roundtrip
# ---------------------------------------------------------------------------

def test_plain_paragraph(theme):
    """A plain markdown paragraph should produce a <p ...>content</p> tag."""
    html = _convert("这是一段普通的段落文字。", theme)

    # Output is wrapped in <section>, so just look for the <p>.
    assert "<section" in html
    assert "<p" in html
    assert "这是一段普通的段落文字。" in html


def test_headings_rendered(theme):
    """h2 and h3 markdown should become <h2> and <h3>."""
    md = "## 二级标题\n\n正文\n\n### 三级标题\n\n更多正文"
    html = _convert(md, theme)

    assert "<h2" in html and "二级标题" in html
    assert "<h3" in html and "三级标题" in html


# ---------------------------------------------------------------------------
# Security — #5 fix
# ---------------------------------------------------------------------------

def test_script_tag_is_escaped(theme):
    """
    #5 fix: literal <script>alert(1)</script> in markdown must NOT produce
    a working <script> tag in the output. Content should be HTML-escaped.
    """
    md = "正文开始\n\n```html\n<script>alert(1)</script>\n```\n\n正文结束"
    html = _convert(md, theme)

    # A raw, executable <script> tag with a literal `>` would be dangerous.
    # After escaping, we expect `&lt;script&gt;` instead.
    assert "<script>alert(1)</script>" not in html, (
        "Raw <script> tag leaked through conversion — XSS risk"
    )
    # The escaped form should be present (content preserved, just neutralized).
    assert "&lt;script&gt;" in html or "&lt;script" in html


def test_inline_script_tag_in_code_is_escaped(theme):
    """Inline `<script>` in `\\`code\\`` must also be escaped."""
    md = "看这行内代码:`<script>`"
    html = _convert(md, theme)

    assert "<script>" not in html.replace("&lt;script&gt;", "")


def test_javascript_url_rejected(theme):
    """
    #5 fix: `[click](javascript:alert(1))` should NOT render as a
    working `href="javascript:alert(1)"` link.
    """
    md = "危险链接 [click me](javascript:alert(1))"
    html = _convert(md, theme)

    # The rendered anchor must not contain a javascript: href.
    # Accept either: href removed, or link rewritten, or the literal text
    # stays but no javascript: scheme in href attribute.
    assert 'href="javascript:' not in html.lower(), (
        "javascript: URL leaked into href — XSS risk"
    )


# ---------------------------------------------------------------------------
# Edge cases — #23 fix
# ---------------------------------------------------------------------------

def test_unclosed_code_block_preserved(theme):
    """
    #23 fix: if markdown ends with an unclosed ``` block, the content
    inside the block should not be silently dropped — it should end up
    in the output one way or another (either rendered as a <pre>
    auto-closed, or as plain text).
    """
    md = "## 开头\n\n```python\nprint('hello')\nimportant = 42\n"
    html = _convert(md, theme)

    # The body of the unclosed code block must not vanish completely.
    # We accept either the <pre> wrapper being present OR the raw content
    # making it through — what we DON'T accept is both being missing.
    has_pre = "<pre" in html
    has_content = "important = 42" in html or "print(&#x27;hello&#x27;)" in html or "print('hello')" in html
    assert has_pre or has_content, (
        "Unclosed code block silently dropped its content"
    )


def test_empty_input(theme):
    """Empty markdown should still produce a valid (if empty) <section>."""
    html = _convert("", theme)
    assert "<section" in html
    # The section should close properly.
    assert "</section>" in html


# ---------------------------------------------------------------------------
# Highlight markers
# ---------------------------------------------------------------------------

def test_bold_marker_renders_strong(theme):
    """**bold** should produce a <strong> tag with an inline style."""
    html = _convert("一个 **加粗** 的词", theme)
    assert "<strong" in html and "加粗" in html
    # Inline style must be present (WeChat requires inline styles only).
    assert "style=" in html


def test_highlight_markers_work(theme):
    """
    Each of ==yellow==, ++blue++, %%pink%%, &&green&&, !!red!!, @@blue-em@@,
    ^^orange^^ should produce a styled <span> (or equivalent tag) in output.
    """
    md = (
        "== 黄色高亮 ==\n\n"
        "++ 蓝色高亮 ++\n\n"
        "%% 粉色高亮 %%\n\n"
        "&& 绿色高亮 &&\n\n"
        "!! 红色强调 !!\n\n"
        "@@ 蓝色强调 @@\n\n"
        "^^ 橙色强调 ^^\n"
    )
    # These markers require no whitespace around them to match — rewrite tight.
    md_tight = (
        "==黄色高亮==\n\n"
        "++蓝色高亮++\n\n"
        "%%粉色高亮%%\n\n"
        "&&绿色高亮&&\n\n"
        "!!红色强调!!\n\n"
        "@@蓝色强调@@\n\n"
        "^^橙色强调^^\n"
    )
    html = _convert(md_tight, theme)

    # Each content string must survive and be wrapped in something styled.
    for text in ["黄色高亮", "蓝色高亮", "粉色高亮", "绿色高亮",
                 "红色强调", "蓝色强调", "橙色强调"]:
        assert text in html, f"highlight content '{text}' missing from output"

    # Minimum sanity: at least 7 inline <span> tags with style= for the
    # seven custom markers above.
    assert html.count("<span") >= 7, (
        f"expected >=7 styled <span> from 7 highlight markers; got {html.count('<span')}"
    )


# ---------------------------------------------------------------------------
# Images and links
# ---------------------------------------------------------------------------

def test_image_rendered_with_style(theme):
    """![alt](url) should produce an <img> with inline style."""
    md = "![示例图](https://example.com/img.png)"
    html = _convert(md, theme)

    assert "<img" in html
    assert "https://example.com/img.png" in html
    assert "style=" in html


def test_ordinary_http_link_kept(theme):
    """Normal https: links should render fine (sanity check for #5)."""
    md = "参考 [文档](https://example.com/doc)"
    html = _convert(md, theme)

    assert '<a ' in html
    assert 'https://example.com/doc' in html


# ---------------------------------------------------------------------------
# Sanity: list and blockquote
# ---------------------------------------------------------------------------

def test_unordered_list(theme):
    md = "- 第一项\n- 第二项\n- 第三项\n"
    html = _convert(md, theme)
    assert "<ul" in html
    assert "第一项" in html and "第二项" in html and "第三项" in html


def test_blockquote(theme):
    md = "> 一句引用\n> 的内容\n"
    html = _convert(md, theme)
    assert "<blockquote" in html
    assert "一句引用" in html


# ---------------------------------------------------------------------------
# 新主题包(2026)新增能力
# ---------------------------------------------------------------------------

def test_sec_marker_renders_divider(theme):
    """`[SEC]` 单独一行应渲染为分节符 <p>。"""
    md = "前文\n\n[SEC]\n\n后文"
    html = _convert(md, theme)
    # 主题的 section_divider_text 是 "● ● ●"
    _, _, divider, _ = theme
    assert divider in html, "[SEC] 没有渲染出 divider 文本"


def test_legacy_eq_marker_still_works(theme):
    """老语法 `===` 单独一行也应继续渲染为分节符(向后兼容)。"""
    md = "前文\n\n===\n\n后文"
    html = _convert(md, theme)
    _, _, divider, _ = theme
    assert divider in html


def test_ol_uses_list_style_num_token(theme):
    """有序列表应按主题的 list_style.num_container/prefix/suffix 渲染数字。"""
    md = "1. 第一项\n2. 第二项\n"
    html = _convert(md, theme)
    assert "<ol" in html and "<li" in html
    # refined-blue 的 num_formatter 是 "padded",所以 1 渲染为 "01"
    # 数字应包在 <span> 里(而不是依赖 <ol> 的原生序号)
    assert "<span" in html
    assert "01" in html or "1" in html  # padded 或 decimal 都接受
    assert "第一项" in html and "第二项" in html


def test_ul_uses_list_style_bullet_token(theme):
    """无序列表应按主题的 list_style.bullet_container/bullet_char 渲染项目符号。"""
    md = "- 项 A\n- 项 B\n"
    html = _convert(md, theme)
    assert "<ul" in html and "<li" in html
    # bullet 包在 <span> 里
    assert "<span" in html
    assert "项 A" in html and "项 B" in html


def test_all_15_themes_load_without_error():
    """所有 15 套主题都应能成功加载,且包含必需字段。"""
    from html_converter import list_themes
    names = list_themes()
    assert len(names) == 15, f"应有 15 套主题,实际 {len(names)}: {names}"
    for name in names:
        styles, highlights, divider, list_style = load_theme(theme_name=name)
        # 每套主题至少要有 body / h2 / p / strong 这几个基础键
        for key in ("body", "h2", "p", "strong", "blockquote", "code_inline"):
            assert key in styles, f"主题 {name} 缺少 styles.{key}"
        # 高亮键至少要齐 4 + 3 套
        for key in ("hl_yellow", "hl_blue", "hl_pink", "hl_green",
                    "em_red", "em_blue", "em_orange"):
            assert key in highlights, f"主题 {name} 缺少 highlights.{key}"
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall