Skip to content

Commit

Permalink
Merge pull request #189 from Mathys-Gasnier/main
Browse files Browse the repository at this point in the history
Adding support for CRLF in the parser
  • Loading branch information
Mathys-Gasnier authored Jan 5, 2025
2 parents 8508752 + 581ae00 commit 87706b4
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions utils/snippetParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ function raise(issue, snippet = '') {
return null;
}

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

const fromCursor = () => text.substring(cursor);
Expand Down Expand Up @@ -68,7 +66,7 @@ function parseSnippet(path, name, text) {
author: properties.author,
tags: properties.tags.split(',').map((tag) => tag.trim()).filter((tag) => tag),
contributors: 'contributors' in properties ? properties.contributors.split(',').map((contributor) => contributor.trim()).filter((contributor) => contributor) : [],
code: code,
code: code.replace(/\r\n/g, '\n'),
}
}

Expand Down

0 comments on commit 87706b4

Please sign in to comment.