Lightweight HTML rendering plugin for NoneBot
Project description
nonebot-plugin-htmlkit
一个基于 litehtml 的轻量级 HTML 渲染插件。
特性
- 基于 fontconfig 的字体管理, 支持系统字体和自定义字体
- 提供了 HTML,纯文本,markdown,和 Jinja2 模板渲染的快捷函数
- 支持自定义图片和 CSS 的加载策略
- 支持通过 CSS 控制样式
- 支持自适应控制渲染宽度
安装
使用 nb-cli 安装:
nb plugin install nonebot-plugin-htmlkit
或者,使用你选择的 Python 包管理器工具安装 nonebot-plugin-htmlkit 即可。
使用
API
from nonebot import require
require("nonebot_plugin_htmlkit")
from nonebot_plugin_htmlkit import (
text_to_pic,
md_to_pic,
template_to_pic,
html_to_pic,
)
[!CAUTION] 注意:请先
require("nonebot_plugin_htmlkit")后再import插件!!!
配置项
plugin-htmlkit 的配置项主要为 fontconfig 的相关配置。
对于 FC/FONTCONFIG 开头的配置项,请参考 fontconfig 文档 以了解更多。
# ===============================
# Fontconfig 配置
# ===============================
# FONTCONFIG_FILE
# 用于覆盖默认的配置文件路径。
FONTCONFIG_FILE: str
# FONTCONFIG_PATH
# 用于覆盖默认的配置目录。
FONTCONFIG_PATH: str
# FONTCONFIG_SYSROOT
# 用于设置默认的 sysroot 目录。
FONTCONFIG_SYSROOT: str
# FC_DEBUG
# 用于输出详细的调试信息。
# 详细见 fontconfig 文档。
FC_DEBUG: str
# FC_DBG_MATCH_FILTER
# 用于在调试时过滤特定模式。
# 仅当 FC_DEBUG 设置为 MATCH2 时生效。
FC_DBG_MATCH_FILTER: str
# FC_LANG
# 用于指定查询时的默认语言(弱绑定)。
# 如果未设置,则从当前 locale 推导。
FC_LANG: str
# FONTCONFIG_USE_MMAP
# 控制是否使用 mmap(2) 来处理缓存文件(如果可用)。
# 值为布尔类型(yes/no, 1/0)。
# 如果显式设置该变量,将跳过系统检查并强制启用或禁用。
FONTCONFIG_USE_MMAP: str
构建说明
受限于 XMake, 构建时须使用 Python 3.10.11,并且在 uv sync 时需一同安装 build 组的依赖(pip setuptools wheel 等)。
以下说明假定你已经按照 XMake 官方文档 安装好了 XMake 并在 PATH 上可用。
# 拉取子模块
git submodule update --init --recursive
# 创建虚拟环境
uv venv
# 激活虚拟环境,在不同操作系统下的命令不同
source .venv/bin/activate
# 安装开发依赖,同时避免直接构建原生包
uv sync --no-install-workspace
# 配置依赖
xmake f -m releasedbg
# 构建
xmake build
# 安装到 bindist,加速 editable 安装
xmake install -o bindist
# 使用 uv 安装到当前虚拟环境
uv sync --reinstall-package nonebot-plugin-htmlkit
如果对 litehtml 做了修改,需重新构建:
xmake require --force litehtml
# 或者用以下更 dirty 但是快速的方法
rm -r build
xmake clean --all
# 重新构建与安装
xmake build
xmake install -o bindist
uv sync --reinstall-package nonebot-plugin-htmlkit
许可证
本插件的 C++ 部分静态链接了 litehtml cairo pango 等第三方库,它们在 LGPL 许可证下发布。
本插件的 Python 部分(所有 .py 文件)在 MIT 许可证下发布,C++ 部分在 LGPL-3.0-or-later 许可证下发布。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nonebot_plugin_htmlkit-0.1.0rc2.tar.gz.
File metadata
- Download URL: nonebot_plugin_htmlkit-0.1.0rc2.tar.gz
- Upload date:
- Size: 51.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8186774697277a591299e5bed19369fffaae4eafe6a2af847003a28a93d0a5ab
|
|
| MD5 |
43ab51437f85d352d774982b6f589e30
|
|
| BLAKE2b-256 |
1417407f84ec42a1fc550a365c7d449e30c7837c3c6162a9a5ab03392221c8b8
|
File details
Details for the file nonebot_plugin_htmlkit-0.1.0rc2-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: nonebot_plugin_htmlkit-0.1.0rc2-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 7.5 MB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2214c704f3bc9dc80bbce04108bf7d052fe0de9198b887e6e976058210edf9c0
|
|
| MD5 |
eda5a9f9d697c4e90b7408c598294f81
|
|
| BLAKE2b-256 |
afeb1065659aaefd54a9944948ccf0e10709e923cd5cf2d031e8df939dfb5e1e
|
File details
Details for the file nonebot_plugin_htmlkit-0.1.0rc2-cp310-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: nonebot_plugin_htmlkit-0.1.0rc2-cp310-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 9.3 MB
- Tags: CPython 3.10+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f468ceeef5e4108009f5ef5f9f26e1656245dd7d321bb06f1654428e0e00218f
|
|
| MD5 |
be4728e122b8991a43fa73948e2e0e11
|
|
| BLAKE2b-256 |
817f0236df08b8afa1956fe2a6f29a9bf388e713a4da3f932d372dbf26d7f494
|
File details
Details for the file nonebot_plugin_htmlkit-0.1.0rc2-cp310-abi3-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: nonebot_plugin_htmlkit-0.1.0rc2-cp310-abi3-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 9.0 MB
- Tags: CPython 3.10+, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29ca908a7d1453d1de20413545868a8439a38b8df9166c369a60906522783a35
|
|
| MD5 |
dd4652a1ca858dad3daa056d25ea008b
|
|
| BLAKE2b-256 |
a56d34e1b7cbdbe24f27f0d91212af75f20d2b0c6412b99c0bf8af6f27d04b56
|
File details
Details for the file nonebot_plugin_htmlkit-0.1.0rc2-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: nonebot_plugin_htmlkit-0.1.0rc2-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 7.0 MB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5dbea84edf8427eecfcd5468af33d9aea927126ddd693d103834fc830222f6f
|
|
| MD5 |
07881a5315b9a6358a2e9880290d2298
|
|
| BLAKE2b-256 |
059834edcf8678c374c1ccea2d2ac8e6bce323048cb14923199bb8d07650ec16
|