Skip to content

Commit

Permalink
Need to localize the new lines, not normalize them #1206
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Dec 16, 2023
1 parent 1663453 commit 47a0968
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
12 changes: 6 additions & 6 deletions test/EleventyTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import TemplateMap from "../src/TemplateMap.js";
import TemplateConfig from "../src/TemplateConfig.js";
import DateGitFirstAdded from "../src/Util/DateGitFirstAdded.js";
import DateGitLastUpdated from "../src/Util/DateGitLastUpdated.js";
import { normalizeNewLines } from "./Util/normalizeNewLines.js";
import { normalizeNewLines, localizeNewLines } from "./Util/normalizeNewLines.js";

const fsp = fs.promises;
const lodashGet = lodash.get;
Expand Down Expand Up @@ -226,7 +226,7 @@ test("Eleventy to json", async (t) => {
url: "/test/",
inputPath: "./test/stubs--to/test.md",
outputPath: "_site/test/index.html",
rawInput: normalizeNewLines("# hi\n"),
rawInput: localizeNewLines("# hi\n"),
content: "<h1>hi</h1>\n",
},
]
Expand Down Expand Up @@ -261,7 +261,7 @@ test("Eleventy to ndjson", async (t) => {
url: "/test/",
inputPath: "./test/stubs--to/test.md",
outputPath: "_site/test/index.html",
rawInput: normalizeNewLines("# hi\n"),
rawInput: localizeNewLines("# hi\n"),
content: "<h1>hi</h1>\n",
});
}
Expand Down Expand Up @@ -298,7 +298,7 @@ test("Eleventy to ndjson (returns a stream)", async (t) => {
url: "/test/",
inputPath: "./test/stubs--to/test.md",
outputPath: "_site/test/index.html",
rawInput: normalizeNewLines("# hi\n"),
rawInput: localizeNewLines("# hi\n"),
content: "<h1>hi</h1>\n",
});
}
Expand Down Expand Up @@ -364,7 +364,7 @@ test("Eleventy programmatic API without init", async (t) => {
url: "/test/",
inputPath: "./test/stubs--to/test.md",
outputPath: "_site/test/index.html",
rawInput: normalizeNewLines("# hi\n"),
rawInput: localizeNewLines("# hi\n"),
content: "<h1>hi</h1>\n",
},
]
Expand Down Expand Up @@ -396,7 +396,7 @@ test("Can Eleventy run two executeBuilds in parallel?", async (t) => {
url: "/test/",
inputPath: "./test/stubs--to/test.md",
outputPath: "_site/test/index.html",
rawInput: normalizeNewLines("# hi\n"),
rawInput: localizeNewLines("# hi\n"),
content: "<h1>hi</h1>\n",
},
];
Expand Down
14 changes: 6 additions & 8 deletions test/Util/normalizeNewLines.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import os from 'node:os';

function normalizeNewLines(str) {
return str.replace(/\r\n/g, "\n");
}

function normalizeNewLinesInObject(obj) {
for(let key in obj) {
if(typeof obj[key] === "string") {
obj[key] = normalizeNewLines(obj[key]);
}
}
function localizeNewLines(str) {
return normalizeNewLines(str).replace(/\n/g, os.EOL);
}

export {
normalizeNewLines,
normalizeNewLinesInObject,
normalizeNewLines,
localizeNewLines,
};

0 comments on commit 47a0968

Please sign in to comment.