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
Stylus: Fix comment-like grammar(/**/ or //) in property url() and st… …ring display #2361
Conversation
…g detection, and added corresponding unit test.
By the way, I found that some regex can be written better, like:
The another example:
The But I'm worried that current writing has other special meanings, otherwise before I realized that, they could have been changed a long time ago. |
Yes, if we replace the But your question, "Shouldn't this be part of inside (the variable) itself?", in my opinion, two kinds of comment could be different answer.
But if we separate the line comment from declaration, it seems that the solution will be more and more difficult. I try to replace the Let me commit and push, then think it over. In fact, I have much thought about it and want to do something. |
IMO, it really doesn't matter with what you go in this case. For 3 or more, yes please use a character class but for 2? For 2 characters it really doesn't matter (and I also did a small benchmark and it seems like
Yes, the Whenever I see a |
About comments: |
For other tokens, I havn't thought about and tested it. Because at the beginning, I only noticed the problem in title, just like the top image, and tried fo fix it. I will consider all of them later, and design a solution. |
Another discuss about regex: In your opinion, the Does this mean that all regex should be checked again? |
No. Having some unescaped But again: It's not worth the effort to actively "fix" this in existing patterns. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last thing and then I think we are ready to merge.
@@ -1,6 +1,13 @@ | |||
(function (Prism) { | |||
var inside = { | |||
'url': /url\((["']?).*?\1\)/i, | |||
'comment': { | |||
pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the comment
pattern isn't always the first pattern, it should be greedy.
I'm still thinking more cases about the relationship of comment and declaration in these days. But about this, I'm testing more scenes, consider the follow test:
Whether I add or not add Could you give me a test which can describe the different of them? |
You're right, it won't change anything. My bad. I didn't notice that |
Thank you for contributing! |
Yesterday I said that I find another bug of stylus, means the comment-like grammar in url() and string displays error.
I find that the token
property-declaration
should have higher priority to covercomment
token and others, in fact, I think thatproperty-declaration
should match the whole line. Please consider the following example:Before my commit, the second line will be devided into 7 parts, 3 comments and 4 other parts which have no token.
If add
greedy: true
inproperty-declaration
, the second line will be completely matched. In order to match the comment in it, I addcomment
ininside
property, which copied by the above code.Similarily, I add
greedy: true
inurl
property, so it can matchurl(http://......)
andurl("http://......")
instead of comment.