Skip to content

Commit

Permalink
Fix parsing errors #7 and #11
Browse files Browse the repository at this point in the history
Change `trimEnclosing` implementation, fix `-scale` to fit specification
  • Loading branch information
daem-on committed Dec 27, 2022
1 parent d0cdef2 commit 94f9b83
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/export/processLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ export function processLayer(layer: paper.Layer) {
const s = settings;
const o = [];

if (s.scale !== "") o.push(`-scale [${s.scale}]`);
if (s.scale !== "") {
const val = s.scale.includes(" ") ? `[${s.scale}]` : s.scale;
o.push(`-scale ${val}`);
}

for (const setting of ScrapSettings.stringSettings.slice(1)) {
if (s[setting])
o.push(`-${setting} "${s[setting]}"`);
o.push(`-${setting} ${s[setting]}`);
}

if (s.otherSettings !== "")
Expand Down
18 changes: 12 additions & 6 deletions src/import/importTH2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ const toPoint = function(global: string[], global2: string[] = undefined) {
]);
};

const trimEnclosing = (text: string) =>
text.trim()
// eslint-disable-next-line no-useless-escape
.replace(/^["'\[]/, "")
.replace(/["'\]]$/, "");
function trimEnclosing(text: string): string {
text = text.trim();
const starting = text.charAt(0);
const ending = text.charAt(text.length - 1);
if ([`"`, `'`].includes(starting) && starting === ending) {
return text.substring(1, text.length - 1);
} else if (starting === `[` && ending === `]`) {
return text.substring(1, text.length - 1);
}
return text;
}

const getOptions = function(source: string) {
const options: Record<string, string> = {};
Expand Down Expand Up @@ -293,7 +299,7 @@ function savePointSettings(point: paper.Shape, options: Record<string, string>)

for (const key of PointSettings.stringSettings) {
if (key in options) {
s[key] = o[key]; delete o[key];
s[key] = trimEnclosing(o[key]); delete o[key];
}
}

Expand Down

0 comments on commit 94f9b83

Please sign in to comment.