nonebot-plugin-htmlrender 0.3.3__py3-none-any.whl → 0.3.5__py3-none-any.whl
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/data_source.py +16 -0
- {nonebot_plugin_htmlrender-0.3.3.dist-info → nonebot_plugin_htmlrender-0.3.5.dist-info}/METADATA +1 -1
- {nonebot_plugin_htmlrender-0.3.3.dist-info → nonebot_plugin_htmlrender-0.3.5.dist-info}/RECORD +5 -5
- {nonebot_plugin_htmlrender-0.3.3.dist-info → nonebot_plugin_htmlrender-0.3.5.dist-info}/WHEEL +1 -1
- {nonebot_plugin_htmlrender-0.3.3.dist-info → nonebot_plugin_htmlrender-0.3.5.dist-info}/licenses/LICENSE +0 -0
|
@@ -144,6 +144,7 @@ async def read_tpl(path: str) -> str:
|
|
|
144
144
|
async def template_to_html(
|
|
145
145
|
template_path: str,
|
|
146
146
|
template_name: str,
|
|
147
|
+
filters: Optional[Dict[str, Any]] = None,
|
|
147
148
|
**kwargs,
|
|
148
149
|
) -> str:
|
|
149
150
|
"""使用jinja2模板引擎通过html生成图片
|
|
@@ -151,6 +152,7 @@ async def template_to_html(
|
|
|
151
152
|
Args:
|
|
152
153
|
template_path (str): 模板路径
|
|
153
154
|
template_name (str): 模板名
|
|
155
|
+
filters (Optional[Dict[str, Any]]): 自定义过滤器
|
|
154
156
|
**kwargs: 模板内容
|
|
155
157
|
Returns:
|
|
156
158
|
str: html
|
|
@@ -160,6 +162,12 @@ async def template_to_html(
|
|
|
160
162
|
loader=jinja2.FileSystemLoader(template_path),
|
|
161
163
|
enable_async=True,
|
|
162
164
|
)
|
|
165
|
+
|
|
166
|
+
if filters:
|
|
167
|
+
for filter_name, filter_func in filters.items():
|
|
168
|
+
template_env.filters[filter_name] = filter_func
|
|
169
|
+
logger.debug(f"加载自定义过滤器 {filter_name}")
|
|
170
|
+
|
|
163
171
|
template = template_env.get_template(template_name)
|
|
164
172
|
|
|
165
173
|
return await template.render_async(**kwargs)
|
|
@@ -207,6 +215,7 @@ async def template_to_pic(
|
|
|
207
215
|
template_path: str,
|
|
208
216
|
template_name: str,
|
|
209
217
|
templates: Dict[Any, Any],
|
|
218
|
+
filters: Optional[Dict[str, Any]] = None,
|
|
210
219
|
pages: Optional[Dict[Any, Any]] = None,
|
|
211
220
|
wait: int = 0,
|
|
212
221
|
type: Literal["jpeg", "png"] = "png", # noqa: A002
|
|
@@ -219,6 +228,7 @@ async def template_to_pic(
|
|
|
219
228
|
template_path (str): 模板路径
|
|
220
229
|
template_name (str): 模板名
|
|
221
230
|
templates (Dict[Any, Any]): 模板内参数 如: {"name": "abc"}
|
|
231
|
+
filters (Optional[Dict[str, Any]]): 自定义过滤器
|
|
222
232
|
pages (Optional[Dict[Any, Any]]): 网页参数 Defaults to
|
|
223
233
|
{"base_url": f"file://{getcwd()}", "viewport": {"width": 500, "height": 10}}
|
|
224
234
|
wait (int, optional): 网页载入等待时间. Defaults to 0.
|
|
@@ -238,6 +248,12 @@ async def template_to_pic(
|
|
|
238
248
|
loader=jinja2.FileSystemLoader(template_path),
|
|
239
249
|
enable_async=True,
|
|
240
250
|
)
|
|
251
|
+
|
|
252
|
+
if filters:
|
|
253
|
+
for filter_name, filter_func in filters.items():
|
|
254
|
+
template_env.filters[filter_name] = filter_func
|
|
255
|
+
logger.debug(f"加载自定义过滤器 {filter_name}")
|
|
256
|
+
|
|
241
257
|
template = template_env.get_template(template_name)
|
|
242
258
|
|
|
243
259
|
return await html_to_pic(
|
{nonebot_plugin_htmlrender-0.3.3.dist-info → nonebot_plugin_htmlrender-0.3.5.dist-info}/RECORD
RENAMED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
nonebot_plugin_htmlrender-0.3.
|
|
2
|
-
nonebot_plugin_htmlrender-0.3.
|
|
3
|
-
nonebot_plugin_htmlrender-0.3.
|
|
1
|
+
nonebot_plugin_htmlrender-0.3.5.dist-info/METADATA,sha256=I-ymdXT1rLAGXQkIt7HIiChwZgp4rFUaV_1XdTzDIQk,5987
|
|
2
|
+
nonebot_plugin_htmlrender-0.3.5.dist-info/WHEEL,sha256=rSwsxJWe3vzyR5HCwjWXQruDgschpei4h_giTm0dJVE,90
|
|
3
|
+
nonebot_plugin_htmlrender-0.3.5.dist-info/licenses/LICENSE,sha256=4HHgpu3ihnBZ9AVZDgOzGnAJRt8W7IQo5VSBEJKRr5g,1062
|
|
4
4
|
nonebot_plugin_htmlrender/__init__.py,sha256=JBxs90TaroVrq5EFo0Yib5_c7OmBCeUqOyQuJvFiXrU,1349
|
|
5
5
|
nonebot_plugin_htmlrender/browser.py,sha256=0AfOO7P3JVv14qkaN8iyvQmpRnIdr4Slu1-SYVGjKpc,3335
|
|
6
6
|
nonebot_plugin_htmlrender/config.py,sha256=M3JLglX0yzo7slebS4w3riciEsqmfruzrQ9sPFz1yzM,357
|
|
7
|
-
nonebot_plugin_htmlrender/data_source.py,sha256=
|
|
7
|
+
nonebot_plugin_htmlrender/data_source.py,sha256=Fy4VEEINXnqNwyfhFb1-iZvAYpVHSEil3R_O9JQV7fo,9233
|
|
8
8
|
nonebot_plugin_htmlrender/templates/github-markdown-light.css,sha256=bWV9QiirgHYgauZBcR9YJ3IvEoA3fP2Cf5aOdshBVrI,17297
|
|
9
9
|
nonebot_plugin_htmlrender/templates/katex/katex.min.b64_fonts.css,sha256=8KXk7iVhFZ-h2LuWlhI6Eq2za2vuDW-n4MrHQJ2eRAU,1458204
|
|
10
10
|
nonebot_plugin_htmlrender/templates/katex/katex.min.js,sha256=cXQ4tsltOzinSxpNqnPldAdfpstIPXBDKihVb7ccZL0,270288
|
|
@@ -13,4 +13,4 @@ nonebot_plugin_htmlrender/templates/markdown.html,sha256=y-_F5YMVLHceU9nuuEAtw2t
|
|
|
13
13
|
nonebot_plugin_htmlrender/templates/pygments-default.css,sha256=lwkE40qSsvPe52nGAZW1luJ7qNeIWpgw7vDX-MZpCDA,4889
|
|
14
14
|
nonebot_plugin_htmlrender/templates/text.css,sha256=zhb6Yd3zndvojU4-qQR46dRg9CsCRvmyWU1-Uhm-2LQ,117
|
|
15
15
|
nonebot_plugin_htmlrender/templates/text.html,sha256=QhoOXE1111YNfxu_b6OYhgm4ygFpIvW0VI6VwYo4Fig,220
|
|
16
|
-
nonebot_plugin_htmlrender-0.3.
|
|
16
|
+
nonebot_plugin_htmlrender-0.3.5.dist-info/RECORD,,
|
|
File without changes
|