You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I like the API design of tinycss2, but find it frustrating that if I'm interpreting some CSS, I always have to be ready for the possibility of finding a ParseError (or indeed a Comment), even if I have now lost the context in which it was parsed, and hence enough information to report an error to the user.
While I understand the benefits of keeping parse errors local, I would propose one or both of:
a function to traverse all token lists found within a parse, so that they can be cleaned or otherwise handled;
an option to attach the original input CSS or similar to each ParseError node.
parse_* functions have a skip_comments parameter. Does this help?
I don’t quite understand what you’re asking for, sorry. What do you mean by "the context in which it was parsed"? Comment and ParseError inherit from Node. All nodes have source_line and source_column attributes, as well as a serialize() method.
Could you given an example with some code?
As to tinycss, I think it has significant design flaws. But if it works for you ¯\_(ツ)_/¯
Thanks, I somehow overlooked skip_comments. Yes, that helps.
To be explicit, I'm writing a library that involves transforming CSS declarations, but many of them are left untransformed and consumed by a client library. My library will land up raising warnings for the parse errors it encounters directly. But then the client is obliged to also catch and handle parse errors, or else trip on them.
Just to let you know: I’m not working on WeasyPrint or tinycss2 anymore. While I don’t mind chatting about it, filing issues is unlikely to get the project moving. Even pull requests I’m unlikely to spend time reviewing etc.
A lot of this is not part of tinycss2 on purpose: to make fallback work, only the set of properties and values that are supported (e.g. in layout code) should be parsed.
@jnothman A lot of things have changed since 2017, are you still interested in this issue?
A lot of this is not part of tinycss2 on purpose: to make fallback work, only the set of properties and values that are supported (e.g. in layout code) should be parsed.
I hadn't known of weasyprint. It's not surprising to find it does a lot of what I've been working on in weasyprint.css...
Yes, I think that most of the features you want are not in TinyCSS2's scope.
Activity
jnothman commentedon May 11, 2017
In particular, it becomes a much greater nuisance to test that my CSS interpretation code works with comments in any part of the CSS.
Or would you recommend just sticking with
tinycss, @SimonSapin?SimonSapin commentedon May 11, 2017
parse_*functions have askip_commentsparameter. Does this help?I don’t quite understand what you’re asking for, sorry. What do you mean by "the context in which it was parsed"?
CommentandParseErrorinherit fromNode. All nodes havesource_lineandsource_columnattributes, as well as aserialize()method.Could you given an example with some code?
As to tinycss, I think it has significant design flaws. But if it works for you ¯\_(ツ)_/¯
jnothman commentedon May 11, 2017
Thanks, I somehow overlooked
skip_comments. Yes, that helps.To be explicit, I'm writing a library that involves transforming CSS declarations, but many of them are left untransformed and consumed by a client library. My library will land up raising warnings for the parse errors it encounters directly. But then the client is obliged to also catch and handle parse errors, or else trip on them.
I rather the tinycss2 interface, thanks :)
SimonSapin commentedon May 11, 2017
It sounds like maybe you want a tree traversal/rewriting mechanism.
Here is an untested attempt:
Which could be used like this:
jnothman commentedon May 14, 2017
Yes, that sort of thing, though I'd design it as a generator, with an interface more like
os.walk.jnothman commentedon May 15, 2017
I.e. replacement would occur in-place in lists and nodes.
jnothman commentedon May 15, 2017
SimonSapin commentedon May 15, 2017
Just to let you know: I’m not working on WeasyPrint or tinycss2 anymore. While I don’t mind chatting about it, filing issues is unlikely to get the project moving. Even pull requests I’m unlikely to spend time reviewing etc.
jnothman commentedon May 15, 2017
SimonSapin commentedon May 15, 2017
A lot of this is not part of tinycss2 on purpose: to make fallback work, only the set of properties and values that are supported (e.g. in layout code) should be parsed.
liZe commentedon Jul 17, 2019
@jnothman A lot of things have changed since 2017, are you still interested in this issue?
Yes, I think that most of the features you want are not in TinyCSS2's scope.
liZe commentedon Feb 23, 2020
@jnothman Feel free to reopen if you want!