nonebot-plugin-htmlrender 0.5.0__tar.gz → 0.5.1__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.5.0 → nonebot_plugin_htmlrender-0.5.1}/.github/workflows/publish.yml +6 -1
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/PKG-INFO +3 -2
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/nonebot_plugin_htmlrender/browser.py +35 -35
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/pyproject.toml +29 -14
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/uv.lock +1 -1
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/.flake8 +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/.github/workflows/codecov.yml +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/.gitignore +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/.python-version +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/LICENSE +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/README.md +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/docs/example.md +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/docs/html2pic.png +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/docs/md2pic.png +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/docs/template2pic.png +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/docs/text2pic.png +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/example/.env.dev +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/example/bot.py +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/example/plugins/render/__init__.py +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/example/plugins/render/html2pic.html +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/example/plugins/render/templates/markdown.css +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/example/plugins/render/templates/mystyle.css +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/example/plugins/render/templates/progress.html.jinja2 +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/example/plugins/render/templates/text.html +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/example/plugins/render/utils.py +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/nonebot_plugin_htmlrender/__init__.py +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/nonebot_plugin_htmlrender/config.py +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/nonebot_plugin_htmlrender/data_source.py +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/nonebot_plugin_htmlrender/templates/github-markdown-light.css +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/nonebot_plugin_htmlrender/templates/katex/katex.min.b64_fonts.css +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/nonebot_plugin_htmlrender/templates/katex/katex.min.js +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/nonebot_plugin_htmlrender/templates/katex/mathtex-script-type.min.js +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/nonebot_plugin_htmlrender/templates/katex/mhchem.min.js +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/nonebot_plugin_htmlrender/templates/markdown.html +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/nonebot_plugin_htmlrender/templates/pygments-default.css +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/nonebot_plugin_htmlrender/templates/text.css +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/nonebot_plugin_htmlrender/templates/text.html +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/tests/__init__.py +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/tests/conftest.py +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/tests/templates/markdown.css +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/tests/templates/mystyle.css +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/tests/templates/progress.html.jinja2 +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/tests/templates/text.html +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/tests/test_htmlrender.py +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/tests/test_template_filter.png +0 -0
- {nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/tests/utils.py +0 -0
{nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/.github/workflows/publish.yml
RENAMED
|
@@ -43,8 +43,13 @@ jobs:
|
|
|
43
43
|
- name: Build Package
|
|
44
44
|
run: uv build
|
|
45
45
|
|
|
46
|
+
- uses: actions/upload-artifact@v4
|
|
47
|
+
with:
|
|
48
|
+
name: artifact
|
|
49
|
+
path: dist/ # or path/to/artifact
|
|
50
|
+
|
|
46
51
|
- name: pypi-publish
|
|
47
|
-
uses: pypa/gh-action-pypi-publish@v1.
|
|
52
|
+
uses: pypa/gh-action-pypi-publish@v1.12.3
|
|
48
53
|
|
|
49
54
|
# - name: Publish Package to PyPI
|
|
50
55
|
# run: uv publish
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: nonebot-plugin-htmlrender
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.1
|
|
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
|
|
@@ -26,6 +26,7 @@ License: MIT License
|
|
|
26
26
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
27
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
28
|
SOFTWARE.
|
|
29
|
+
License-File: LICENSE
|
|
29
30
|
Requires-Python: <4.0,>=3.9
|
|
30
31
|
Requires-Dist: aiofiles>=0.8.0
|
|
31
32
|
Requires-Dist: jinja2>=3.0.3
|
|
@@ -6,16 +6,17 @@ from contextlib import asynccontextmanager, contextmanager
|
|
|
6
6
|
from dataclasses import dataclass
|
|
7
7
|
from enum import Enum
|
|
8
8
|
from typing import Optional, Literal, AsyncIterator, TextIO
|
|
9
|
+
from typing_extensions import TypeGuard
|
|
9
10
|
from urllib.parse import urlparse
|
|
10
11
|
|
|
11
12
|
from nonebot.log import logger
|
|
12
|
-
from playwright.async_api import Browser, Error, Page, Playwright, async_playwright
|
|
13
|
+
from playwright.async_api import Browser, Error, Page, Playwright, async_playwright, BrowserType
|
|
13
14
|
|
|
14
15
|
from .config import plugin_config
|
|
15
16
|
|
|
16
17
|
_browser: Optional[Browser] = None
|
|
17
18
|
_playwright: Optional[Playwright] = None
|
|
18
|
-
|
|
19
|
+
AllowedBrowser = Literal["chromium", "firefox", "webkit"]
|
|
19
20
|
|
|
20
21
|
|
|
21
22
|
@contextmanager
|
|
@@ -26,6 +27,17 @@ def _suppress_and_log():
|
|
|
26
27
|
except Exception as e:
|
|
27
28
|
logger.opt(exception=e).warning("关闭 playwright 时发生错误。")
|
|
28
29
|
|
|
30
|
+
def is_allowed_browser(browser_type: str) -> TypeGuard[AllowedBrowser]:
|
|
31
|
+
"""检查浏览器类型是否有效。"""
|
|
32
|
+
return browser_type in ["chromium", "firefox", "webkit"]
|
|
33
|
+
|
|
34
|
+
async def _launch(browser_type: AllowedBrowser, **kwargs) -> Browser:
|
|
35
|
+
logger.info(f"使用 {browser_type.capitalize()} 启动中...")
|
|
36
|
+
_browser_cls: BrowserType = getattr(_playwright, browser_type)
|
|
37
|
+
_browser = await _browser_cls.launch(**kwargs)
|
|
38
|
+
logger.debug(f"{browser_type.capitalize()} 路径: {_browser_cls.executable_path}")
|
|
39
|
+
return _browser
|
|
40
|
+
|
|
29
41
|
|
|
30
42
|
async def init_browser(**kwargs) -> Browser:
|
|
31
43
|
"""初始化全局 playwright 浏览器实例并返回浏览器实例。"""
|
|
@@ -51,6 +63,8 @@ async def start_browser(**kwargs) -> Browser:
|
|
|
51
63
|
if plugin_config.htmlrender_browser
|
|
52
64
|
else "chromium"
|
|
53
65
|
)
|
|
66
|
+
if not is_allowed_browser(browser_type):
|
|
67
|
+
raise ValueError(f"不支持的浏览器类型: {browser_type}")
|
|
54
68
|
|
|
55
69
|
if plugin_config.htmlrender_browser_channel:
|
|
56
70
|
kwargs["channel"] = plugin_config.htmlrender_browser_channel
|
|
@@ -62,37 +76,24 @@ async def start_browser(**kwargs) -> Browser:
|
|
|
62
76
|
|
|
63
77
|
_playwright = await async_playwright().start()
|
|
64
78
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
case "webkit":
|
|
72
|
-
logger.info("使用 WebKit 启动中...")
|
|
73
|
-
_browser = await _playwright.webkit.launch(**kwargs)
|
|
74
|
-
logger.debug(f"WebKit 路径: {_playwright.webkit.executable_path}")
|
|
75
|
-
|
|
76
|
-
case "chromium":
|
|
77
|
-
if plugin_config.htmlrender_connect_over_cdp:
|
|
78
|
-
logger.info("使用 Chromium CDP 连接中...")
|
|
79
|
-
return await _playwright.chromium.connect_over_cdp(**kwargs)
|
|
80
|
-
|
|
81
|
-
logger.info("使用 Chromium 启动中...")
|
|
82
|
-
_browser = await _playwright.chromium.launch(**kwargs)
|
|
83
|
-
logger.debug(f"Chromium 路径: {_playwright.chromium.executable_path}")
|
|
84
|
-
|
|
85
|
-
case _:
|
|
86
|
-
raise ValueError(f"不支持的浏览器类型: {browser_type}")
|
|
79
|
+
if browser_type == "chromium" and plugin_config.htmlrender_connect_over_cdp:
|
|
80
|
+
logger.info("使用 Chromium CDP 连接中...")
|
|
81
|
+
_browser = await _playwright.chromium.connect_over_cdp(**kwargs)
|
|
82
|
+
else:
|
|
83
|
+
_browser = await _launch(browser_type)
|
|
87
84
|
|
|
88
85
|
return _browser
|
|
89
86
|
|
|
90
87
|
|
|
91
|
-
def get_browser() -> Browser:
|
|
92
|
-
""""""
|
|
93
|
-
if
|
|
94
|
-
|
|
95
|
-
|
|
88
|
+
async def get_browser(**kwargs) -> Browser:
|
|
89
|
+
"""获取 Browser 实例,不存在则初始化"""
|
|
90
|
+
if _browser and _browser.is_connected():
|
|
91
|
+
return _browser
|
|
92
|
+
|
|
93
|
+
try:
|
|
94
|
+
return await init_browser(**kwargs)
|
|
95
|
+
except Exception as e:
|
|
96
|
+
raise RuntimeError("无法初始化浏览器实例") from e
|
|
96
97
|
|
|
97
98
|
|
|
98
99
|
@asynccontextmanager
|
|
@@ -106,7 +107,7 @@ async def get_new_page(device_scale_factor: float = 2, **kwargs) -> AsyncIterato
|
|
|
106
107
|
Returns:
|
|
107
108
|
AsyncIterator[Page]: 页面对象。
|
|
108
109
|
"""
|
|
109
|
-
ctx = get_browser()
|
|
110
|
+
ctx = await get_browser()
|
|
110
111
|
page = await ctx.new_page(device_scale_factor=device_scale_factor, **kwargs)
|
|
111
112
|
try:
|
|
112
113
|
yield page
|
|
@@ -263,14 +264,13 @@ async def read_stream(stream, out: TextIO = sys.stdout) -> None:
|
|
|
263
264
|
|
|
264
265
|
msg_type = get_message_type(text)
|
|
265
266
|
|
|
266
|
-
|
|
267
|
-
case MessageType.PROGRESS:
|
|
267
|
+
if msg_type is MessageType.PROGRESS:
|
|
268
268
|
progress_text = text.split("|", 1)[1].strip()
|
|
269
269
|
write_progress(progress_text)
|
|
270
270
|
last_progress = text
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
271
|
+
else:
|
|
272
|
+
ensure_newline()
|
|
273
|
+
logger.info(text)
|
|
274
274
|
|
|
275
275
|
|
|
276
276
|
async def execute_install_command(
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "nonebot-plugin-htmlrender"
|
|
3
|
-
version = "0.5.
|
|
3
|
+
version = "0.5.1"
|
|
4
4
|
description = "通过浏览器渲染图片"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [{ name = "kexue", email = "x@kexue-cloud.cn" }]
|
|
7
7
|
requires-python = ">=3.9,<4.0"
|
|
8
8
|
license = { file = "LICENSE" }
|
|
9
9
|
dependencies = [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
"aiofiles>=0.8.0",
|
|
11
|
+
"jinja2>=3.0.3",
|
|
12
|
+
"markdown>=3.3.6",
|
|
13
|
+
"nonebot2>=2.2.0",
|
|
14
|
+
"playwright>=1.48.0",
|
|
15
|
+
"pygments>=2.10.0",
|
|
16
|
+
"pymdown-extensions>=9.1",
|
|
17
|
+
"python-markdown-math>=0.8",
|
|
18
18
|
]
|
|
19
19
|
|
|
20
20
|
[project.urls]
|
|
@@ -28,13 +28,28 @@ asyncio_mode = "auto"
|
|
|
28
28
|
|
|
29
29
|
[dependency-groups]
|
|
30
30
|
dev = [
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
"nonebot-adapter-onebot>=2.4.6",
|
|
32
|
+
"nonebot2[fastapi]>=2.3.3",
|
|
33
|
+
"nonebug>=0.4.2",
|
|
34
|
+
"pillow>=11.0.0",
|
|
35
|
+
"pytest-asyncio>=0.24.0",
|
|
36
36
|
]
|
|
37
37
|
|
|
38
|
+
[tool.pyright]
|
|
39
|
+
pythonVersion = "3.9"
|
|
40
|
+
pythonPlatform = "All"
|
|
41
|
+
defineConstant = { PYDANTIC_V2 = true }
|
|
42
|
+
executionEnvironments = [
|
|
43
|
+
{ root = "./tests", extraPaths = [
|
|
44
|
+
"./",
|
|
45
|
+
] },
|
|
46
|
+
{ root = "./" },
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
typeCheckingMode = "standard"
|
|
50
|
+
reportShadowedImports = false
|
|
51
|
+
disableBytesTypePromotions = true
|
|
52
|
+
|
|
38
53
|
[build-system]
|
|
39
54
|
requires = ["hatchling"]
|
|
40
55
|
build-backend = "hatchling.build"
|
|
File without changes
|
{nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/.github/workflows/codecov.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/example/plugins/render/utils.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/tests/templates/markdown.css
RENAMED
|
File without changes
|
{nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/tests/templates/mystyle.css
RENAMED
|
File without changes
|
|
File without changes
|
{nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/tests/templates/text.html
RENAMED
|
File without changes
|
{nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/tests/test_htmlrender.py
RENAMED
|
File without changes
|
{nonebot_plugin_htmlrender-0.5.0 → nonebot_plugin_htmlrender-0.5.1}/tests/test_template_filter.png
RENAMED
|
File without changes
|
|
File without changes
|