-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
(PHP Template) A single apostrophe ' breaks php-template highlighting #4152
Comments
If this is correct PHP then I don't think we properly fully support all types of PHP comments or all nuances of strings. Our grammar specifically says that single quoted strings may NOT contain any type of escape characters... where as Thoughts? |
Hmm thats a good question. But in the bug I tried to demonstrate the escape char is not relevant. I've just used it in the example so it stays valid php but without it or with normal quotes around that string, the same issue appears. Also if there is no escape at all, just php code and then one comment in a code block that contains a "don't" or "can't" all highlight breaks aftwards. Have you tried it in the demo? |
That's interesting. To my knowledge a lot of programming/script languages (php, python, js, ruby, java, perl) support escape chars inside a single quoted string. I've asked chatgpt about it and here is the answer on what can and cannot be escaped in single quote php strings:
|
It is very relevant - if we understood the escape we'd know that that quote isn't a terminator at all. The issue here is two fold:
These combined create the issues you are seeing. To fix this both
The way sublanguage processing works (language within language) is almost like "two phase"... the first parsing pass has to consume the entire block as a single unit - and then pass it off to be reparsed by the second grammar. That means a lot of rules that half way understand the content (skipping strings, comments, etc), and just skip it - until we find the closing pattern. We have to skip strings and comments because a |
I use the developer tool, it's much more powerful than the demo. :-) |
If I whip up a fix are you comfortable building from source and validating - perhaps throwing addition test cases at it trying to break it? |
If you explain to me each step in detail I'd gladly do that! See me as a beginner. |
Might want to start here: https://highlightjs.readthedocs.io/en/latest/building-testing.html Once you've built a I'd start with For example you might first want to start with the inherited single quoted string, where it removes all the escapes by niling |
So seems for PHP we need to modify the line comment rule to also recognize And of course we need to add |
Can you implement this fix? I don't have the capacity right now. I'll gladly test and try to break it afterwards. |
I found something else for the $extra = 'Some optional additional value for the closure';
$validator->add('title', 'custom', [
'rule' => function ($value, $context) use ($extra) {
// Custom logic that returns true if the validation passes and
// false if the error message below should be shown
},
'message' => 'The title is not valid'
]); |
You really need to fire up the developer tool so you can see the spans visually. |
Would that have helped you if I included the visual html spans in the screenshot or as text below? I can still do it but I also provided the code. |
I was thinking it might help YOU. :) |
Unfortunately I really don't have the capacity right now and in the near future to dive into the code and figure out a fix. Would be really thankful if you do it and I'll gladly help to test it afterwards! |
Describe the issue
An apostrophe
'
that exists on its own without being closed seems to break highlighting of everything that comes after it even if it's in a comment or escaped but only with the languagephp-template
. Withphp
it works fine as it should.Funnily if anywhere later this
'
is "closed" it works again.Which language seems to have the issue?
php-template
Are you using
highlight
orhighlightAuto
?Highlight, not auto.
Sample Code to Reproduce
Code: See expected behaviour
Not highlighted:
Correctly highlighted:
Expected behavior
Github highlights the php bits:
I expect it to highlight the code correctly even if not every ' is closed. In a comment for instance, English words allow for shortcuts with ' for instance "don't" or "can't".
Additional observations
Its breaks only if the apostrophe is in PHP code (not HTML) and if it's not in a code block comment /* such as this, that won't cause any troubles */.
It's always everything that comes after it that is broken not before so if half the file doesn't contain a
'
and then suddenly a php part with a'
either in a// comment '
or in a string'string \' with an apostrophe'
the bottom half of the file is not highlighted.The text was updated successfully, but these errors were encountered: