import { markdownToLines, markdownToHTML } from './handle-markdown-text.js'; import { test, expect } from 'vitest'; test('markdownToLines - Basic test', () => { const input = `This is regular text Here is a new line There is some words **with a bold** section Here is a line *with an italic* section`; const expectedOutput = [ [ { content: 'This', type: 'normal' }, { content: 'is', type: 'normal' }, { content: 'regular', type: 'normal' }, { content: 'text', type: 'normal' }, ], [ { content: 'Here', type: 'normal' }, { content: 'is', type: 'normal' }, { content: 'a', type: 'normal' }, { content: 'new', type: 'normal' }, { content: 'line', type: 'normal' }, ], [ { content: 'There', type: 'normal' }, { content: 'is', type: 'normal' }, { content: 'some', type: 'normal' }, { content: 'words', type: 'normal' }, { content: 'with', type: 'strong' }, { content: 'a', type: 'strong' }, { content: 'bold', type: 'strong' }, { content: 'section', type: 'normal' }, ], [ { content: 'Here', type: 'normal' }, { content: 'is', type: 'normal' }, { content: 'a', type: 'normal' }, { content: 'line', type: 'normal' }, { content: 'with', type: 'em' }, { content: 'an', type: 'em' }, { content: 'italic', type: 'em' }, { content: 'section', type: 'normal' }, ], ]; const output = markdownToLines(input); expect(output).toEqual(expectedOutput); }); test('markdownToLines - Empty input', () => { const input = ''; const expectedOutput = [[]]; const output = markdownToLines(input); expect(output).toEqual(expectedOutput); }); test('markdownToLines - No formatting', () => { const input = `This is a simple test with no formatting`; const expectedOutput = [ [ { content: 'This', type: 'normal' }, { content: 'is', type: 'normal' }, { content: 'a', type: 'normal' }, { content: 'simple', type: 'normal' }, { content: 'test', type: 'normal' }, ], [ { content: 'with', type: 'normal' }, { content: 'no', type: 'normal' }, { content: 'formatting', type: 'normal' }, ], ]; const output = markdownToLines(input); expect(output).toEqual(expectedOutput); }); test('markdownToLines - Only bold formatting', () => { const input = `This is a **bold** test`; const expectedOutput = [ [ { content: 'This', type: 'normal' }, { content: 'is', type: 'normal' }, { content: 'a', type: 'normal' }, { content: 'bold', type: 'strong' }, { content: 'test', type: 'normal' }, ], ]; const output = markdownToLines(input); expect(output).toEqual(expectedOutput); }); test('markdownToLines - paragraph 1', () => { const input = `**Start** with a second line`; const expectedOutput = [ [ { content: 'Start', type: 'strong' }, { content: 'with', type: 'normal' }, ], [ { content: 'a', type: 'normal' }, { content: 'second', type: 'normal' }, { content: 'line', type: 'normal' }, ], ]; const output = markdownToLines(input); expect(output).toEqual(expectedOutput); }); test('markdownToLines - paragraph', () => { const input = `**Start** with a second line`; const expectedOutput = [ [ { content: 'Start', type: 'strong' }, { content: 'with', type: 'normal' }, ], [ { content: 'a', type: 'normal' }, { content: 'second', type: 'normal' }, { content: 'line', type: 'normal' }, ], ]; const output = markdownToLines(input); expect(output).toEqual(expectedOutput); }); test('markdownToLines - Only italic formatting', () => { const input = `This is an *italic* test`; const expectedOutput = [ [ { content: 'This', type: 'normal' }, { content: 'is', type: 'normal' }, { content: 'an', type: 'normal' }, { content: 'italic', type: 'em' }, { content: 'test', type: 'normal' }, ], ]; const output = markdownToLines(input); expect(output).toEqual(expectedOutput); }); it('markdownToLines - Mixed formatting', () => { let input = `*Italic* and **bold** formatting`; let expected = [ [ { content: 'Italic', type: 'em' }, { content: 'and', type: 'normal' }, { content: 'bold', type: 'strong' }, { content: 'formatting', type: 'normal' }, ], ]; expect(markdownToLines(input)).toEqual(expected); input = `*Italic with space* and **bold ws** formatting`; expected = [ [ { content: 'Italic', type: 'em' }, { content: 'with', type: 'em' }, { content: 'space', type: 'em' }, { content: 'and', type: 'normal' }, { content: 'bold', type: 'strong' }, { content: 'ws', type: 'strong' }, { content: 'formatting', type: 'normal' }, ], ]; expect(markdownToLines(input)).toEqual(expected); }); it('markdownToLines - Mixed formatting', () => { const input = `The dog in **the** hog... a *very long text* about it Word!`; const expectedOutput = [ [ { content: 'The', type: 'normal' }, { content: 'dog', type: 'normal' }, { content: 'in', type: 'normal' }, { content: 'the', type: 'strong' }, { content: 'hog...', type: 'normal' }, { content: 'a', type: 'normal' }, { content: 'very', type: 'em' }, { content: 'long', type: 'em' }, { content: 'text', type: 'em' }, { content: 'about', type: 'normal' }, { content: 'it', type: 'normal' }, ], [{ content: 'Word!', type: 'normal' }], ]; const output = markdownToLines(input); expect(output).toEqual(expectedOutput); }); test('markdownToLines - No auto wrapping', () => { expect( markdownToLines( `Hello, how do you do?`, { markdownAutoWrap: false } ) ).toMatchInlineSnapshot(` [ [ { "content": "Hello, how do", "type": "normal", }, ], [ { "content": "you do?", "type": "normal", }, ], ] `); }); test('markdownToHTML - Basic test', () => { const input = `This is regular text Here is a new line There is some words **with a bold** section Here is a line *with an italic* section`; const expectedOutput = `
This is regular text
Here is a new line
There is some words with a bold section
Here is a line with an italic section
This is a simple test
with no formatting
This is a bold test
`; const output = markdownToHTML(input); expect(output).toEqual(expectedOutput); }); test('markdownToHTML - Only italic formatting', () => { const input = `This is an *italic* test`; const expectedOutput = `This is an italic test
`; const output = markdownToHTML(input); expect(output).toEqual(expectedOutput); }); test('markdownToHTML - Mixed formatting', () => { const input = `*Italic* and **bold** formatting`; const expectedOutput = `Italic and bold formatting
`; const output = markdownToHTML(input); expect(output).toEqual(expectedOutput); }); test('markdownToHTML - Unsupported formatting', () => { expect( markdownToHTML(`Hello - l1 - l2 - l3`) ).toMatchInlineSnapshot('"Hello
Unsupported markdown: list"'); }); test('markdownToHTML - no auto wrapping', () => { expect( markdownToHTML( `Hello, how do you do?`, { markdownAutoWrap: false } ) ).toMatchInlineSnapshot('"Hello, how do
you do?
Hello, how do
you do?