diff --git a/packages/typedoc-plugin-markdown/src/libs/utils/_index.ts b/packages/typedoc-plugin-markdown/src/libs/utils/_index.ts index 14cb0396..f71549a4 100644 --- a/packages/typedoc-plugin-markdown/src/libs/utils/_index.ts +++ b/packages/typedoc-plugin-markdown/src/libs/utils/_index.ts @@ -6,7 +6,6 @@ export * from './format-table-cell'; export * from './get-file-name-with-extension'; export * from './index'; export * from './is-quoted'; -export * from './normalize-line-breaks'; export * from './remove-first-scoped-directory'; export * from './remove-line-breaks'; export * from './sanitize-comments'; diff --git a/packages/typedoc-plugin-markdown/src/libs/utils/format-table-cell.ts b/packages/typedoc-plugin-markdown/src/libs/utils/format-table-cell.ts index 77cdf92b..e135f7fe 100644 --- a/packages/typedoc-plugin-markdown/src/libs/utils/format-table-cell.ts +++ b/packages/typedoc-plugin-markdown/src/libs/utils/format-table-cell.ts @@ -5,7 +5,7 @@ */ export function formatTableCell(str: string) { return str - .replace(/\n/g, ' ') + .replace(/\r?\n/g, ' ') .replace( /```(\w+\s)?([\s\S]*?)```/gs, (match, p1, p2) => `\`${p2.trim()}\``, diff --git a/packages/typedoc-plugin-markdown/src/libs/utils/normalize-line-breaks.spec.ts b/packages/typedoc-plugin-markdown/src/libs/utils/normalize-line-breaks.spec.ts deleted file mode 100644 index 4122cfad..00000000 --- a/packages/typedoc-plugin-markdown/src/libs/utils/normalize-line-breaks.spec.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { normalizeLineBreaks } from './normalize-line-breaks'; - -describe('normalizeLineBreaks', () => { - it('should correctly concatenate lines', () => { - const input = `This line should be concatenated with the next one. -The next line. - -This is the next line double break. -- list item 1 -- list item 2 - -This is another test.`; - - const expectedOutput = `This line should be concatenated with the next one. The next line. - -This is the next line double break. -- list item 1 -- list item 2 - -This is another test.`; - - expect(normalizeLineBreaks(input)).toBe(expectedOutput); - }); -}); diff --git a/packages/typedoc-plugin-markdown/src/libs/utils/normalize-line-breaks.ts b/packages/typedoc-plugin-markdown/src/libs/utils/normalize-line-breaks.ts deleted file mode 100644 index cb4a533a..00000000 --- a/packages/typedoc-plugin-markdown/src/libs/utils/normalize-line-breaks.ts +++ /dev/null @@ -1,38 +0,0 @@ -export function normalizeLineBreaks(str: string): string { - const codeBlocks: string[] = []; - - const placeholder = '\n___CODEBLOCKPLACEHOLDER___\n'; - str = str.replace(/```[\s\S]*?```/g, (match) => { - codeBlocks.push(match); - return placeholder; - }); - - const lines = str.split('\n'); - let result = ''; - for (let i = 0; i < lines.length; i++) { - if (lines[i].length === 0) { - result = result + lines[i] + '\n'; - } else { - if ( - !lines[i].startsWith('#') && - lines[i + 1] && - /^[a-zA-Z`]/.test(lines[i + 1]) - ) { - result = result + lines[i] + ' '; - } else { - if (i < lines.length - 1) { - result = result + lines[i] + '\n'; - } else { - result = result + lines[i]; - } - } - } - } - - result = result.replace( - new RegExp(placeholder, 'g'), - () => `${codeBlocks.shift()}` || '', - ); - - return result; -} diff --git a/packages/typedoc-plugin-markdown/src/libs/utils/remove-line-breaks.ts b/packages/typedoc-plugin-markdown/src/libs/utils/remove-line-breaks.ts index d7be912e..10d9655d 100644 --- a/packages/typedoc-plugin-markdown/src/libs/utils/remove-line-breaks.ts +++ b/packages/typedoc-plugin-markdown/src/libs/utils/remove-line-breaks.ts @@ -1,3 +1,3 @@ export function removeLineBreaks(str: string) { - return str?.replace(/\n/g, ' ').replace(/ {2,}/g, ' '); + return str?.replace(/\r?\n/g, ' ').replace(/ {2,}/g, ' '); } diff --git a/packages/typedoc-plugin-markdown/src/theme/context/helpers/get-description-for-reflection.ts b/packages/typedoc-plugin-markdown/src/theme/context/helpers/get-description-for-reflection.ts index 15865082..d6a2561e 100644 --- a/packages/typedoc-plugin-markdown/src/theme/context/helpers/get-description-for-reflection.ts +++ b/packages/typedoc-plugin-markdown/src/theme/context/helpers/get-description-for-reflection.ts @@ -12,7 +12,7 @@ export function getDescriptionForReflection( return this.helpers .getCommentParts(comment.summary) ?.split('\n\n')[0] - .replace(/\n/g, ' '); + .replace(/\r?\n/g, ' '); } return null; }