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

Keep comments in CssStyleSheet #99

Open
mganss opened this issue Jan 18, 2022 · 2 comments
Open

Keep comments in CssStyleSheet #99

mganss opened this issue Jan 18, 2022 · 2 comments
Milestone

Comments

@mganss
Copy link
Contributor

mganss commented Jan 18, 2022

It seems that CSS comments are not kept in the CSSOM and thus are not preserved when you call ToCss() on a previously parsed CssStyleSheet object.

var html = @"<style>  /* Set text color to red */ h1{color:red}</style>";
var parser = new HtmlParser(new HtmlParserOptions(), BrowsingContext.New(Configuration.Default.WithCss(new CssParserOptions())));
var dom = parser.ParseDocument(html);
var styleSheet = dom.StyleSheets[0] as ICssStyleSheet;
var css = styleSheet.ToCss(); // -> "h1 { color: rgba(255, 0, 0, 1) }"
@FlorianRappl
Copy link
Contributor

Well, there is no such thing in the CSSOM; we collect all that into "trivia" (a technique popularized by Roslyn). The ToCss serialization only works on the CSSOM -> so in order to serialize with the comments something else would need to be serialized (or the CSSOM would need to be extended / changed).

Potentially, a flag could be introduced, but even then I am not sure how these comments would be attached. Maybe they would be attached to the stylesheet itself with a reference "where" they should be placed (this "where" is a big problem; in this OM things may be added, removed, changed, ... - I guess any change would then need to reset / remove / alter the comments?).

@mganss
Copy link
Contributor Author

mganss commented Jan 19, 2022

I realize this is a non-trivial endeavour, in particular the "where" part you mentioned. Unlike in HTML, comments in CSS can be arbitrarily interleaved with other tokens (e.g. background-color: /* black */ #000;) so this would need to be reflected in the OM as well. Feel free to close this.

@FlorianRappl FlorianRappl added this to the v0.17 milestone May 31, 2022
@FlorianRappl FlorianRappl modified the milestones: v0.17, v1.0 Jan 15, 2023
@FlorianRappl FlorianRappl modified the milestones: v1.0, vNext Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants