fix(utils): handle CRLF when parsing MDX imports (#8606)

This commit is contained in:
Sébastien Castiel 2023-02-02 03:48:28 -05:00 committed by GitHub
parent ece720b1a7
commit 2f02beebe2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions

View file

@ -55,16 +55,18 @@ export function createExcerpt(fileString: string): string | undefined {
const fileLines = fileString
.trimStart()
// Remove Markdown alternate title
.replace(/^[^\n]*\n[=]+/g, '')
.split('\n');
.replace(/^[^\r\n]*\r?\n[=]+/g, '')
.split(/\r?\n/);
let inCode = false;
let inImport = false;
let lastCodeFence = '';
for (const fileLine of fileLines) {
if (fileLine === '' && inImport) {
// An empty line marks the end of imports
if (!fileLine.trim() && inImport) {
inImport = false;
}
// Skip empty line.
if (!fileLine.trim()) {
continue;