Skip to content

Commit

Permalink
Merge pull request #1229 from pjkaufman/master
Browse files Browse the repository at this point in the history
Feat: `Line Break at Document End` No Longer Adds Blank Line at End of Empty Notes
  • Loading branch information
pjkaufman authored Nov 23, 2024
2 parents e4f7b6a + fc068d6 commit 5063adb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ export default {
// line-break-at-document-end.ts
'line-break-at-document-end': {
'name': 'Line Break at Document End',
'description': 'Ensures that there is exactly one line break at the end of a document.',
'description': 'Ensures that there is exactly one line break at the end of a document if the note is not empty.',
},
// move-footnotes-to-the-bottom.ts
'move-footnotes-to-the-bottom': {
Expand Down
9 changes: 9 additions & 0 deletions src/rules/line-break-at-document-end.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export default class LineBreakAtDocumentEnd extends RuleBuilder<LineBreakAtDocum
return LineBreakAtDocumentEndOptions;
}
apply(text: string, options: LineBreakAtDocumentEndOptions): string {
if (text.length === 0) {
return text;
}

text = text.replace(/\n+$/g, '');
text += '\n';
return text;
Expand Down Expand Up @@ -46,6 +50,11 @@ export default class LineBreakAtDocumentEnd extends RuleBuilder<LineBreakAtDocum
${''}
`,
}),
new ExampleBuilder({ // https://github.com/platers/obsidian-linter/issues/1228
description: 'Empty files will not have a blank line added',
before: dedent``,
after: dedent``,
}),
];
}
get optionBuilders(): OptionBuilderBase<LineBreakAtDocumentEndOptions>[] {
Expand Down

0 comments on commit 5063adb

Please sign in to comment.