mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-08-07 09:23:00 +02:00
#5 - Added a different behaviour to remove quotes
This commit is contained in:
@@ -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."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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";
|
||||
export const SETTING_INDENT_ARRAY = "taxonomy.indentArrays";
|
||||
export const SETTING_REMOVE_QUOTES = "taxonomy.noPropertyValueQuotes";
|
||||
@@ -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<string>) {
|
||||
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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user