import type { App } from 'vuepress/core' import type { CopyCodeOptions } from '../src/node/types.js' import MarkdownIt from 'markdown-it' import { describe, expect, it } from 'vitest' import { copyCodeButtonPlugin } from '../src/node/copy-code-button/index.js' function createMarkdown(options: boolean | CopyCodeOptions = {}, lang = 'en-US') { const md = new MarkdownIt() md.options.highlight = str => `
${str}
` const fence = md.renderer.rules.fence! md.renderer.rules.fence = (...args) => `
${fence(...args)}
` const app = { env: { isDebug: false }, siteData: { lang, locales: { '/': { lang }, '/zh/': { lang: 'zh-CN' }, '/en/': { lang: 'en-US' }, '/xxx/': { lang: 'unknown' } }, }, } as unknown as App copyCodeButtonPlugin(md, app, options) return md } describe('copy code button plugin', () => { it('should work with default', () => { const md = createMarkdown() expect(md.render('```js\nconst a = 1\n```', { filePathRelative: '/test.md' })).toContain('