diff --git a/package.json b/package.json index 57e09d3c..7599ba4e 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,11 @@ "type": "boolean", "default": true, "markdownDescription": "Specify if arrays in front matter are indented. Default: true." + }, + "frontMatter.taxonomy.noPropertyValueQuotes": { + "type": "array", + "default": [], + "markdownDescription": "Specify the properties from which quotes need to be removed." } } }, diff --git a/src/constants/settings.ts b/src/constants/settings.ts index 50ca0cca..6f4a22f2 100644 --- a/src/constants/settings.ts +++ b/src/constants/settings.ts @@ -9,4 +9,5 @@ export const SETTING_DATE_FORMAT = "taxonomy.dateFormat"; export const SETTING_SLUG_PREFIX = "taxonomy.slugPrefix"; export const SETTING_SLUG_SUFFIX = "taxonomy.slugSuffix"; -export const SETTING_INDENT_ARRAY = "taxonomy.indentArrays"; \ No newline at end of file +export const SETTING_INDENT_ARRAY = "taxonomy.indentArrays"; +export const SETTING_REMOVE_QUOTES = "taxonomy.noPropertyValueQuotes"; \ No newline at end of file diff --git a/src/helpers/ArticleHelper.ts b/src/helpers/ArticleHelper.ts index a1bd8b5d..379c629d 100644 --- a/src/helpers/ArticleHelper.ts +++ b/src/helpers/ArticleHelper.ts @@ -2,8 +2,8 @@ import * as vscode from 'vscode'; import * as matter from "gray-matter"; import { stopWords } from '../constants/stopwords-en'; import { charMap } from '../constants/charMap'; -import { DEFAULT_SAFE_SCHEMA, CORE_SCHEMA, DumpOptions } from 'js-yaml'; -import { CONFIG_KEY, SETTING_INDENT_ARRAY, SETTING_DATE_FORMAT } from '../constants'; +import { CONFIG_KEY, SETTING_INDENT_ARRAY, SETTING_DATE_FORMAT, SETTING_REMOVE_QUOTES } from '../constants'; +import { DumpOptions } from 'js-yaml'; export class ArticleHelper { @@ -29,12 +29,22 @@ export class ArticleHelper { public static async update(editor: vscode.TextEditor, article: matter.GrayMatterFile) { const config = vscode.workspace.getConfiguration(CONFIG_KEY); const indentArray = config.get(SETTING_INDENT_ARRAY) as boolean; - const dateFormat = config.get(SETTING_DATE_FORMAT) as string; + const removeQuotes = config.get(SETTING_REMOVE_QUOTES) as string[]; - const newMarkdown = matter.stringify(article.content, article.data, ({ - schema: dateFormat ? CORE_SCHEMA : DEFAULT_SAFE_SCHEMA, + let newMarkdown = matter.stringify(article.content, article.data, ({ noArrayIndent: !indentArray } as DumpOptions as any)); + + // Check for field where quotes need to be removed + if (removeQuotes && removeQuotes.length) { + for (const toRemove of removeQuotes) { + if (article && article.data && article.data[toRemove]) { + newMarkdown = newMarkdown.replace(`'${article.data[toRemove]}'`, article.data[toRemove]); + newMarkdown = newMarkdown.replace(`"${article.data[toRemove]}"`, article.data[toRemove]); + } + } + } + const nrOfLines = editor.document.lineCount as number; await editor.edit(builder => builder.replace(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(nrOfLines, 0)), newMarkdown)); }