platers / obsidian-linter

An Obsidian plugin that formats and styles your notes with a focus on configurability and extensibility.
https://platers.github.io/obsidian-linter/
MIT License
1.13k stars 79 forks source link

Bug: YAML Key Sort option removes multi-line content after literal operator `|` #1082

Open CharmedSatyr opened 2 months ago

CharmedSatyr commented 2 months ago

Describe the Bug

When the YAML Key Sort option Sorts the YAML keys based on the order and priority specified. and a YAML Sort Order for Other Keys order is enabled, nested content after a literal operator | is removed.

This is a problem for me because I'm using Obsidian Custom Sort, which recommends syntax with a sorting-spec key followed by a literal operator.

How to Reproduce

  1. Enable Settings > Linter > Sorts the YAML keys based on the order and priority specified.
  2. Set YAML Sort Order for Other Keys to Ascending Alphabetical or Descending Alphabetical.
  3. Add front matter with a literal operator and nested content.
  4. Run the linter.
  5. The nested lines after the | will be removed.

Example

---
sorting-spec: |
  order-desc: a-z
---

order-desc: a-z will be removed.

Expected Behavior

Nested content after a literal operator should not be removed.

Device

pjkaufman commented 2 months ago

Hey @CharmedSatyr . I believe this is a known issue. I don't think the Linter currently supports that syntax for YAML values, but I am open to changes to add that kind of support to the Linter.

CharmedSatyr commented 2 months ago

Thanks @pjkaufman. There is a note in the option about blank lines being removed and nested keys not being sorted. However, for me, it is unexpected behavior that the linter would delete (potentially lots of) non-blank lines of properly formatted front matter. This ticket does feel like a bug rather than feature request for that reason.

pjkaufman commented 2 months ago

Hey @CharmedSatyr , this is a bug, but it has come up before if I recall and the issue was using a syntax that the Linter currently does not properly handle. There have been discussions on how to fix this, but none of them have yielded any fruit for now. So this is something where I am looking for help from other devs to contribute a fix for this issue as this literal operator is not currently handled by the Linter.

pjkaufman commented 2 months ago

For context, the prior report of this bug was https://github.com/platers/obsidian-linter/issues/992