Metadata-Version: 2.4
Name: wechat-formatter
Version: 1.0.0
Summary: Render Markdown into inline-styled HTML for WeChat Official Account (公众号) articles, with 6 visual themes × 12 colors.
Author: wechat-formatter contributors
License: MIT
Project-URL: Homepage, https://github.com/your-org/wechat-formatter
Project-URL: Repository, https://github.com/your-org/wechat-formatter
Keywords: wechat,markdown,公众号,wechat-mp,html,formatter,mistune
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Text Processing :: Markup :: HTML
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: mistune<4.0,>=3.0
Dynamic: license-file

# wechat-formatter

把 Markdown 渲染成**内联样式 HTML**，可直接复制粘贴到微信公众号编辑器。

基于 [`mistune`](https://github.com/lepture/mistune)，内置 **6 种视觉风格 × 12 种配色 = 72 套模板**，所有 CSS 都写在 `style="..."` 内联属性里，不依赖任何外部 CSS 文件或 JS。

## 安装

```bash
pip install wechat-formatter
```

或从源码安装：

```bash
cd wechat-formatter
pip install .
```

## 快速开始

```python
from wechat_formatter import get_template, render_article, FormatTweaks

markdown_text = """\
# 你好，公众号

这是一段**普通文字**，包含 ==高亮== 内容和 ^上标^、~下标~。

## 一个小标题

- 列表项一
- 列表项二
- ~~删除线~~

> 这是一段引用

```python
print("hello")
```
"""

# 按中文风格名 + 颜色名选择模板
template = get_template("极简风", "经典")

# 可选：覆盖字号、行高、边距等
tweaks = FormatTweaks(
    fontSize=15,
    lineHeight=1.75,
    paragraphSpacing=16,
)

html = render_article(markdown_text, template, tweaks)

# 把 html 写入文件，用浏览器打开后全选复制，粘贴到公众号编辑器
with open("article.html", "w", encoding="utf-8") as f:
    f.write(html)
```

## 模板选择

`get_template(category, color)` 接受中文风格名或英文 id：

| 风格中文名 | 英文 id |
|---|---|
| 新粗野风 | `neo-brutalism` |
| 极简风 | `minimalist` |
| 商务风 | `business` |
| 文艺风 | `literary` |
| 科技风 | `tech` |
| 节庆风 | `festive` |

颜色名（12 种）：`经典`、`雅致`、`先锋`、`深邃`、`晨光`、`星穹`、`暖阳`、`暮色`、`清泉`、`破晓`、`璀璨`、`幽蓝`。

也可以遍历全部模板：

```python
from wechat_formatter import all_templates, grouped_templates

for tpl in all_templates:
    print(tpl.category, tpl.name, tpl.themeColor)

# 按风格分组
for group in grouped_templates:
    print(group["name"], len(group["templates"]))
```

## FormatTweaks 参数

| 字段 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| `themeColor` | `str \| None` | `None` | 覆盖模板主题色（hex） |
| `fontSize` | `int` | `15` | 正文字号 px |
| `lineHeight` | `float` | `1.75` | 行高 |
| `paragraphSpacing` | `int` | `16` | 段间距 px |
| `firstLineIndent` | `bool` | `False` | 首行缩进 2em |
| `letterSpacing` | `float` | `0.5` | 字间距 px |
| `imageRadius` | `int` | `4` | 图片圆角 px |
| `h1Layout` | `str \| None` | `None` | 一级标题对齐：`left`/`center`/`right` |
| `h2Layout` | `str \| None` | `None` | 二级标题对齐 |
| `pagePaddingTop` | `int` | `20` | 页面上边距 px |
| `pagePaddingRight` | `int` | `20` | 页面右边距 px |
| `pagePaddingBottom` | `int` | `20` | 页面下边距 px |
| `pagePaddingLeft` | `int` | `20` | 页面左边距 px |

## 支持的 Markdown 语法

- 标准：标题 `#`/`##`/`###`、段落、**加粗**、*斜体*、`行内代码`、链接、图片、引用、有序/无序列表、分割线 `---`、表格
- 扩展：
  - `==高亮==` → `<mark>`
  - `^上标^` → `<sup>`
  - `~下标~` → `<sub>`
  - `~~删除线~~` → `<del>`
  - 任务列表（`- [x]` / `- [ ]`）
  - 代码块带 macOS 风格圆点头部
  - 段落中多图自动排成一行

## API 一览

```python
from wechat_formatter import (
    # 渲染
    render_article,
    # 模板
    all_templates,        # list[TemplateConfig]
    grouped_templates,    # list[dict]，按风格分组
    get_template,         # (category, color) -> TemplateConfig
    build_template,       # 自定义构建
    get_styles_by_category,
    # 类型
    TemplateConfig,
    FormatTweaks,
    BaseStyle,
    # 颜色
    color_palettes,
    categories_list,
    names,
    hex_to_rgb,
    hex_to_rgba,
    # 工具
    get_style_value,
    ensure_style_value,
    bg_fallback,
)
```

## License

MIT
