estruyf / vscode-front-matter

Front Matter is a CMS running straight in Visual Studio Code. Can be used with static site generators like Hugo, Jekyll, Hexo, NextJs, Gatsby, and many more...
https://frontmatter.codes
MIT License
1.99k stars 83 forks source link

Issue: YAML parser 'renders' yaml when FM is active, instead of leaving valid YAML alone #382

Closed anakinsleftleg closed 7 months ago

anakinsleftleg commented 2 years ago

Describe the bug I'm not sure if this should be a bug or a feature but I'm putting it under bug because it behaves in a way I would not expect and do not desire.

To set the scene, a content file is using YAML for the frontmatter. That frontmatter has some YAML features like reference variables or empty keys:

description: &summary Multipurpose description.
summary: *summary
subtitle: 
keywords: ['interesting', 'stuff']

These are all valid YAML. When I enable/turn on/make active FrontMatter (which is to say the FM sidebar is open), and I open the content file that has the above frontmatter, FM calls the YAML parser and the YAML parser 'renders' the frontmatter as it was into what it might look like when the project gets build with Hugo. That's fine for when the project gets built, but I don't think it is fine for when I'm working with the raw files which are supposed to be optimized for the user/developer, not for a consumer of YAML (that's where the Hugo build process comes in).

The YAML above gets rendered into:

description: Multipurpose description.
summary: Multipurpose description.
subtitle: null
keywords:
  - interesting
  - stuff

The reference variables go away and the variable value is applied to the destination. The empty key is filled with null. The array is converted from in-line to ... indented? (I know FM now has a parameter that lets you tell it how you want arrays to be rendered, but while there might be a way I want some arrays arranged, I might not want all arrays that same way.)

To Reproduce Basically described above.

Expected behavior I expect the YAML to look exactly as I have written it without change. I don't want nor need that YAML to be rendered into the final YAML output, it is actually detrimental. VSCode has a YAML linter (or I have installed one, whichever) and it tells me as I type whether something is valid YAML or not. That's all I would want or expect.

Reference variables should remain without the values being transferred. I would like to leave empty keys empty, instead of will null. I would like some arrays to be formatted in one manner and other arrays in the other manner (or just not format the arrays at all and leave it as I have written it). For populating the frontmatter from the FM panel, I would agree that an array field should be individually specified for how to format it. An empty field should be empty, not null. And the sidebar should respect and accept reference variables.

Desktop (please complete the following information):

estruyf commented 7 months ago

This is a limit of the yaml parser and will be kept as is.