Skip to content

Commit

Permalink
#221 - Logic to remove new line by gray matter
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Jan 7, 2022
1 parent 3a847f7 commit 32a6862
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/helpers/ArticleHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,23 @@ export class ArticleHelper {
public static async update(editor: vscode.TextEditor, article: matter.GrayMatterFile<string>) {
const removeQuotes = Settings.get(SETTING_REMOVE_QUOTES) as string[];
const commaSeparated = Settings.get<string[]>(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) {
Expand Down

0 comments on commit 32a6862

Please sign in to comment.