Spaces:
Sleeping
Sleeping
File size: 1,837 Bytes
b6ecafa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | import { describe, it, expect } from 'vitest'
// Reproduce the stripHtml logic from markdown-renderer to test it in isolation
function stripHtml(content: string): string {
return content.replace(/<[^>]*>/g, '')
}
describe('stripHtml', () => {
it('removes simple HTML tags', () => {
expect(stripHtml('<p>Hello</p>')).toBe('Hello')
})
it('removes self-closing tags', () => {
expect(stripHtml('Before <br/> After')).toBe('Before After')
})
it('removes img tags from GitHub pastes', () => {
const input = 'Description with <img src="https://example.com/screenshot.png" alt="screenshot"> embedded image'
expect(stripHtml(input)).toBe('Description with embedded image')
})
it('removes nested HTML tags', () => {
expect(stripHtml('<div><strong>Bold</strong> text</div>')).toBe('Bold text')
})
it('preserves plain text without tags', () => {
expect(stripHtml('No tags here, just **markdown**')).toBe('No tags here, just **markdown**')
})
it('handles empty string', () => {
expect(stripHtml('')).toBe('')
})
it('removes multiple img tags', () => {
const input = '<img src="a.png"><img src="b.png">text<img src="c.png">'
expect(stripHtml(input)).toBe('text')
})
it('removes HTML comments', () => {
expect(stripHtml('Before <!-- comment --> After')).toBe('Before After')
})
it('handles tags with attributes and whitespace', () => {
const input = '<a href="https://example.com" target="_blank" >Link text</a>'
expect(stripHtml(input)).toBe('Link text')
})
it('preserves angle brackets that are not HTML tags', () => {
// This is a limitation — mathematical expressions like "x < 5" would be affected
// But for our use case (stripping pasted HTML), this is acceptable
expect(stripHtml('5 > 3 is true')).toBe('5 > 3 is true')
})
})
|