Skip to content
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

chore: Fix CRLF end of line regex #77

Merged
merged 2 commits into from
Feb 1, 2024
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
10 changes: 5 additions & 5 deletions lib/front_matter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import yaml from 'js-yaml';
const rPrefixSep = /^(-{3,}|;{3,})/;
const rFrontMatter = /^(-{3,}|;{3,})\n([\s\S]+?)\n\1\n?([\s\S]*)/;
const rFrontMatterNew = /^([\s\S]+?)\n(-{3,}|;{3,})\n?([\s\S]*)/;
const rFrontMatter = /^(-{3,}|;{3,})\r?\n([\s\S]+?)\r?\n\1\r?\n?([\s\S]*)/;
const rFrontMatterNew = /^([\s\S]+?)\r?\n(-{3,}|;{3,})\r?\n?([\s\S]*)/;

function split(str: string) {
if (typeof str !== 'string') throw new TypeError('str is required!');
Expand Down Expand Up @@ -81,7 +81,7 @@ function parseJSON(str) {
function escapeYAML(str: string) {
if (typeof str !== 'string') throw new TypeError('str is required!');

return str.replace(/\n(\t+)/g, (match, tabs) => {
return str.replace(/\r?\n(\t+)/g, (match, tabs) => {
let result = '\n';

for (let i = 0, len = tabs.length; i < len; i++) {
Expand Down Expand Up @@ -164,9 +164,9 @@ function stringifyYAML(obj, options) {
function stringifyJSON(obj) {
return JSON.stringify(obj, null, ' ')
// Remove indention
.replace(/\n {2}/g, () => '\n')
.replace(/\r?\n {2}/g, () => '\n')
// Remove prefixing and trailing braces
.replace(/^{\n|}$/g, '');
.replace(/^{\r?\n|}$/g, '');
}

function doubleDigit(num) {
Expand Down
Loading