nonebot-plugin-htmlrender 0.6.5__tar.gz → 0.6.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nonebot_plugin_htmlrender-0.6.6/.dockerignore +10 -0
- nonebot_plugin_htmlrender-0.6.6/.github/workflows/docker_image.yml +53 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/PKG-INFO +58 -30
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/README.md +57 -29
- nonebot_plugin_htmlrender-0.6.6/docker-compose.yaml +37 -0
- nonebot_plugin_htmlrender-0.6.6/dockerfile +39 -0
- nonebot_plugin_htmlrender-0.6.6/entrypoint.sh +71 -0
- nonebot_plugin_htmlrender-0.6.6/example/docker-compose.yaml +1 -0
- nonebot_plugin_htmlrender-0.6.6/example/entrypoint.sh +1 -0
- nonebot_plugin_htmlrender-0.6.6/example/pyproject.toml +24 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/nonebot_plugin_htmlrender/browser.py +4 -4
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/pyproject.toml +1 -1
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/uv.lock +570 -524
- nonebot_plugin_htmlrender-0.6.5/example/.env.dev +0 -7
- nonebot_plugin_htmlrender-0.6.5/example/bot.py +0 -12
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/.github/workflows/codecov.yml +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/.github/workflows/publish.yml +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/.gitignore +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/.pre-commit-config.yaml +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/.python-version +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/LICENSE +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/docs/example.md +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/docs/html2pic.png +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/docs/md2pic.png +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/docs/template2pic.png +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/docs/text2pic.png +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/example/plugins/render/__init__.py +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/example/plugins/render/html2pic.html +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/example/plugins/render/templates/markdown.css +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/example/plugins/render/templates/mystyle.css +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/example/plugins/render/templates/progress.html.jinja2 +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/example/plugins/render/templates/text.html +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/example/plugins/render/utils.py +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/nonebot_plugin_htmlrender/__init__.py +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/nonebot_plugin_htmlrender/config.py +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/nonebot_plugin_htmlrender/consts.py +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/nonebot_plugin_htmlrender/data_source.py +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/nonebot_plugin_htmlrender/install.py +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/nonebot_plugin_htmlrender/process.py +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/nonebot_plugin_htmlrender/signal.py +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/nonebot_plugin_htmlrender/templates/github-markdown-light.css +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/nonebot_plugin_htmlrender/templates/katex/katex.min.b64_fonts.css +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/nonebot_plugin_htmlrender/templates/katex/katex.min.js +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/nonebot_plugin_htmlrender/templates/katex/mathtex-script-type.min.js +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/nonebot_plugin_htmlrender/templates/katex/mhchem.min.js +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/nonebot_plugin_htmlrender/templates/markdown.html +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/nonebot_plugin_htmlrender/templates/pygments-default.css +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/nonebot_plugin_htmlrender/templates/text.css +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/nonebot_plugin_htmlrender/templates/text.html +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/nonebot_plugin_htmlrender/utils.py +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/tests/__init__.py +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/tests/conftest.py +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/tests/resources/test_template_filter.png +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/tests/templates/markdown.css +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/tests/templates/mystyle.css +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/tests/templates/progress.html.jinja2 +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/tests/templates/text.html +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/tests/test_browser.py +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/tests/test_deprecated_decorator.py +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/tests/test_htmlrender.py +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/tests/test_install.py +0 -0
- {nonebot_plugin_htmlrender-0.6.5 → nonebot_plugin_htmlrender-0.6.6}/tests/test_process.py +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
name: Build and upload docker image
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
pull_request:
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group:
|
|
11
|
+
${{ github.workflow }}-${{ github.ref_name }}-${{
|
|
12
|
+
github.event.pull_request.number || github.sha }}
|
|
13
|
+
cancel-in-progress: true
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
build:
|
|
17
|
+
name: "build image"
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
|
|
22
|
+
- name: Login to GitHub Container Registry
|
|
23
|
+
uses: docker/login-action@v3
|
|
24
|
+
with:
|
|
25
|
+
registry: ghcr.io
|
|
26
|
+
username: ${{ github.actor }}
|
|
27
|
+
password: ${{ secrets.GITHUB_TOKEN }}
|
|
28
|
+
|
|
29
|
+
- name: Set up QEMU
|
|
30
|
+
uses: docker/setup-qemu-action@v3
|
|
31
|
+
|
|
32
|
+
- name: Set up Docker Buildx
|
|
33
|
+
uses: docker/setup-buildx-action@v3
|
|
34
|
+
|
|
35
|
+
- name: Extract metadata for Docker
|
|
36
|
+
id: meta
|
|
37
|
+
uses: docker/metadata-action@v5
|
|
38
|
+
with:
|
|
39
|
+
images: ghcr.io/${{ github.repository }}/nonebot2-playwrght-uv
|
|
40
|
+
tags: |
|
|
41
|
+
type=raw,value=latest,enable={{is_default_branch}}
|
|
42
|
+
type=ref,event=branch
|
|
43
|
+
type=sha,format=long
|
|
44
|
+
|
|
45
|
+
- name: Build and push
|
|
46
|
+
uses: docker/build-push-action@v6
|
|
47
|
+
with:
|
|
48
|
+
push: ${{ github.event_name != 'pull_request' }}
|
|
49
|
+
platforms: linux/amd64,linux/arm64
|
|
50
|
+
tags: ${{ steps.meta.outputs.tags }}
|
|
51
|
+
labels: ${{ steps.meta.outputs.labels }}
|
|
52
|
+
cache-from: type=gha,scope=nonebot2-playwrght-uv
|
|
53
|
+
cache-to: type=gha,mode=min,scope=nonebot2-playwrght-uv
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nonebot-plugin-htmlrender
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.6
|
|
4
4
|
Summary: 通过浏览器渲染图片
|
|
5
5
|
Project-URL: Homepage, https://github.com/kexue-z/nonebot-plugin-htmlrender
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/kexue-z/nonebot-plugin-htmlrender/issues
|
|
@@ -44,13 +44,13 @@ Description-Content-Type: text/markdown
|
|
|
44
44
|
- 可通过查看`example`参考使用实例
|
|
45
45
|
- 如果有安装浏览器等问题,先查看文档最底下的`常见问题`再去看 issue 有没有已经存在的
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
## ✨ 功能
|
|
48
48
|
|
|
49
49
|
- 通过 html 和浏览器生成图片
|
|
50
50
|
- 支持`纯文本` `markdown` 和 `jinja2` 模板输入
|
|
51
51
|
- 通过 CSS 来控制样式
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
## 使用
|
|
54
54
|
|
|
55
55
|
参考[example/plugins/render/**init**.py](example/plugins/render/__init__.py)
|
|
56
56
|
|
|
@@ -72,9 +72,9 @@ from nonebot_plugin_htmlrender import (
|
|
|
72
72
|
# 注意顺序,先require再 from ... import ...
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
## 配置
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
### .env 配置项说明
|
|
78
78
|
|
|
79
79
|
```ini
|
|
80
80
|
# Playwright 浏览器引擎类型
|
|
@@ -112,9 +112,52 @@ htmlrender_browser_executable_path = ""
|
|
|
112
112
|
# 可选,用于连接已运行的浏览器实例
|
|
113
113
|
# 使用时需要在启动浏览器时添加参数 --remote-debugging-port=端口号
|
|
114
114
|
htmlrender_connect_over_cdp = "http://127.0.0.1:9222"
|
|
115
|
+
|
|
116
|
+
# Playwright ws 连接地址
|
|
117
|
+
# 可选,用于连接 playwright 的 docker 容器
|
|
118
|
+
# https://playwright.dev/docs/docker
|
|
119
|
+
# 配套的 docker-compose.yaml 中,已经填好了
|
|
120
|
+
htmlrender_connect="ws://playwright:3000"
|
|
115
121
|
```
|
|
116
122
|
|
|
117
|
-
##
|
|
123
|
+
## 部署
|
|
124
|
+
|
|
125
|
+
### (建议)使用 docker compose 进行部署
|
|
126
|
+
|
|
127
|
+
> 前提条件:你的项目使用 uv 管理 或 `pyproject.toml` 的 `dependencies` 中已经包含你的依赖
|
|
128
|
+
>
|
|
129
|
+
> 此方法会将 nonebot2 和 playwright 分开两个容器
|
|
130
|
+
|
|
131
|
+
1. 将 `docker-compose.yaml` & `entrypoint.sh` 复制到你自己的项目根目录下
|
|
132
|
+
2. 根据你的需要调整 `docker-compose.yaml` & `entrypoint.sh`
|
|
133
|
+
3. 拉取镜像 `docker compose pull`
|
|
134
|
+
4. 启动容器 `docker compose up -d`
|
|
135
|
+
|
|
136
|
+
> - 查看日志 `docker compose logs -f`
|
|
137
|
+
> - 停止/重启容器 `docker compose`
|
|
138
|
+
|
|
139
|
+
### docker 单容器部署
|
|
140
|
+
|
|
141
|
+
> 前提条件:你的项目使用 uv 管理 或 `pyproject.toml` 的 `dependencies` 中已经包含你的依赖
|
|
142
|
+
>
|
|
143
|
+
> 此方法会将 nonebot2 和 playwright 运行在同一个容器中
|
|
144
|
+
>
|
|
145
|
+
> 而且你还有需要清楚你要干什么
|
|
146
|
+
|
|
147
|
+
1. 将 `docker-compose.yaml` & `entrypoint.sh` 复制到你自己的项目根目录下
|
|
148
|
+
2. 根据你的情况,调整指令
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
docker run -d \
|
|
152
|
+
--name nonebot2 \
|
|
153
|
+
-v $(pwd):/app \
|
|
154
|
+
-p 9012:9012 \
|
|
155
|
+
-e "PLAYWRIGHT_BROWSERS_PATH=/app/pw-browsers" \
|
|
156
|
+
ghcr.io/kexue-z/nonebot-plugin-htmlrender/nonebot2-playwrght-uv sh -c "./entrypoint.sh"
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## 说明
|
|
160
|
+
### markdown 转 图片
|
|
118
161
|
|
|
119
162
|
- 使用 `GitHub-light` 样式
|
|
120
163
|
- 支持绝大部分 md 语法
|
|
@@ -125,38 +168,38 @@ htmlrender_connect_over_cdp = "http://127.0.0.1:9222"
|
|
|
125
168
|
- 图片需要使用外部连接并使用`html`格式 否则文末会超出截图范围
|
|
126
169
|
- 图片可使用 md 语法 路径可为 `绝对路径`(建议), 或 `相对于template_path` 的路径
|
|
127
170
|
|
|
128
|
-
|
|
171
|
+
### 模板 转 图片
|
|
129
172
|
|
|
130
173
|
- 使用 jinja2 模板引擎
|
|
131
174
|
- 页面参数可自定义
|
|
132
175
|
|
|
133
|
-
|
|
176
|
+
## 🌰 栗子
|
|
134
177
|
|
|
135
178
|
[example.md](docs/example.md)
|
|
136
179
|
|
|
137
|
-
|
|
180
|
+
### 文本转图片(同时文本里面可以包括 html 图片)
|
|
138
181
|
|
|
139
182
|

|
|
140
183
|
|
|
141
|
-
|
|
184
|
+
### markdown 转图片(同时文本里面可以包括 html 图片)
|
|
142
185
|
|
|
143
186
|

|
|
144
187
|
|
|
145
|
-
|
|
188
|
+
### 纯 html 转图片
|
|
146
189
|
|
|
147
190
|

|
|
148
191
|
|
|
149
|
-
|
|
192
|
+
### jinja2 模板转图片
|
|
150
193
|
|
|
151
194
|

|
|
152
195
|
|
|
153
|
-
|
|
196
|
+
## 特别感谢
|
|
154
197
|
|
|
155
198
|
- [MeetWq](https://github.com/MeetWq) 提供数学公式支持代码和代码高亮
|
|
156
199
|
|
|
157
|
-
|
|
200
|
+
## 常见疑难杂症
|
|
158
201
|
|
|
159
|
-
|
|
202
|
+
### `playwright._impl._api_types.Error:` 初次运行时报错
|
|
160
203
|
|
|
161
204
|
- 一般为缺少必要的运行环境,如中文字体等
|
|
162
205
|
|
|
@@ -175,18 +218,3 @@ LANG zh_CN.UTF-8
|
|
|
175
218
|
LANGUAGE zh_CN.UTF-8
|
|
176
219
|
LC_ALL zh_CN.UTF-8
|
|
177
220
|
```
|
|
178
|
-
|
|
179
|
-
### CentOS 使用 `yum`
|
|
180
|
-
|
|
181
|
-
- ~~小心 CentOS~~
|
|
182
|
-
-
|
|
183
|
-
参考[CentOS Dockerfile](https://github.com/kumaraditya303/playwright-centos/blob/master/Dockerfile)
|
|
184
|
-
- 添加中文字体库
|
|
185
|
-
- ~~最佳解决办法~~
|
|
186
|
-
- 使用 Docker 然后用 Python 镜像 按照上面 Ubuntu 的写 `dockerfile`
|
|
187
|
-
|
|
188
|
-
下面这个依赖运行一下 也许就可以用了
|
|
189
|
-
|
|
190
|
-
```sh
|
|
191
|
-
dnf install -y alsa-lib at-spi2-atk at-spi2-core atk cairo cups-libs dbus-libs expat flac-libs gdk-pixbuf2 glib2 glibc gtk3 libX11 libXcomposite libXdamage libXext libXfixes libXrandr libXtst libcanberra-gtk3 libdrm libgcc libstdc++ libxcb libxkbcommon libxshmfence libxslt mesa-libgbm nspr nss nss-util pango policycoreutils policycoreutils-python-utils zlib cairo-gobject centos-indexhtml dbus-glib fontconfig freetype gtk2 libXcursor libXi libXrender libXt liberation-fonts-common liberation-sans-fonts libffi mozilla-filesystem p11-kit-trust pipewire-libs harfbuzz-icu libglvnd-glx libglvnd-egl libnotify opus woff2 gstreamer1-plugins-base gstreamer1-plugins-bad-free openjpeg2 libwebp enchant libsecret hyphen libglvnd-gles
|
|
192
|
-
```
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
- 可通过查看`example`参考使用实例
|
|
5
5
|
- 如果有安装浏览器等问题,先查看文档最底下的`常见问题`再去看 issue 有没有已经存在的
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## ✨ 功能
|
|
8
8
|
|
|
9
9
|
- 通过 html 和浏览器生成图片
|
|
10
10
|
- 支持`纯文本` `markdown` 和 `jinja2` 模板输入
|
|
11
11
|
- 通过 CSS 来控制样式
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
## 使用
|
|
14
14
|
|
|
15
15
|
参考[example/plugins/render/**init**.py](example/plugins/render/__init__.py)
|
|
16
16
|
|
|
@@ -32,9 +32,9 @@ from nonebot_plugin_htmlrender import (
|
|
|
32
32
|
# 注意顺序,先require再 from ... import ...
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
## 配置
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
### .env 配置项说明
|
|
38
38
|
|
|
39
39
|
```ini
|
|
40
40
|
# Playwright 浏览器引擎类型
|
|
@@ -72,9 +72,52 @@ htmlrender_browser_executable_path = ""
|
|
|
72
72
|
# 可选,用于连接已运行的浏览器实例
|
|
73
73
|
# 使用时需要在启动浏览器时添加参数 --remote-debugging-port=端口号
|
|
74
74
|
htmlrender_connect_over_cdp = "http://127.0.0.1:9222"
|
|
75
|
+
|
|
76
|
+
# Playwright ws 连接地址
|
|
77
|
+
# 可选,用于连接 playwright 的 docker 容器
|
|
78
|
+
# https://playwright.dev/docs/docker
|
|
79
|
+
# 配套的 docker-compose.yaml 中,已经填好了
|
|
80
|
+
htmlrender_connect="ws://playwright:3000"
|
|
75
81
|
```
|
|
76
82
|
|
|
77
|
-
##
|
|
83
|
+
## 部署
|
|
84
|
+
|
|
85
|
+
### (建议)使用 docker compose 进行部署
|
|
86
|
+
|
|
87
|
+
> 前提条件:你的项目使用 uv 管理 或 `pyproject.toml` 的 `dependencies` 中已经包含你的依赖
|
|
88
|
+
>
|
|
89
|
+
> 此方法会将 nonebot2 和 playwright 分开两个容器
|
|
90
|
+
|
|
91
|
+
1. 将 `docker-compose.yaml` & `entrypoint.sh` 复制到你自己的项目根目录下
|
|
92
|
+
2. 根据你的需要调整 `docker-compose.yaml` & `entrypoint.sh`
|
|
93
|
+
3. 拉取镜像 `docker compose pull`
|
|
94
|
+
4. 启动容器 `docker compose up -d`
|
|
95
|
+
|
|
96
|
+
> - 查看日志 `docker compose logs -f`
|
|
97
|
+
> - 停止/重启容器 `docker compose`
|
|
98
|
+
|
|
99
|
+
### docker 单容器部署
|
|
100
|
+
|
|
101
|
+
> 前提条件:你的项目使用 uv 管理 或 `pyproject.toml` 的 `dependencies` 中已经包含你的依赖
|
|
102
|
+
>
|
|
103
|
+
> 此方法会将 nonebot2 和 playwright 运行在同一个容器中
|
|
104
|
+
>
|
|
105
|
+
> 而且你还有需要清楚你要干什么
|
|
106
|
+
|
|
107
|
+
1. 将 `docker-compose.yaml` & `entrypoint.sh` 复制到你自己的项目根目录下
|
|
108
|
+
2. 根据你的情况,调整指令
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
docker run -d \
|
|
112
|
+
--name nonebot2 \
|
|
113
|
+
-v $(pwd):/app \
|
|
114
|
+
-p 9012:9012 \
|
|
115
|
+
-e "PLAYWRIGHT_BROWSERS_PATH=/app/pw-browsers" \
|
|
116
|
+
ghcr.io/kexue-z/nonebot-plugin-htmlrender/nonebot2-playwrght-uv sh -c "./entrypoint.sh"
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## 说明
|
|
120
|
+
### markdown 转 图片
|
|
78
121
|
|
|
79
122
|
- 使用 `GitHub-light` 样式
|
|
80
123
|
- 支持绝大部分 md 语法
|
|
@@ -85,38 +128,38 @@ htmlrender_connect_over_cdp = "http://127.0.0.1:9222"
|
|
|
85
128
|
- 图片需要使用外部连接并使用`html`格式 否则文末会超出截图范围
|
|
86
129
|
- 图片可使用 md 语法 路径可为 `绝对路径`(建议), 或 `相对于template_path` 的路径
|
|
87
130
|
|
|
88
|
-
|
|
131
|
+
### 模板 转 图片
|
|
89
132
|
|
|
90
133
|
- 使用 jinja2 模板引擎
|
|
91
134
|
- 页面参数可自定义
|
|
92
135
|
|
|
93
|
-
|
|
136
|
+
## 🌰 栗子
|
|
94
137
|
|
|
95
138
|
[example.md](docs/example.md)
|
|
96
139
|
|
|
97
|
-
|
|
140
|
+
### 文本转图片(同时文本里面可以包括 html 图片)
|
|
98
141
|
|
|
99
142
|

|
|
100
143
|
|
|
101
|
-
|
|
144
|
+
### markdown 转图片(同时文本里面可以包括 html 图片)
|
|
102
145
|
|
|
103
146
|

|
|
104
147
|
|
|
105
|
-
|
|
148
|
+
### 纯 html 转图片
|
|
106
149
|
|
|
107
150
|

|
|
108
151
|
|
|
109
|
-
|
|
152
|
+
### jinja2 模板转图片
|
|
110
153
|
|
|
111
154
|

|
|
112
155
|
|
|
113
|
-
|
|
156
|
+
## 特别感谢
|
|
114
157
|
|
|
115
158
|
- [MeetWq](https://github.com/MeetWq) 提供数学公式支持代码和代码高亮
|
|
116
159
|
|
|
117
|
-
|
|
160
|
+
## 常见疑难杂症
|
|
118
161
|
|
|
119
|
-
|
|
162
|
+
### `playwright._impl._api_types.Error:` 初次运行时报错
|
|
120
163
|
|
|
121
164
|
- 一般为缺少必要的运行环境,如中文字体等
|
|
122
165
|
|
|
@@ -135,18 +178,3 @@ LANG zh_CN.UTF-8
|
|
|
135
178
|
LANGUAGE zh_CN.UTF-8
|
|
136
179
|
LC_ALL zh_CN.UTF-8
|
|
137
180
|
```
|
|
138
|
-
|
|
139
|
-
### CentOS 使用 `yum`
|
|
140
|
-
|
|
141
|
-
- ~~小心 CentOS~~
|
|
142
|
-
-
|
|
143
|
-
参考[CentOS Dockerfile](https://github.com/kumaraditya303/playwright-centos/blob/master/Dockerfile)
|
|
144
|
-
- 添加中文字体库
|
|
145
|
-
- ~~最佳解决办法~~
|
|
146
|
-
- 使用 Docker 然后用 Python 镜像 按照上面 Ubuntu 的写 `dockerfile`
|
|
147
|
-
|
|
148
|
-
下面这个依赖运行一下 也许就可以用了
|
|
149
|
-
|
|
150
|
-
```sh
|
|
151
|
-
dnf install -y alsa-lib at-spi2-atk at-spi2-core atk cairo cups-libs dbus-libs expat flac-libs gdk-pixbuf2 glib2 glibc gtk3 libX11 libXcomposite libXdamage libXext libXfixes libXrandr libXtst libcanberra-gtk3 libdrm libgcc libstdc++ libxcb libxkbcommon libxshmfence libxslt mesa-libgbm nspr nss nss-util pango policycoreutils policycoreutils-python-utils zlib cairo-gobject centos-indexhtml dbus-glib fontconfig freetype gtk2 libXcursor libXi libXrender libXt liberation-fonts-common liberation-sans-fonts libffi mozilla-filesystem p11-kit-trust pipewire-libs harfbuzz-icu libglvnd-glx libglvnd-egl libnotify opus woff2 gstreamer1-plugins-base gstreamer1-plugins-bad-free openjpeg2 libwebp enchant libsecret hyphen libglvnd-gles
|
|
152
|
-
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
services:
|
|
2
|
+
nonebot:
|
|
3
|
+
image: ghcr.io/kexue-z/nonebot-plugin-htmlrender/nonebot2-playwrght-uv
|
|
4
|
+
env_file:
|
|
5
|
+
- .env.prod
|
|
6
|
+
ports:
|
|
7
|
+
# nonebot2 监听端口
|
|
8
|
+
- "9012:9012"
|
|
9
|
+
volumes:
|
|
10
|
+
- .:/app
|
|
11
|
+
|
|
12
|
+
# 如果使用 plugin-localstore,你应该同时挂载下面几个路径
|
|
13
|
+
# - plugin-localstore-cache:/root/.cache/nonebot2
|
|
14
|
+
# - plugin-localstore-data:/root/.local/share/nonebot2
|
|
15
|
+
# - plugin-localstore-config:/root/.config/nonebot2
|
|
16
|
+
|
|
17
|
+
# 挂载浏览器目录,持久化存储,同时修改下方环境变量
|
|
18
|
+
# - /path/to/your/host/browsers:/pw-browsers
|
|
19
|
+
|
|
20
|
+
environment:
|
|
21
|
+
- HTMLRENDER_CONNECT="ws://playwright:3000"
|
|
22
|
+
# - PLAYWRIGHT_BROWSERS_PATH=/pw-browsers
|
|
23
|
+
|
|
24
|
+
playwright:
|
|
25
|
+
image: mcr.microsoft.com/playwright:v1.52.0-noble
|
|
26
|
+
container_name: playwright
|
|
27
|
+
entrypoint: ["/bin/sh", "-c", "npx -y playwright@1.52.0 run-server --port 3000 --host 0.0.0.0"]
|
|
28
|
+
volumes:
|
|
29
|
+
# 挂载 nonebot 的文件路径,以便本地资源文件可以访问
|
|
30
|
+
- .:/app
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# 如果使用 plugin-localstore,你应该同时挂载下面几个路径
|
|
34
|
+
# volumes:
|
|
35
|
+
# plugin-localstore-cache:
|
|
36
|
+
# plugin-localstore-data:
|
|
37
|
+
# plugin-localstore-config:
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Use a Python image with uv
|
|
2
|
+
FROM docker.io/library/python:3.12-slim-bookworm
|
|
3
|
+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
|
4
|
+
|
|
5
|
+
# Setting env
|
|
6
|
+
ENV TZ=Asia/Shanghai \
|
|
7
|
+
DEBIAN_FRONTEND=noninteractive \
|
|
8
|
+
# Enable bytecode compilation
|
|
9
|
+
UV_COMPILE_BYTECODE=1 \
|
|
10
|
+
UV_LINK_MODE=copy
|
|
11
|
+
|
|
12
|
+
# use mirrors
|
|
13
|
+
# ENV UV_DEFAULT_INDEX="https://mirrors.aliyun.com/pypi/simple"
|
|
14
|
+
|
|
15
|
+
# use mirrors
|
|
16
|
+
# RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib" >> /etc/apt/sources.list\
|
|
17
|
+
# && echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib" >> /etc/apt/sources.list\
|
|
18
|
+
# && echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib" >> /etc/apt/sources.list\
|
|
19
|
+
# && echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib" >> /etc/apt/sources.list
|
|
20
|
+
|
|
21
|
+
# install nb-cli & playwright
|
|
22
|
+
RUN uv pip install --system nb-cli playwright
|
|
23
|
+
|
|
24
|
+
# install font fonts-noto-color-emoji
|
|
25
|
+
RUN apt-get update \
|
|
26
|
+
&& apt-get install -y --no-install-recommends fontconfig \
|
|
27
|
+
&& rm -rf /tmp/sarasa /tmp/sarasa.7z /var/lib/apt/lists/*
|
|
28
|
+
|
|
29
|
+
# RUN playwright install --only-shell --with-deps chromium \
|
|
30
|
+
# && rm -rf /var/lib/apt/lists/*
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# Set workdir `/app`
|
|
34
|
+
WORKDIR /app
|
|
35
|
+
|
|
36
|
+
# Clean uv entrypoint
|
|
37
|
+
ENTRYPOINT [""]
|
|
38
|
+
|
|
39
|
+
CMD ["sh","-c", "./entrypoint.sh"]
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Font installation script
|
|
4
|
+
|
|
5
|
+
set -e
|
|
6
|
+
|
|
7
|
+
# Source fonts directory
|
|
8
|
+
# FONT_SRC_DIR="/app/fonts"
|
|
9
|
+
# Destination fonts directory
|
|
10
|
+
# FONT_DEST_DIR="/usr/share/fonts"
|
|
11
|
+
|
|
12
|
+
# Supported font file extensions
|
|
13
|
+
# FONT_EXTS=("ttc" "ttf" "otf" "woff" "woff2")
|
|
14
|
+
|
|
15
|
+
# Font installation function with existence check
|
|
16
|
+
# install_fonts() {
|
|
17
|
+
# local dir="$1"
|
|
18
|
+
|
|
19
|
+
# # Find all font files
|
|
20
|
+
# while IFS= read -r -d '' file; do
|
|
21
|
+
# # Get file extension
|
|
22
|
+
# ext="${file##*.}"
|
|
23
|
+
|
|
24
|
+
# # Check if it's a supported font format
|
|
25
|
+
# if [[ " ${FONT_EXTS[@]} " =~ " ${ext,,} " ]]; then
|
|
26
|
+
# # Get relative path
|
|
27
|
+
# relative_path="${file%/*}"
|
|
28
|
+
# relative_path="${relative_path#$FONT_SRC_DIR/}"
|
|
29
|
+
|
|
30
|
+
# # Create destination directory
|
|
31
|
+
# dest_dir="$FONT_DEST_DIR/$relative_path"
|
|
32
|
+
# mkdir -p "$dest_dir"
|
|
33
|
+
|
|
34
|
+
# # Destination file path
|
|
35
|
+
# dest_file="$dest_dir/$(basename "$file")"
|
|
36
|
+
|
|
37
|
+
# # Check if file already exists
|
|
38
|
+
# if [ ! -f "$dest_file" ]; then
|
|
39
|
+
# # Copy font file
|
|
40
|
+
# echo "Installing font: $file -> $dest_dir/"
|
|
41
|
+
# install -m644 "$file" "$dest_dir/"
|
|
42
|
+
# else
|
|
43
|
+
# echo "Skipping existing font: $dest_file"
|
|
44
|
+
# fi
|
|
45
|
+
# fi
|
|
46
|
+
# done < <(find "$dir" -type f -print0)
|
|
47
|
+
# }
|
|
48
|
+
|
|
49
|
+
# Main execution
|
|
50
|
+
# if [ -d "$FONT_SRC_DIR" ]; then
|
|
51
|
+
# echo "Starting font installation..."
|
|
52
|
+
# install_fonts "$FONT_SRC_DIR"
|
|
53
|
+
|
|
54
|
+
# # Update font cache
|
|
55
|
+
# echo "Updating font cache..."
|
|
56
|
+
# fc-cache -fv
|
|
57
|
+
|
|
58
|
+
# echo "Font installation completed!"
|
|
59
|
+
# else
|
|
60
|
+
# echo "Error: Font directory $FONT_SRC_DIR does not exist, skipping installation. Note: Playwright might lack Chinese fonts"
|
|
61
|
+
# fi
|
|
62
|
+
|
|
63
|
+
# Playwright browsers
|
|
64
|
+
# echo "Install Playwright browsers..."
|
|
65
|
+
# playwright install --only-shell --with-deps chromium \
|
|
66
|
+
# && rm -rf /var/lib/apt/lists/*
|
|
67
|
+
|
|
68
|
+
# Install your project deps
|
|
69
|
+
uv sync --frozen --no-install-project --no-dev
|
|
70
|
+
|
|
71
|
+
nb run
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
../docker-compose.yaml
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
../entrypoint.sh
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "example"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "example"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.9, <4.0"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"nonebot-adapter-onebot>=2.4.6",
|
|
9
|
+
"nonebot-plugin-htmlrender>=0.6.5",
|
|
10
|
+
"nonebot2[fastapi]>=2.4.2",
|
|
11
|
+
"pillow>=11.2.1",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[tool.nonebot]
|
|
15
|
+
adapters = [
|
|
16
|
+
{ name = "OneBot V11", module_name = "nonebot.adapters.onebot.v11" },
|
|
17
|
+
]
|
|
18
|
+
plugins = [""]
|
|
19
|
+
plugin_dirs = ["plugins"]
|
|
20
|
+
builtin_plugins = ["echo"]
|
|
21
|
+
|
|
22
|
+
[[tool.uv.index]]
|
|
23
|
+
url = "https://mirrors.aliyun.com/pypi/simple"
|
|
24
|
+
default = true
|
|
@@ -173,10 +173,10 @@ async def start_browser(**kwargs) -> Browser:
|
|
|
173
173
|
kwargs["executable_path"] = plugin_config.htmlrender_browser_executable_path
|
|
174
174
|
else:
|
|
175
175
|
try:
|
|
176
|
-
await check_playwright_env()
|
|
176
|
+
await check_playwright_env(**kwargs)
|
|
177
177
|
except RuntimeError:
|
|
178
178
|
await install_browser()
|
|
179
|
-
await check_playwright_env()
|
|
179
|
+
await check_playwright_env(**kwargs)
|
|
180
180
|
|
|
181
181
|
_browser = await _launch(plugin_config.htmlrender_browser, **kwargs)
|
|
182
182
|
|
|
@@ -193,12 +193,12 @@ async def shutdown_browser() -> None:
|
|
|
193
193
|
await _playwright.stop()
|
|
194
194
|
|
|
195
195
|
|
|
196
|
-
async def check_playwright_env():
|
|
196
|
+
async def check_playwright_env(**kwargs):
|
|
197
197
|
"""Check Playwright environment."""
|
|
198
198
|
logger.info("Checking Playwright environment...")
|
|
199
199
|
try:
|
|
200
200
|
async with async_playwright() as p:
|
|
201
|
-
await getattr(p, plugin_config.htmlrender_browser).launch()
|
|
201
|
+
await getattr(p, plugin_config.htmlrender_browser).launch(**kwargs)
|
|
202
202
|
except Exception as e:
|
|
203
203
|
raise RuntimeError(
|
|
204
204
|
"Playwright environment is not set up correctly. "
|