#17 - Added support for indentation

This commit is contained in:
Elio Struyf
2020-09-10 16:28:45 +02:00
parent 2905d4e09d
commit 0970fe47b9
2 changed files with 9 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ import { TaxonomyType } from "../models";
import { CONFIG_KEY, SETTING_TAXONOMY_TAGS, SETTING_TAXONOMY_CATEGORIES, EXTENSION_NAME } from '../constants';
import { ArticleHelper, SettingsHelper, FilesHelper } from '../helpers';
import { TomlEngine, getFmLanguage, getFormatOpts } from '../helpers/TomlEngine';
import { DumpOptions } from 'js-yaml';
export class Settings {
@@ -240,11 +241,13 @@ export class Settings {
taxonomies = taxonomies.filter(o => o !== selectedOption);
}
data[matterProp] = [...new Set(taxonomies)].sort();
const spaces = vscode.window.activeTextEditor?.options?.tabSize;
// Update the file
fs.writeFileSync(file.path, matter.stringify(article.content, article.data, {
...TomlEngine,
...langOpts
}), { encoding: "utf8" });
...langOpts,
indent: spaces || 2
} as DumpOptions as any), { encoding: "utf8" });
}
}
}

View File

@@ -66,11 +66,14 @@ export class ArticleHelper {
const language = getFmLanguage();
const langOpts = getFormatOpts(language);
const spaces = vscode.window.activeTextEditor?.options?.tabSize;
return matter.stringify(content, data, ({
...TomlEngine,
...langOpts,
noArrayIndent: !indentArray,
lineWidth: 500
lineWidth: 500,
indent: spaces || 2
} as DumpOptions as any));
}