mirror of
https://github.com/iflytek/skillhub.git
synced 2026-10-09 03:17:52 +00:00
fix(web): avoid stretching markdown badge images
This commit is contained in:
parent
012ed35a10
commit
5f8a411852
2 changed files with 15 additions and 1 deletions
12
web/src/features/skill/markdown-renderer.test.tsx
Normal file
12
web/src/features/skill/markdown-renderer.test.tsx
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { describe, expect, it } from 'vitest'
|
||||
import { MARKDOWN_IMAGE_CLASS_NAME } from './markdown-renderer'
|
||||
|
||||
describe('MARKDOWN_IMAGE_CLASS_NAME', () => {
|
||||
it('keeps markdown images at their intrinsic width while remaining responsive', () => {
|
||||
const classNames = MARKDOWN_IMAGE_CLASS_NAME.split(' ')
|
||||
|
||||
expect(classNames).toContain('h-auto')
|
||||
expect(classNames).toContain('max-w-full')
|
||||
expect(classNames).not.toContain('w-full')
|
||||
})
|
||||
})
|
||||
|
|
@ -6,6 +6,8 @@ import { cn } from '@/shared/lib/utils'
|
|||
import { remarkInferCodeLanguage } from './code-language'
|
||||
import { stripMarkdownFrontmatter } from './markdown-frontmatter'
|
||||
|
||||
export const MARKDOWN_IMAGE_CLASS_NAME = 'h-auto max-w-full'
|
||||
|
||||
interface MarkdownRendererProps {
|
||||
content: string
|
||||
className?: string
|
||||
|
|
@ -181,7 +183,7 @@ export function MarkdownRenderer({ content, className }: MarkdownRendererProps)
|
|||
</td>
|
||||
),
|
||||
img: ({ className: imageClassName, alt, ...props }) => (
|
||||
<img className={cn('w-full', imageClassName)} alt={alt ?? ''} {...props} />
|
||||
<img className={cn(MARKDOWN_IMAGE_CLASS_NAME, imageClassName)} alt={alt ?? ''} {...props} />
|
||||
),
|
||||
}}
|
||||
>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue