diff --git a/src/helpers/ArticleHelper.ts b/src/helpers/ArticleHelper.ts index 6d33ca3b..8cb925fc 100644 --- a/src/helpers/ArticleHelper.ts +++ b/src/helpers/ArticleHelper.ts @@ -49,9 +49,23 @@ export class ArticleHelper { public static async update(editor: vscode.TextEditor, article: matter.GrayMatterFile) { const removeQuotes = Settings.get(SETTING_REMOVE_QUOTES) as string[]; const commaSeparated = Settings.get(SETTING_COMMA_SEPARATED_FIELDS); + + // Check if there is a line ending + const lines = article.content.split("\n"); + const lastLine = lines.pop(); + const endsWithNewLine = lastLine !== undefined && lastLine.trim() === ""; let newMarkdown = this.stringifyFrontMatter(article.content, Object.assign({}, article.data)); + // Logic to not include a new line at the end of the file + if (!endsWithNewLine) { + const lines = newMarkdown.split("\n"); + const lastLine = lines.pop(); + if (lastLine !== undefined && lastLine?.trim() === "") { + newMarkdown = lines.join("\n"); + } + } + // Check for field where quotes need to be removed if (removeQuotes && removeQuotes.length) { for (const toRemove of removeQuotes) {