diff --git a/apps/server/src/collaboration/collaboration.util.spec.ts b/apps/server/src/collaboration/collaboration.util.spec.ts deleted file mode 100644 index 7115e7c10..000000000 --- a/apps/server/src/collaboration/collaboration.util.spec.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { jsonToMarkdown } from './collaboration.util'; - -const cell = (type: 'tableHeader' | 'tableCell', text: string) => ({ - type, - content: [ - { - type: 'paragraph', - content: text ? [{ type: 'text', text }] : [], - }, - ], -}); - -const row = (type: 'tableHeader' | 'tableCell', texts: string[]) => ({ - type: 'tableRow', - content: texts.map((text) => cell(type, text)), -}); - -const tableDoc = (rows: ReturnType[]) => ({ - type: 'doc', - content: [{ type: 'table', content: rows }], -}); - -describe('jsonToMarkdown', () => { - it('uses the table header row as the markdown header', () => { - const markdown = jsonToMarkdown( - tableDoc([ - row('tableHeader', ['Name', 'Role']), - row('tableCell', ['Ada', 'Engineer']), - ]), - ); - - expect(markdown.trim().split('\n')).toEqual([ - '| Name | Role |', - '| --- | --- |', - '| Ada | Engineer |', - ]); - }); - - it('adds an empty header when the table has no header row', () => { - const markdown = jsonToMarkdown( - tableDoc([ - row('tableCell', ['Ada', 'Engineer']), - row('tableCell', ['Alan', 'Mathematician']), - ]), - ); - - expect(markdown.trim().split('\n')).toEqual([ - '| | |', - '| --- | --- |', - '| Ada | Engineer |', - '| Alan | Mathematician |', - ]); - }); -}); diff --git a/apps/server/src/integrations/export/html-to-markdown.spec.ts b/apps/server/src/integrations/export/html-to-markdown.spec.ts new file mode 100644 index 000000000..8e4e43d04 --- /dev/null +++ b/apps/server/src/integrations/export/html-to-markdown.spec.ts @@ -0,0 +1,54 @@ +import { htmlToMarkdown } from '@docmost/editor-ext'; + +const colgroup = + ''; + +describe('htmlToMarkdown', () => { + it('uses the table header row as the markdown header', () => { + const markdown = htmlToMarkdown( + `${colgroup}` + + '' + + '' + + '

Name

Role

Ada

Engineer

', + ); + + expect(markdown.trim().split('\n')).toEqual([ + '| Name | Role |', + '| --- | --- |', + '| Ada | Engineer |', + ]); + }); + + it('adds an empty header when the table has no header row', () => { + const markdown = htmlToMarkdown( + `${colgroup}` + + '' + + '' + + '

Ada

Engineer

Alan

Mathematician

', + ); + + expect(markdown.trim().split('\n')).toEqual([ + '| | |', + '| --- | --- |', + '| Ada | Engineer |', + '| Alan | Mathematician |', + ]); + }); + + it('marks details blocks so their content is parsed as markdown', () => { + const markdown = htmlToMarkdown( + '
Title' + + '

Some bold

' + + '
', + ); + + expect(markdown.trim().split('\n')).toEqual([ + '
', + 'Title', + '', + 'Some **bold**', + '', + '
', + ]); + }); +}); diff --git a/packages/editor-ext/src/lib/markdown/utils/turndown.utils.ts b/packages/editor-ext/src/lib/markdown/utils/turndown.utils.ts index 8316c1bf3..3914d792b 100644 --- a/packages/editor-ext/src/lib/markdown/utils/turndown.utils.ts +++ b/packages/editor-ext/src/lib/markdown/utils/turndown.utils.ts @@ -150,7 +150,7 @@ function preserveDetail(turndownService: _TurndownService) { ) .join(''); - return `\n
\n${detailSummary}\n\n${detailsContent}\n\n
\n`; + return `\n
\n${detailSummary}\n\n${detailsContent}\n\n
\n`; }, }); }