cssparser.js icon indicating copy to clipboard operation
cssparser.js copied to clipboard

Option to include comments in json output

Open tomgenoni opened this issue 7 years ago • 3 comments

One use case is for documentation. For example, at the top of each CSS file I might include a title and a description. The JSON could then be used to output that meta information along with the actual CSS.

tomgenoni avatar Dec 06 '17 21:12 tomgenoni

Thanks for the request! I agree to your opinion.

I also wanted supporting comments, however, I was troubled because there is something difficult to solve. As we know, comments blocks can be located at anywhere in CSS. So, sometimes it's difficult to put comments informations into JSON:

/* field decorator */
.my-field {
    padding-left: 1em; /* left padding */
    /* background color */
    background-color: /* don't fix this */ #fff /* white */
}

I know this is ugly example. but, it's possible. :/ If you have any idea to handle these cases, please let me know. :) Thanks! :)

cwdoh avatar Dec 17 '17 16:12 cwdoh

Do you you mean it would be difficult to construct JSON from the example above or that its difficult to parse?

In any case what I wanted to do was use the comments for documentation, where the source would look like:

/*
# My Thing

This component does x, y, and z.
*/

.my-thing {
  padding-left: 1em;
}

Here only the comments at the root level would be captured, though I could see that may be too specific a use case for this script.

tomgenoni avatar Dec 17 '17 20:12 tomgenoni

Okay. I'll include this feature in the next release. :)

cwdoh avatar Dec 18 '17 00:12 cwdoh