Skip to content

Commit 581ae00

Browse files
Adding support for CRLF in the parser
1 parent 3f3137a commit 581ae00

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

utils/snippetParser.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ function raise(issue, snippet = '') {
2727
return null;
2828
}
2929

30-
const crlfRegex = /\r\n/gm;
3130
const propertyRegex = /^\s+([a-zA-Z]+):\s*(.+)/;
32-
const headerEndCodeStartRegex = /^\s*---\s*```.*\n/;
31+
const headerEndCodeStartRegex = /^\s*---\s*```.*\r?\n/;
3332
const codeRegex = /^(.+)```/s
3433
function parseSnippet(path, name, text) {
35-
if(crlfRegex.exec(text) !== null) return raise('Found CRLF line endings instead of LF line endings', path);
3634
let cursor = 0;
3735

3836
const fromCursor = () => text.substring(cursor);
@@ -68,7 +66,7 @@ function parseSnippet(path, name, text) {
6866
author: properties.author,
6967
tags: properties.tags.split(',').map((tag) => tag.trim()).filter((tag) => tag),
7068
contributors: 'contributors' in properties ? properties.contributors.split(',').map((contributor) => contributor.trim()).filter((contributor) => contributor) : [],
71-
code: code,
69+
code: code.replace(/\r\n/g, '\n'),
7270
}
7371
}
7472

0 commit comments

Comments
 (0)