Skip to content

Commit

Permalink
Correctly convert tabs to spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
mgmeyers committed Apr 15, 2021
1 parent 4440059 commit dcae8a7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-style-settings",
"name": "Style Settings",
"version": "0.2.2",
"version": "0.2.3",
"minAppVersion": "0.11.5",
"description": "Offers controls for adjusting theme, plugin, and snippet CSS variables.",
"author": "mgmeyers",
Expand Down
37 changes: 25 additions & 12 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,26 @@ export default class CSSSettingsPlugin extends Plugin {
let match = settingRegExp.exec(text);

if (match && match.length) {
const nameMatch = text.match(nameRegExp);
const name: string | null = nameMatch ? nameMatch[1] : null;
do {
const nameMatch = text.match(nameRegExp);
const name: string | undefined = nameMatch
? nameMatch[1]
: undefined;

try {
do {
try {
const str = match[1].trim();

const indent = detectIndent(str);
const settings = yaml.load(str.replace(/\t/g, indent.indent), {
filename: name,
}) as ParsedCSSSettings;

const settings = yaml.load(
str.replace(
/\t/g,
indent.type === "space" ? indent.indent : " "
),
{
filename: name,
}
) as ParsedCSSSettings;

if (
typeof settings === "object" &&
Expand All @@ -63,10 +73,10 @@ export default class CSSSettingsPlugin extends Plugin {
) {
settingsList.push(settings);
}
} while ((match = settingRegExp.exec(text)) !== null);
} catch (e) {
errorList.push({ name, error: `${e}` });
}
} catch (e) {
errorList.push({ name, error: `${e}` });
}
} while ((match = settingRegExp.exec(text)) !== null);
}
}

Expand Down Expand Up @@ -122,7 +132,10 @@ class CSSSettingsTab extends PluginSettingTab {

errorList.forEach((err) => {
containerEl.createDiv({ cls: "style-settings-error" }, (wrapper) => {
wrapper.createDiv({ cls: "style-settings-error-name", text: `Error: ${err.name}` });
wrapper.createDiv({
cls: "style-settings-error-name",
text: `Error: ${err.name}`,
});
wrapper.createDiv({
cls: "style-settings-error-desc",
text: err.error,
Expand Down
1 change: 1 addition & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"0.2.3": "0.11.5",
"0.2.2": "0.11.5",
"0.2.1": "0.11.5",
"0.2.0": "0.11.5",
Expand Down

0 comments on commit dcae8a7

Please sign in to comment.