import { cleanMarkdownNbsp } from './cleanMarkdownNbsp'; describe('cleanMarkdownNbsp', () => { it('should return unchanged text if no   is present', () => { const input = '# Heading\n\nSome paragraph\n\n- [ ] Todo item'; expect(cleanMarkdownNbsp(input)).toBe(input); }); it('should clean standalone   lines between paragraphs and items', () => { const input = [ 'jjjj', '', ' ', '', 'jjj', '', '![Freehand Drawing.svg](joplin-content://resource/123.svg)', '', ' ', '', '- [x] 2026/11/01 16:24', ].join('\n'); const expected = [ 'jjjj', '', 'jjj', '', '![Freehand Drawing.svg](joplin-content://resource/123.svg)', '', '- [x] 2026/11/01 16:24', ].join('\n'); expect(cleanMarkdownNbsp(input)).toBe(expected); }); it('should clean multiple contiguous or spaced   entities and variants ( ,  )', () => { const input = [ 'Section 1', '  ', 'Section 2', '     ', 'Section 3', ' ', 'Section 4', ' ', 'Section 5', ].join('\n'); const expected = [ 'Section 1', '', 'Section 2', '', 'Section 3', '', 'Section 4', '', 'Section 5', ].join('\n'); expect(cleanMarkdownNbsp(input)).toBe(expected); }); it('should preserve inline   inside text and table cells', () => { const text = 'Hello world with inline nonbreaking space.'; expect(cleanMarkdownNbsp(text)).toBe(text); const table = '| Header 1 | Header 2 |\n| --- | --- |\n|   | Value |'; expect(cleanMarkdownNbsp(table)).toBe(table); }); it('should preserve inline backtick code spans like ` `', () => { const text = 'Use ` ` for non-breaking space in HTML.'; expect(cleanMarkdownNbsp(text)).toBe(text); }); it('should preserve   inside fenced code blocks', () => { const codeBlock = [ '```html', ' ', '
 
', '```', ].join('\n'); expect(cleanMarkdownNbsp(codeBlock)).toBe(codeBlock); const tildeCodeBlock = [ '~~~html', ' ', '~~~', ].join('\n'); expect(cleanMarkdownNbsp(tildeCodeBlock)).toBe(tildeCodeBlock); }); it('should handle consecutive   lines cleanly', () => { const input = 'Paragraph 1\n\n \n\n \n\nParagraph 2'; const expected = 'Paragraph 1\n\nParagraph 2'; expect(cleanMarkdownNbsp(input)).toBe(expected); }); it('should support Windows CRLF line endings', () => { const input = 'Line 1\r\n\r\n \r\n\r\nLine 2'; const expected = 'Line 1\r\n\r\nLine 2'; expect(cleanMarkdownNbsp(input)).toBe(expected); }); });