Skip to main content

entari-plugin-htmlrender

面向 Entari 的可插拔图片渲染插件:支持将 HTML、Markdown、纯文本、Jinja2 模板 渲染为图片,同时内置基于 Pillow / Skia 的独立 Python 绘图能力。

在线文档 · 快速开始 · 配置参考 · API 参考 · 示例项目 · 升级到 0.2


功能概览

  • 统一的内容出图接口:通过 HtmlRenderer 一致地渲染 HTML、Markdown、纯文本与 Jinja2 模板,也支持用 HtmlPreparer 将“内容准备”与“后端出图”拆开复用。
  • 可切换的 HTML 渲染后端:
    • Takumi:基于 Rust 的进程内原生排版引擎,轻量快速,额外提供 SVG 输出、布局测量、动图编码与动态字体管理。
    • Playwright:支持远程 WebSocket / CDP 连接与本地启动,完整支持动态网页、选择器截图与 KaTeX 数学公式。
  • 独立的 Python 绘图通道:无需启用任何 HTML 引擎,即可直接用 Pillow 或 Skia 编写同步绘图函数(支持按文件/模块组织与开发期热重载),或渲染声明式 RasterScene。
  • 默认安全的资源边界:本地文件读取采用显式路径白名单(含符号链接校验),远程资源拉取默认拦截私网地址并逐跳校验重定向。

快速开始

运行环境要求:Python >=3.11,<4.0,Entari >=0.19.4,<0.20.0。

1. 安装插件与所需后端

基础包不包含任何渲染后端,请按实际场景选择可选依赖(可组合安装,如 [takumi,pillow]):

# 推荐:使用 Takumi 渲染静态内容(无需安装浏览器)
uv add "entari-plugin-htmlrender[takumi]>=0.2.0"

# 需要完整浏览器能力(JavaScript、网页截图、数学公式)
uv add "entari-plugin-htmlrender[playwright]>=0.2.0"

# 需要 Python 绘图能力(按需选择 pillow 或 skia)
uv add "entari-plugin-htmlrender[pillow]>=0.2.0"

2. 配置 Entari

在 Entari 配置文件中启用 htmlrender:

plugins:
  htmlrender:
    provider: takumi
    startup: probe

3. 在插件中调用

在事件处理函数中通过 Entari 依赖注入直接声明 HtmlRenderer(支持注入 HtmlRenderer、HtmlPreparer、TemplateRenderer、ResourceAccess、GraphicsRenderer、DrawingRenderer 或聚合入口 HtmlRenderService):

from entari_plugin_htmlrender import HtmlRenderer, RasterOptions, RenderedImage


async def render_card(renderer: HtmlRenderer) -> RenderedImage:
    return await renderer.rasterize_markdown(
        "# Hello, Entari\n\nRendered with Takumi.",
        raster=RasterOptions(width=720),
    )

返回的 RenderedImage 可直接通过 bytes(image) 提取 PNG / JPEG 字节流,并通过 image.width、image.height、image.media_type 读取元信息。HTML、纯文本与模板分别对应 rasterize_html()、rasterize_text() 和 rasterize_template()。


渲染与绘图方案对比

方案 可选依赖 适用场景 主要边界
Takumi [takumi] 静态卡片、帮助菜单、Markdown、Jinja2 模板、SVG、测量与动图 不执行 JavaScript;不支持 Markdown 数学公式;样式需内联
Playwright [playwright] 复杂浏览器布局、JavaScript、网页/选择器截图、KaTeX 数学公式 需运行浏览器实例(生产环境推荐独立部署远程服务)
Pillow / Skia [pillow] / [skia] 使用 Python 函数直接绘制卡片、拼图、矢量图形或 RasterScene 独立于 HTML 引擎,不解析 HTML / Markdown

其他可选依赖:[filehost](远程浏览器本地大文件托管)、[prometheus](Prometheus 指标)、[sentry](Sentry 追踪)、[all](安装全部可选组件)。


示例与文档


致谢

本项目基于开源社区的多项优秀工作构建与演进,在此一并致谢:


开源协议

本项目基于 MIT License 开源。

Metadata

Release files for entari-plugin-htmlrender 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for entari-plugin-htmlrender 0.2.0
File Size Uploaded Provenance Actions
entari_plugin_htmlrender-0.2.0.tar.gz 2.8 MB With provenance Details for entari_plugin_htmlrender-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for entari-plugin-htmlrender 0.2.0
File Interpreter ABI Platform Actions
entari_plugin_htmlrender-0.2.0-py3-none-any.whl Python 3 none any Details for entari_plugin_htmlrender-0.2.0-py3-none-any.whl

Total release size: 4.1 MB

Release files / entari_plugin_htmlrender-0.2.0.tar.gz

Download URL entari_plugin_htmlrender-0.2.0.tar.gz
Size 2.8 MB
Tags Source
SHA-256 checksum
How to use checksums
7877764ef398112de9d895e0abc7f2f1202cda9d1b3d5e4e80a4a10e53c76936
BLAKE2b-256 checksum
How to use checksums
0ebe75f7db72b6c9cc06f0116f8910df4a7b2d9ebd99ffae69392bb0138a2f22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Release files / entari_plugin_htmlrender-0.2.0-py3-none-any.whl

Download URL entari_plugin_htmlrender-0.2.0-py3-none-any.whl
Size 1.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
d02ab343e8a721b8a4ad2f1a75d02af20b0da100a161baafc5fce07addd05f62
BLAKE2b-256 checksum
How to use checksums
6dc9f324cc930adfbee7724b3ea4bc12aefff7d919ce19e8983f66b3c42c4c9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Security for entari-plugin-htmlrender 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for entari_plugin_htmlrender-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page