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

fix dedenting #79

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"anzip": "^0.2.0",
"arraybuffer-to-buffer": "^0.0.7",
"cli-progress": "^3.8.2",
"dedent": "^1.5.3",
"string-dedent": "^3.0.1",
"glob": "^7.1.6",
"js-logger": "^1.6.1",
"line-reader": "^0.4.0",
Expand Down
23 changes: 15 additions & 8 deletions src/Sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {
writeEnd,
} = require("./common");
const { writeFile, unlink } = require("fs");
const dedent = require("dedent");
const dedent = require("string-dedent");
const path = require("path");
const arrayBuffToBuff = require("arraybuffer-to-buffer");
const anzip = require("anzip");
Expand Down Expand Up @@ -78,6 +78,13 @@ class Snippet {
if (config.disable_ellipsis) {
disable_ellipsis = true;
}
if (config.enable_code_dedenting) {
let lineString = `
${lines.join("\n")}
`;
lineString = dedent(lineString);
return lineString.split("\n");
}
return lines;
}

Expand Down Expand Up @@ -136,13 +143,8 @@ class File {
this.lines = [];
}
// fileString converts the array of lines into a string
fileString(dedentCode = false) {
fileString() {
let lines = `${this.lines.join("\n")}\n`;

if (dedentCode) {
lines = dedent(lines);
}

return lines;
}
}
Expand Down Expand Up @@ -454,7 +456,7 @@ class Sync {
for (const file of files) {
await writeAsync(
file.fullpath,
file.fileString(this.config.features.enable_code_dedenting)
file.fileString()
);
this.progress.increment();
}
Expand Down Expand Up @@ -526,6 +528,11 @@ function overwriteConfig(current, extracted) {
? current.enable_code_block
: extracted.enable_code_block;

config.enable_code_dedenting =
extracted?.enable_code_dedenting ?? true
? current.enable_code_dedenting
: extracted.enable_code_dedenting;

if (extracted?.highlightedLines ?? undefined) {
config.highlights = extracted.highlightedLines;
}
Expand Down
Loading
Loading