25 lines
948 B
TypeScript
25 lines
948 B
TypeScript
import { describe, expect, it } from 'vitest'
|
|||
|
|
import { extractRichText, renderRichContent } from './rich-content'
|
||
|
|
|
||
|
|
describe('rich content helpers', () => {
|
||
|
|
it('renders markdown into html', () => {
|
||
|
|
const html = renderRichContent('# 标题\n\n- 甲\n- 乙\n\n**加粗** [链接](https://example.com)')
|
||
|
|
|
||
|
|
expect(html).toContain('<h1>标题</h1>')
|
||
|
|
expect(html).toContain('<ul>')
|
||
|
|
expect(html).toContain('<strong>加粗</strong>')
|
||
|
|
expect(html).toContain('<a href="https://example.com"')
|
||
|
|
})
|
||
|
|
|
||
|
|
it('keeps safe html and strips scripts', () => {
|
||
|
|
const html = renderRichContent('<p>hello <strong>world</strong></p><script>alert(1)</script>')
|
||
|
|
|
||
|
|
expect(html).toBe('<p>hello <strong>world</strong></p>')
|
||
|
|
})
|
||
|
|
|
||
|
|
it('extracts plain text from rich content', () => {
|
||
|
|
expect(extractRichText('<p>Hello <strong>world</strong></p>')).toBe('Hello world')
|
||
|
|
expect(extractRichText('## 标题\n\n内容')).toBe('标题 内容')
|
||
|
|
})
|
||
|
|
})
|