diff --git a/.editorconfig b/.editorconfig index 220e0298e..a8cde4620 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,3 +12,6 @@ trim_trailing_whitespace = true [package.json] indent_size = 2 + +[src/test/converter2/issues/gh2631/crlf.md] +end_of_line = crlf diff --git a/.gitattributes b/.gitattributes index e77811b3a..06874f468 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,6 @@ # Disable core.autocrlf's line ending conversion behavior to prevent test failures on Windows * text=auto eol=lf +src/test/converter2/issues/gh2631/crlf.md text=auto eol=crlf *.png binary *.psd binary diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c3ce3994..55f6e7105 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,11 +8,13 @@ - `@link` tags will now be validated in referenced markdown documents, #2629. - `@link` tags are now resolved in project documents, #2629. - HTML/JSON output generated by TypeDoc now contains a trailing newline, #2632. +- TypeDoc now correctly handles markdown documents with CRLF line endings, #2628. - `@hidden` is now properly applied when placed in a function implementation comment, #2634. - Comments on re-exports are now rendered. ### Thanks! +- @bukowa - @garrett-hopper ## v0.26.3 (2024-06-28) diff --git a/src/lib/converter/comments/parser.ts b/src/lib/converter/comments/parser.ts index e98917676..af65774ea 100644 --- a/src/lib/converter/comments/parser.ts +++ b/src/lib/converter/comments/parser.ts @@ -203,26 +203,12 @@ export function parseCommentString( // Check for frontmatter let frontmatterData: Record = {}; const firstBlock = content[0]; - - let lineBreak: string; - switch (firstBlock.text.startsWith("---\r\n")) { - case true: - lineBreak = "\r\n"; - break; - case false: - lineBreak = "\n"; - break; - } - - if (firstBlock.text.startsWith(`---${lineBreak}`)) { - const end = firstBlock.text.indexOf(`${lineBreak}---${lineBreak}`); + if (firstBlock.text.startsWith("---\n")) { + const end = firstBlock.text.indexOf("\n---\n"); if (end !== -1) { - const yamlText = firstBlock.text.slice( - `---${lineBreak}`.length, - end, - ); + const yamlText = firstBlock.text.slice("---\n".length, end); firstBlock.text = firstBlock.text - .slice(end + `${lineBreak}---${lineBreak}`.length) + .slice(end + "\n---\n".length) .trimStart(); const frontmatter = parseYamlDoc(yamlText, { prettyErrors: false }); @@ -230,7 +216,7 @@ export function parseCommentString( // Can't translate issues coming from external library... logger.warn( warning.message as TranslatedString, - warning.pos[0] + `---${lineBreak}`.length, + warning.pos[0] + "---\n".length, file, ); } @@ -238,7 +224,7 @@ export function parseCommentString( // Can't translate issues coming from external library... logger.error( error.message as TranslatedString, - error.pos[0] + `---${lineBreak}`.length, + error.pos[0] + "---\n".length, file, ); } diff --git a/src/lib/utils/minimalSourceFile.ts b/src/lib/utils/minimalSourceFile.ts index f597b96b8..6469de5e1 100644 --- a/src/lib/utils/minimalSourceFile.ts +++ b/src/lib/utils/minimalSourceFile.ts @@ -7,10 +7,20 @@ import { binaryFindPartition } from "./array"; const lineStarts = new WeakMap(); export class MinimalSourceFile implements SourceFileLike { + readonly text: string; constructor( - readonly text: string, + text: string, readonly fileName: string, ) { + // This is unfortunate, but the yaml library we use relies on the source + // text using LF line endings https://github.com/eemeli/yaml/issues/127. + // If we don't do this, in a simple document which includes a single key + // like: + // --- + // title: Windows line endings + // --- + // we'll end up with a parsed title of "Windows line endings\r" + this.text = text.replaceAll("\r\n", "\n"); lineStarts.set(this, [0]); } diff --git a/src/test/converter2/issues/gh2631/crlf.md b/src/test/converter2/issues/gh2631/crlf.md new file mode 100644 index 000000000..aa988a781 --- /dev/null +++ b/src/test/converter2/issues/gh2631/crlf.md @@ -0,0 +1,5 @@ +--- +title: "Windows Line Endings" +--- + +This file contains CRLF line endings diff --git a/src/test/converter2/issues/gh2631/index.ts b/src/test/converter2/issues/gh2631/index.ts new file mode 100644 index 000000000..ed16886d6 --- /dev/null +++ b/src/test/converter2/issues/gh2631/index.ts @@ -0,0 +1,5 @@ +/** + * @module + * @document crlf.md + */ +export const a = 123; diff --git a/src/test/issues.c2.test.ts b/src/test/issues.c2.test.ts index 566cd6196..99f827ae6 100644 --- a/src/test/issues.c2.test.ts +++ b/src/test/issues.c2.test.ts @@ -1637,6 +1637,14 @@ describe("Issue Tests", () => { logger.expectNoOtherMessages(); }); + it("#2631 handles CRLF line endings in frontmatter", () => { + const project = convert(); + equal( + project.documents?.map((d) => d.name), + ["Windows Line Endings"], + ); + }); + it("#2634 handles @hidden on function implementations", () => { const project = convert(); equal(project.children?.map((c) => c.name) || [], []);