koishi-plugin-html-renderer
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

koishi-plugin-html-renderer

npm

使用EJS和playwright实现的Koishi平台原生HTML渲染插件

✨ 功能

  • 通过 playwright 截图功能生成 HTML 渲染图片
  • 支持 ejs 模板
  • TODO: 支持 markdown 纯文本
  • TODO: 支持 CSS 控制样式

使用

import { Context, Schema, h } from 'koishi'
import {} from 'koishi-plugin-html-renderer'

export const name = 'html-renderer-test'

export interface Config {}

export const Config: Schema<Config> = Schema.object({})

export const inject = ['html_renderer']

export async function apply(ctx: Context) {
  // write your plugin here
  ctx.on('message', async (session) => {
    if (session.content == 'test') {
      const buffer = await ctx.html_renderer.render_html(__dirname.replaceAll('\\', '/') + '/templates', 'test.ejs', {
        'qid': 114514,
        'username': '田所浩二',
        'days': '12',
        'xp': '114514',
        'increment': '+1',
        'rank': 1,
        'hitokoto': '逸一时误一世',
        'background': 'bg_0.png',
      },
      {
          'viewport': {'width': 600, 'height': 332},
          'base_url': 'file://' + __dirname.replaceAll('\\', '/') + '/templates',
      }
      )
      await session.send(h.image(buffer, 'image/png'))
    }
  })
}

Package Sidebar

Install

npm i koishi-plugin-html-renderer

Weekly Downloads

29

Version

1.0.0

License

MIT

Unpacked Size

18.6 kB

Total Files

6

Last publish

Collaborators

  • white-paper-233