nuxtlabs / remark-mdc

Remark plugin to support MDC syntax.
https://remark-mdc.nuxt.space
MIT License
53 stars 5 forks source link

Adding escape character for dots in YAML keys #87

Open serkodev opened 2 months ago

serkodev commented 2 months ago

Is your feature request related to a problem? Please describe.

Yes

In Nuxt Content, I'm trying to add a Vue component with props in YAML format, but I'm encountering an issue with keys that contain a dot (.). Here’s an example of the YAML:

::comp
---
foo.bar: 1
---
::

Currently, remark-mdc uses flat.unflatten in parseFrontMatter, which transforms parent.child keys into a nested structure, like this:

::comp
---
foo:
  bar: 1
---
::

While I understand that this feature is designed to support nested keys, in my case, I need to retain the dots in the original keys (e.g., foo.bar). Is it possible to introduce an escape character (e.g., foo\.bar) to prevent the transformation and preserve the key format?

Thanks for considering this feature!

Additional Infomation

Alternatively, another approach that may be more aligned with YAML's general behavior is to support explicit string keys. For example:

::comp
---
"foo.bar": 1
---
::

This would ensure that the key remains as a string and is not interpreted as a nested structure BUT it maybe hard to implement because need to customize to YAML parser / lexer.

serkodev commented 2 months ago

I just drafted a PR (#88) to implement escape for unflatten.

However, I need some assistance on stringifyFrontMatter and stringifyCodeBlockProps. Are any maintainers available to take a look? Your help would be greatly appreciated. Thanks!