npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@v5md/plugin-export

v0.0.8

Published

v5md 导出插件:Markdown / HTML / PDF / 图片

Readme

@v5md/plugin-export

v5md 的导出插件:Markdown、HTML、PDF 和图片。没有工具条按钮,全部通过外部 API 调用。

安装

npm install @v5md/plugin-export

使用

import { createExportPlugin, type ExportApi } from '@v5md/plugin-export'

const editor = new Editor({
  element,
  plugins: [createExportPlugin({ title: '我的文章', locale: 'zh-CN' })],
})

// locale: 'zh-CN' | 'en' — 未传 title 时影响默认文档标题

const exporter = editor.getPlugin<ExportApi>('export')!

const markdown = exporter.api.exportMarkdown()
const html = await exporter.api.exportHtml()
const png = await exporter.api.exportImage({ type: 'png', scale: 2 })
const pdf = await exporter.api.exportPdf({ format: 'a4', margin: 24 })

也可以直接下载:

exporter.api.downloadMarkdown('article.md')
await exporter.api.downloadHtml('article.html')
await exporter.api.downloadImage('article.png')
await exporter.api.downloadPdf('article.pdf')
await exporter.api.print()

API

| 方法 | 说明 | | --- | --- | | exportMarkdown() | 返回 Markdown | | exportHtmlFragment() | 返回带内联样式的 HTML 片段 | | exportHtml() | 返回完整 HTML 文档,图片会尽量内联为 data URL | | exportImage(options?) | 返回 PNG / JPEG Blob | | exportPdf(options?) | 返回 PDF Blob | | print() | 打开浏览器打印对话框,可选择「另存为 PDF」 | | downloadMarkdown(fileName?) | 下载 Markdown | | downloadHtml(fileName?) | 下载 HTML | | downloadImage(fileName?, options?) | 下载图片 | | downloadPdf(fileName?, options?) | 下载 PDF |

exportHtml() 会导出当前编辑器已经渲染好的内容,因此公式保留 KaTeX 排版、Mermaid 保留渲染后的 SVG,而不是退回源码代码块;ECharts 等 canvas 图表会先快照成图片再写入 HTML;图片会先用 fetch 转成 data URL,遇到跨域图片时回退为绝对 URL。exportHtml() 和 downloadHtml() 都是异步的。exportHtmlFragment() 仍然输出适合公众号粘贴的内联样式片段。

PDF 和图片默认使用 html2canvas + jspdf,这两个依赖在插件包内部按需动态加载。PDF 会按块边界切片分页,尽量避免从列表项、图表、表格中间切开。也可以选择浏览器打印路径:print() 会打开打印对话框,由用户在浏览器里选择「另存为 PDF」(矢量文字、系统中文字体)。需要自定义实现时,通过 renderer 替换:

createExportPlugin({
  renderer: {
    image: async (element, options) => myImageRenderer(element, options),
    pdf: async (element, options) => myPdfRenderer(element, options),
  },
})

downloadPdf() 当前是图片式 PDF(保证中文与图表不丢字);需要可选中文字时请用 print(),或通过自定义 renderer.pdf 接入其他方案。