-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Tokenize css before beautifying #545
Comments
@bitwiseman Are you still interested in this? I might be willing to work on this a few tokens at a time instead of tokenising the entire beautifier at once. |
@mhnaeem I'm not sure how you'd convert to using tokens one or two at a time. |
@mhnaeem If you see where I'm going from that mess off code, please go for it. Otherwise hold off until I get comments and strings working. Then it should be at a point where it is easier to add more tokens one at a time. |
@bitwiseman Actually that is very similar to what I had in mind. I actually wrote a partially working tokenizer to understand the mechanics of CSS. My biggest issue was handling whitespace and newlines with the with partially tokenized code. You have to back track all the whitespace and newline characters in the input scanner if an unknown token comes along so the rest of the beautifier code can work as normal and peek for spaces if needed. I will let you take a stab at fixing strings to see how you handle working with positions before I can take a look. Things that I learned from experimentation:
var pattern_reader = new Pattern(this._input);
this.__patterns = {
// https://stackoverflow.com/questions/448981/which-characters-are-valid-in-css-class-names-selectors
class_selector: pattern_reader.matching(/\.-?[_a-zA-Z]+[_a-zA-Z0-9-]*/),
id_selector: pattern_reader.matching(/#-?[_a-zA-Z]+[_a-zA-Z0-9-]*/)
}; |
@mhnaeem From you're comments it sounds like you've already done significant work. |
I have created a draft PR #2032, not sure if it has any usefulness. I wasn't really focused on committing a lot of code because that was just me learning so most of the work I did is lost 😅. The code you have is definitely the right way to go if we were to look at writing a tokenizer |
@mhnaeem Given your comments, I really just wanted to see what you'd done and try to pull any useful parts of it into my work with commits that credit you as the author of those bits. |
See #506.
This is the kind of bug that is much less likely to occur if you actually tokenize instead of just streaming through characters spewing output.
The text was updated successfully, but these errors were encountered: