Skip to main content

Nonebot-Plugin-EasyMarkdown

Markdown

License: MIT PyPI Python 3.8

基于fitz与xhtml2pdf的格式化markdown语法,并转化为图片发送的插件

介绍

对于大语言模型越来越广泛使用的今天,大部分人在网页复制其回答总是会带有md的正则语法。导致许多时候我们要将其粘贴至word等地方时格式会很乱,并且还要手动去除这些语法,徒增麻烦。

同样的,并不是大多数人都会使用typora等md编辑软件

因此,本项目提供了一个简易的解决方案,只需将文本发送至bot,bot便能够将文本格式化并转化成图片发送回来,同时也包括去除了md语法的纯文本内容

安装

使用nb-cli进行安装:

nb plugin install nonebot-plugin-easymarkdown

或使用pip安装:

pip install nonebot-plugin-easymarkdown

使用

@机器人+.md+空格+md文本内容

原理

使用markdown2库将md文本转化为html,再使用xhtml2pdf库将html文本转化为pdf文件,最后使用fitz库将pdf文件转化为图片

graph TD
    A[md文本] --> |markdown2库| B[html文本]
    B --> |xhtml2pdf库| C[pdf文件]
    C --> |fitz库| D[图片]

图片发送完毕会立即删除生成的图片与pdf文件,不会占用服务器空间

为了保证插件的易用性,因此不使用html2image等需要自行安装第三方工具的库,所以bot运行起来可能会稍慢

图例

output_page_1

output_page_2

output_page_3

存在的问题

由于xhtml2pdf库对于中文较少的支持,所以不支持粗体、斜体、倾斜粗体的md文本

不支持latex表达式

代码块不支持代码高亮(有,但是不会高亮)

其余大部分md文本均可较好显示

贡献

欢迎提交Pull Request或报告Issues。

许可

MIT License

Release files for nonebot-plugin-easymarkdown 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nonebot-plugin-easymarkdown 1.0.3
File Size Uploaded
nonebot_plugin_easymarkdown-1.0.3.tar.gz 9.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nonebot-plugin-easymarkdown 1.0.3
File Interpreter ABI Platform
nonebot_plugin_easymarkdown-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 21.5 kB

Release files / nonebot_plugin_easymarkdown-1.0.3.tar.gz

Download URL nonebot_plugin_easymarkdown-1.0.3.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ddc8b20cc5b62b3f07bbc5c78ea16d4009d960277c1f6bd42cc3ed1fbabc6cc8
BLAKE2b-256 checksum
How to use checksums
8fedbab1d1d23322d41cf940f1960f899f5099a3513c38b43d27c9db01025168
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.11 Windows/10

Release files / nonebot_plugin_easymarkdown-1.0.3-py3-none-any.whl

Download URL nonebot_plugin_easymarkdown-1.0.3-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f89f6aaa9f7b581a23676d5dd6e4efa9d5b3806f6897a2dda14db4d861bee8d
BLAKE2b-256 checksum
How to use checksums
87255537ba8278daeb02fdb8b3e41aa18985a2bb72997e57c37dc549d0bffeff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.11 Windows/10

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page