-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
CSS, SASS(SCSS), LESS, STYLUS highlighting differences. #2269
Comments
Of each bug with each grammar? I'm not sure that's a great use of time. What really should happen here is to look at how to consolidate all of these, reuse some matchers, merge grammars where possible, etc. That might start to look like more of a ground-level rewrite - and then this exact list of bugs wouldn't be useful at all. It's be more useful to rebuild things on a solid foundation and then see where we stood. It's possible Less/CSS/SCSS could likely become a single grammar... (or very close)... and SASS and Stylus are very similar also. Optimally someone (with a lot of time) needs to dig in here and think about this at a very high level. If we can do something like build 5 on 2 core grammars... or 5 on 1... then keeping the features in sync with future improvements becomes much simpler. Otherwise we could spend a bunch of effort today just to have them get out of sync again in the future. |
Your side by side is also potentially not accurate as you used the same source-source code... SASS and Stylus (at least) are an entirely different grammars AFAIK. They don't expect/require brackets or semi-colons, etc... so it's possible some of the issues you're seeing are because they aren't intended to highlight RAW css code, which is what it appears you're using. To actually test them properly you'd need the same CSS, but converted to each actual language, though some of them might be interchangeable. |
Stylus sounds fun:
LOL. |
I'd really love to avoid having to include ALL the TAGS and ATTRIBUTES if possible. |
You might start by looking at which rules are "generic" in the sense that we could have them in a single place (like CSS) and then pull into the other grammars from there. And then CSS would become a requirement of the other grammars and common things (like list of tags, or attributes, if necessary) would live in CSS grammar. CSS's |
Not so much a feature as side-effect because it's only highlighting attributes it's heard of... but this shouldn't probably be "fixed" to highlight the whole attribute like elsewhere since (as discussed elsewhere) we don't really have a class for highlighting prefixes differently. |
Almost everything that came to my mind the last day was said. The css preprocessors require thorough study for proper work. the difficulty is how to solve it so that everything is highlighted correctly, without having to specify each language element separately. It would be good to solve this, but it takes a lot of work. However, if we did, we would get a more compact and efficient code. In addition, the appearance of css highlights could show a consistent image, which improves clarity and looks nicer. I would be happy if this could be solved. |
@yyyc514 Is it possible to call a language in another language by modifying its elements? I started to create scss by rewriting the original css. goes well so far, but in many places you have to go into the original code. What do you think would be a good solution? It could be possible to highlight multiple languages within a language file if it is possible to resolve the add-on code snippets only for that alias scss stylus etc. switch on. What is possible in hljs? |
Take a look at arduino and CPP. One way to do this is to make them all depend on CSS and put all the "core" rules there (as much as makes sense)... then you build all the syntaxes based on those rules... For example if we REALLY need a list of all CSS attributes you'd put it in inside CSS then do: var cssLang = hljs.getLanguage("css").exports
cssLang.attributeNames
// etc Or some such... This might be a lot easier to solve after we switch to modules and the new build system, which is why I wasn't in a rush to solve it. :-) Honestly I wondered if CSS/SCSS could be a single language... but I"m not sure how feasible that is. |
There is also sublanguage support, but I don't think that's what we want to do. |
I'd start with VERY small snippets and then make your new grammars work with them, then expand.. and keep iterating... like start with:
That is SCSS and CSS. Get it highlighting... then add another layer:
Make sure that works for both... then maybe more onto pseudo selectors, or |
And if you also did Stylus and Less side by side then you'd see how they were all working at once... and if you did all this in a PR we could provide thoughts and advice as you went. Then after you covered the basics you'd move on to extension specific things like variables, etc... though I guess variables are also part of CSS now too, lol... but you get the point I hope. |
Thanks for the help! I'm exploring the possibilities. I hope I can put together a single compact solution and avoid duplication. |
@yyyc514 I'm still thinking about what to do with stylus. If you need to add css properties, which solution is good? Currently used:
Shorter version:
Most compact version:
The file size can thus be reduced. Because there are many such css properties. I don't know how much it affects the speed, but it worsens the purity with the introduction of a new css feature. |
List them all out, the other just makes future maintenance hard. This is what gzip is for (saving bytes)... But I'd do even further and list then in array form now a string... I have a feeling we'll want to use them outside of |
I don't mind being smart for certain individual attribute though, such as for border:
That might actually make it easier to see what is going on and doesn't make maintenance harder since it's really part of a single attribute "border", so it's well grouped. |
I also saw a block solution, but there it finally generates a regular expression full of treasures out of the array with extra steps. |
If I was doing it I'd probably do a mix in an array:
Then you could use regex to describe some of the attributes that lended themselves well to that... or else just an array of literal strings. |
Though I still debate if you need an actual list. It seems you could just match |
So let's use it like this: PROPERTIES.join('|') It's not good this way:
In this case, non-existent properties are also formed. |
Properties that will never appear in CSS files anyways. And how much easier to maintain is that that writing out 100 different possibilities? Many of our grammars cheat in the same way. But again, why not avoid the list completely? |
Yes css is good. |
How so? All the examples I see still have properties ending in Oh I see you can also write: body
color white Ugh :-) Still isn't the first word always a property? |
The stylus leaves everything out, so incorrectly marked elements can be formed if there is no list. |
I'm not sure this is true, but it MIGHT be. It's definitely easier if you have a list. Isn't
|
Seems 100% possible: https://github.com/PrismJS/prism/blob/master/components/prism-stylus.js If we can avoid a list that also means the syntax is always stays up-to-date... and we don't need to keep adding new CSS/HTML tags to it over the years. That's a big win. |
If possible, I'd like to avoid the list. But I wouldn't get a wrong selection either.
or
Thanks for the link. |
In that sample every "more than one word" is an property/value pair. The only "edge case" is By word I mean "contiguous sequence of characters". |
Yes, I think it will be necessary for a few more weeks. Regarding the list of CSS properties, I would suggest:
https://developer.mozilla.org/en-US/docs/Web/CSS/--* I've collected a list of internal functions: If I differentiate the built-in functions, I need to list them. |
Not worth it, just list them both. That's not that long of a list... I think the real decision is whether there is value in differentiating built-in functions vs user functions. I think probably? |
No objection. |
Current state: This is used by css: This is used by stylus: The two representations are clearly different. If we do not differentiate them, then we have to decide what the uniform highlighting structure of the function should be. Each solution has its advantages and disadvantages. The benefit of differentiation is that it shows you where to look for the function. A non-built-in function in the style files, while a built-in function in the style language description. |
I'm not really sure what I'm looking at. It would probably help if you used the same underlying code for both examples and then showed what it looks like in the different languages. I looks like you're using entirely different snippets so that makes it really hard to see anything (at least for me). |
I feel like I already answered this. I saw lets track both functions and built-ins as different things and see how that works out. |
Any luck? :) |
FYI: Now that we have modules we also have the ability to pull common things out into a I'm not 100% sure that's what we want here, but just mentioning it as a possibility. It's definitely preferable to copy-and-paste for simple things. |
Where is the source code example for your very first post? And how did you get the 4 side by side? Do you have a HTML template you're using for the previews? It'd be helpful if you attached those things so others could also use them. I think we need to go back and split this into bite size pieces so that each one can turn into a small PR that is easy to review and get merged. If fear we've gone and made this a huge project and hence it's stalled out. You could do it by language but I think it'd be easier to do it by feature... So you could start with say vendor prefixes, get those working the same everywhere, etc... then pseudo-selectors, etc... these could be separate PRs or separate commits inside a larger PR... If you made a complete list of CSS/CSS processor features how long would it be? 10-20 items? And adding markup tests for each as you went... that way once you had things looking the same you could refactor the languages easily knowing we had solid tests to catch any issues. |
I created a checklist (above in the first message of this thread) and an example: #2425 First, add tests. Then make the grammars consistent. Optimization and sharing code can come last - so I didn't even focus on that. Obviously we should share vendor prefixes globally, etc. I have a small script to make keeping the tests in sync easier:
If you want to work on this you can make PRs against the |
@taufik-nurrohman This is a big chunk of work if you wanted something large to cut your teeth on. :-) |
I will have time again by June. I will continue to work on the topic. Sorry I didn't have time for the new year :(. There is a need on which I would like to ask @yyyc514 opinion, as well as the opinion of others. When you leave the selector in an article, because only the property and the value are important: |
Maybe, maybe not. I feel like we're wasting time answering questions like this without specific context. I made a long list (see initial message) of individual items to work thru... so lets focus on that list - knocking things off one at a time - and then when one of the items on it leads to us asking this kind of question, I say discuss it at that point - with the full context on hand, a PR to look at, etc. I've also been trying to make the minimal invasive changes to do this so far... and work on building up a comprehensive test suite across all the CSS-like grammars... then once we have very high test coverage we can circle back at how we might make any of the individual grammars simpler. |
@yyyc514 Thank you for your support! When I cut in, it seemed simpler at first. However, during the work, it turned out that the basic css highlighter also has shortcomings. I don’t want to waste time, but a lot of little little things came up. Maybe I lost a little bit of the details. Such as unicode selectors, which are also highlighted in the Visual studio code. For example, that's why I created the following solution:
There are lots and lots of little things, yet. I started working on these, but they stopped. I will have time to continue soon. ._ /* NOT Classes*/ |
Title: |
They each have their own shortcomings. Bringing them all into alignment is going to be a lot of slow, laborious effort I think. I started it, but I think someone else may have to finish it. I'm not interested in patches that ONLY fix one while ignoring the others.
Picking a single item like that (Unicode selectors) and making a PR is a great idea... add a test, sync it across the CSS languages (I believe I have a script and that most of them support "plain jane CSS" in addition to their more complex form) and then make changes to guarantee the same behavior. This work (overall) should be done in lots of tiny PRs or else it will be impossible to review. That's why I have a detailed list of CSS features in checklist form at the top of this item... hopefully each item would be a small PR that could be easily reviewed. |
What issues did you notice with
|
What are url and format here? They aren't technically functions are they? |
Could you clarify if you remember? I'm sure keyframes needs work, but what was the issue with font-face (other than the function aren't highlighted, see question above). Right now I have this: (Stylus) |
One could question whether we highlight the explicit values like |
A list of things to keep in sync:
See the
css_consistency
branch.:
(enh) Improve CSS consistency across CSS-like grammars #2425::
(enh) Improve CSS consistency across CSS-like grammars #2425:lang(de)
a[href*="example" I]
(See: (css) selector-attributes are not highlight correctly #2243)(grayscale(0.5)
)@import
, etc.!important
Sass bug list:
Less bug list:
Stylus bug list:
There is a lot of difference. If I have enough time, I'll make examples one by one. I welcome any help. Thanks in advance for all your help!
The text was updated successfully, but these errors were encountered: