✨ feat(vscode): 注释里的仓库图片按比例显示
This commit is contained in:
1 parent
57b2f2a115
commit
9faf9cde9e
13 files changed
+312
-8
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { renderMarkdown, renderMarkdownDiff } from './markdown'
|
||||
import { repoImageInner } from './repoImage'
|
||||
|
||||
describe('renderMarkdown', () => {
|
||||
it('一行文字是一个段落;段内换行是软换行,空行分段', () => {
|
||||
@@ -42,6 +43,32 @@ describe('renderMarkdown', () => {
|
||||
expect(renderMarkdown('')).not.toContain('<img')
|
||||
})
|
||||
|
||||
it('合法仓库图片路径会变成图片;问到之前只是路径', () => {
|
||||
const path = 'frontend/src/components/overview/screenshots/OverviewSection.png'
|
||||
const html = renderMarkdown(``)
|
||||
expect(html).toContain(`data-path="${path}"`)
|
||||
expect(html).toContain(`>${path}<`)
|
||||
expect(html).not.toContain('<img')
|
||||
const src = 'https://file+.vscode-resource.vscode-cdn.net/OverviewSection.png'
|
||||
const shown = repoImageInner(path, '概览卡片', { src })
|
||||
expect(shown).toBe(`<a href="${path}"><img src="${src}" alt="概览卡片"></a>`)
|
||||
})
|
||||
|
||||
it('http、..、./ 的图片不渲染', () => {
|
||||
expect(renderMarkdown('')).not.toContain('<img')
|
||||
expect(renderMarkdown('')).not.toContain('cr-repo-image')
|
||||
expect(renderMarkdown('')).not.toContain('<img')
|
||||
expect(renderMarkdown('')).not.toContain('cr-repo-image')
|
||||
expect(renderMarkdown('')).not.toContain('<img')
|
||||
expect(renderMarkdown('')).not.toContain('cr-repo-image')
|
||||
})
|
||||
|
||||
it('文件不存在时是「找不到图片」加路径,不是图片', () => {
|
||||
const shown = repoImageInner('frontend/missing.png', '图', 'missing')
|
||||
expect(shown).toBe('找不到图片 frontend/missing.png')
|
||||
expect(shown).not.toContain('<img')
|
||||
})
|
||||
|
||||
it('仓库路径链接能点,带类名或类名.成员也一样', () => {
|
||||
expect(renderMarkdown('[智能体定义](vendor/agents)')).toBe('<p><a href="vendor/agents">智能体定义</a></p>\n')
|
||||
expect(renderMarkdown('[智能体表](backend/src/luffy_agent/agent/models.py#Agent)')).toBe('<p><a href="backend/src/luffy_agent/agent/models.py#Agent">智能体表</a></p>\n')
|
||||
|
||||
Reference in new issue
Block a user