Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nonebot_plugin_htmlkit-0.1.0rc3.tar.gz (51.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

nonebot_plugin_htmlkit-0.1.0rc3-cp310-abi3-win_amd64.whl (7.5 MB view details)

Uploaded CPython 3.10+Windows x86-64

nonebot_plugin_htmlkit-0.1.0rc3-cp310-abi3-manylinux_2_34_x86_64.whl (9.3 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.34+ x86-64

nonebot_plugin_htmlkit-0.1.0rc3-cp310-abi3-manylinux_2_34_aarch64.whl (9.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.34+ ARM64

nonebot_plugin_htmlkit-0.1.0rc3-cp310-abi3-macosx_11_0_arm64.whl (7.0 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file nonebot_plugin_htmlkit-0.1.0rc3.tar.gz.

File metadata

File hashes

Hashes for nonebot_plugin_htmlkit-0.1.0rc3.tar.gz
Algorithm Hash digest
SHA256 9ab747edd3977204500e8e06c18733a9ddcb0c500de4761bad319e72bc05bffb
MD5 70f8b2c86d39be50b8e4c3427b2e6fd7
BLAKE2b-256 038f8b44c1398b9316b7399c3b0be513a3fff36c043dd7a4ac44d7abcb122f9c

See more details on using hashes here.

File details

Details for the file nonebot_plugin_htmlkit-0.1.0rc3-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for nonebot_plugin_htmlkit-0.1.0rc3-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d66891d2ce892c26caa3b20dd54f498672bf4989817a1a2fb964e6717fa4ee61
MD5 e325575f07fe8f1d0608cb49435323d5
BLAKE2b-256 46d2d65d39829d301313578fdd3e3de672bb3cb0dd8944a686e96df376924b23

See more details on using hashes here.

File details

Details for the file nonebot_plugin_htmlkit-0.1.0rc3-cp310-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for nonebot_plugin_htmlkit-0.1.0rc3-cp310-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2da2ad7d35ab323c7d2a31db3d4d602d797e973d0ba1121b2ec657c03c01efbd
MD5 088e9d80a494825760f5261d12c79eee
BLAKE2b-256 c01ed02c39f3b14a2385462c91a310c6a883887f38bbe2bff4813fd5c672d951

See more details on using hashes here.

File details

Details for the file nonebot_plugin_htmlkit-0.1.0rc3-cp310-abi3-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for nonebot_plugin_htmlkit-0.1.0rc3-cp310-abi3-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 fceeaf9bf00692bc572cf7fe4f34590ed833ac798a8ef31293c81f384e4550db
MD5 03818142e319bd56a9b378d839beedc0
BLAKE2b-256 9df78740d114995e71a13421ecbcae91384bb7ef49cd22b207b3e9361269a692

See more details on using hashes here.

File details

Details for the file nonebot_plugin_htmlkit-0.1.0rc3-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nonebot_plugin_htmlkit-0.1.0rc3-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5d7e44b155dc1d543eec0f39c51563d398d72bb54a95a268564fb4cd68da3db3
MD5 311c886f3664ca8bc26718a8c63de0cb
BLAKE2b-256 c719c8c7f2f48aaa614f67c2d6f0bf86269cd36e64be2aa508687f66f305cc48

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page