Skip to content

Commit

Permalink
chore: fixed parsing CRLF regex
Browse files Browse the repository at this point in the history
fix for sometimes changing post from github directly
which doesnt have auto trim whitespaces while saving file
  • Loading branch information
dimaslanjaka committed May 13, 2023
1 parent daaf0ea commit 4faac3a
Showing 1 changed file with 5 additions and 5 deletions.
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 @@ -124,7 +124,7 @@ function parseJSON(str: string) {
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 @@ -210,9 +210,9 @@ 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, '')
);
}

Expand Down

0 comments on commit 4faac3a

Please sign in to comment.