import { describe, expect, it } from 'vitest'; import { htmlToPlainText } from '../html-to-text'; describe('htmlToPlainText', () => { it('preserves line breaks from
within a paragraph', () => { expect(htmlToPlainText('

Line 1.
Line 2.

')).toBe('Line 1.\nLine 2.'); }); it('separates block elements with newlines instead of running them together (#421)', () => { // The previous textContent-based implementation produced "Line 1.Line 2.Paragraph 2." expect(htmlToPlainText('
Line 1.
Line 2.
Paragraph 2.
')).toBe( 'Line 1.\nLine 2.\nParagraph 2.' ); }); it('with paragraphSpacing, separates paragraphs with a blank line', () => { expect( htmlToPlainText('

Line 1.
Line 2.

Paragraph 2.

', { paragraphSpacing: true }) ).toBe('Line 1.\nLine 2.\n\nParagraph 2.'); }); it('without paragraphSpacing, separates paragraphs with a single newline', () => { expect(htmlToPlainText('

A

B

')).toBe('A\nB'); }); it('renders links as text when the text equals the href', () => { expect( htmlToPlainText('

alice@example.com

') ).toBe('alice@example.com'); }); it('renders links as "text " when they differ', () => { expect(htmlToPlainText('

Visit our site

')).toBe( 'Visit our site ' ); }); it('collapses excess whitespace and trims the result', () => { expect(htmlToPlainText('

Hello world

')).toBe('Hello world'); }); it('caps consecutive blank lines at one', () => { expect(htmlToPlainText('

A




B

', { paragraphSpacing: true })).toBe( 'A\n\nB' ); }); it('returns an empty string for empty or whitespace-only HTML', () => { expect(htmlToPlainText('')).toBe(''); expect(htmlToPlainText('

')).toBe(''); }); it('handles nested lists as separate lines', () => { expect(htmlToPlainText('')).toBe('One\nTwo'); }); });