Skip to content

Adding support for CRLF in the parser #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's rarely used anymore but some systems (I think macs) used to use CR or \r for new line. Should we add support for that also?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should worry about that, otherwise everything is going to get complicated, really quickly

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
Loading