obsidian-linter: Bug: Incorrect addition of H1 when the note only contains front-matter

Describe the Bug

I had a note that only consisted of YAML front-matter. I activated the linter option “Inserts the file name as an H1 if no H1 exists.”. When you lint the file, the heading gets added after the closing --- of the front-matter and a blank line gets inserted after the opening ---.

How to Reproduce

Steps to reproduce the behavior:

  1. Create a new note with an arbitrary title.
  2. Add a frontmatter block to it.
  3. Make sure there is no new-line at the end of the file.
  4. Go to the linter options and activate “Inserts the file name as an H1 if no H1 exists.” in the heading options.
  5. Lint the note.

Example to reproduce issue with

Say we have a note with title Test note which has the following contents:

---
hello: test
---

Note: there is no ending new-line after the closing ---.

After a lint, the note gets converted to:

---

hello: test
---# Test note

Expected Behavior

The note gets properly linted, and the title of the note gets added below the YAML front-matter.

---
hello: test
---

# Test note

Screenshots

Screenshot 2022-11-25 at 14 50 59 Screenshot 2022-11-25 at 14 51 12

Device

  • Desktop
  • Mobile

Additional Context

I’m happy to work on a fix if you give me pointers on where to look at. Awesome job, btw ❤️

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16

Most upvoted comments

That’s odd. It should be ignoring the YAML. But maybe it is not. Some of the rules definitely do not play well together. I will see if I can reproduce with the data.json you provided.

This issue should now be fixed on the master branch of the plugin and will go out with the next release. Please let us know if that is not the case.

Thanks! I am definitely looking to make the plugin easier to user for other people to contribute. I know it can be kind of tricky with a few things, but I tried to outline several helpful things in the contribution file. Hopefully it explains how to add new rules and fix bugs.

As someone that has helped with this plugin for around 6 months, I assume that I am leaving something out that would be helpful for other people looking to contribute due to my familiarity with the setup of the plugin.