Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i stringify toml comment? #22

Open
Gnosnay opened this issue Oct 29, 2019 · 5 comments
Open

How can i stringify toml comment? #22

Gnosnay opened this issue Oct 29, 2019 · 5 comments

Comments

@Gnosnay
Copy link

Gnosnay commented Oct 29, 2019

hey iarna~ this parser is so convenient to convert between toml and JSOject.
but i have one question about that how can i insert the toml comment when i use TOML.stringify method to convert one js object to toml text?

i will appreciate it if u can give me some advice. thx a lot.

@iarna
Copy link
Owner

iarna commented Apr 18, 2020

At this time, comments are not supported. The biggest limitation is just figuring out how this would be represented. It would be useful for someone interested to spend some time working up examples of how this might work... what the source object versus resulting TOML would look like, and vice-versa.

@scriptcoded
Copy link

@iarna What would the primary use case for comments in the output be? Just preserving them for doing machine edits of config files, or writing new comments?

@iarna
Copy link
Owner

iarna commented Jul 17, 2020

@scriptcoded Probably both, certainly if it can do the first, then the second should be straightforward.

@scriptcoded
Copy link

@iarna Perhaps. In my head the hard thing with comments is that they don't have an unique identifier, which means that they can not be easily represented in a POJO. The first solution that came to me was to use random identifiers for comments. The issues with that are pretty obvious though, as there is a risk for collisions between comments and actual keys. Also, it's not a very friendly interface for developers.

Another idea might be to tie comment to properties, and return a separate object containing comments. For example:

# names contains a list of usernames and their IRL names.
# Multiline?
[names]
"foo" = "Mr. Foo"
# Nested comment?
"bar" = "The big Bar"
// Return value from `toml.parse`
{
  "data": { /* The normal output */ },
  "comments": {
    "names": "names contains a list of usernames and their IRL names.\\nMultiline?",
    "names.bar": "Nested comment?"
  }
}

@jjeejj
Copy link

jjeejj commented Feb 4, 2021

comment is support now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants