-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add more modern PHP syntax highlighting #176
Conversation
@javiereguiluz I just rebased this PR and made it green. So it's ready for you to try out locally whenever you want :) (no pressure at all, things won't break) |
Wo, I love it, thanks @wouterj ! |
Wouter, thanks a lot for this great work. What a nice addition to the PHP highlighting 🙇🙇 I've been playing with it locally and it works exactly as expected:
A before/after example using one of the same examples that you showed: So, we can totally merge this and start using it in production. Thanks! |
Thanks for testing Javier! I'll let you handle releasing a version as you can best coordinate this with the website :) |
Thanks! This was released as |
As those PHP highlighting rules have been forked from the ones in the highlight.php library, which were based on the highlight.js project, it would be great to identify which improvements could be submitted to upstream projects. Maybe at some point in the future, we would be able to avoid maintaining custom highlighting rules for PHP and Twig. |
@stof in an ideal world, yes. But in practical world, the reality is that the PHP fork is more or less dead. The project relies on Highlight.js's JS syntax files and has a script to convert them to JSON. However, since Highlight.js 10 the JS syntax files can contain functions that will be used when highlighting code. These of course can not be converted to JSON, which broke the convert script. There is an experiment to create a JS code to PHP code converter (scrivo/highlight.php#109), but that seems rather stalled (and sounds fragile). So we are forever stuck to the syntax files of v9. On the long term, we probably would be better of to use another highlighting library. In the mean time, we can keep manually updating the PHP syntax file (given that is by far the most significant language in the Symfony docs). |
Because I had fun playing around with this, I've added more changes to the PHP syntax file, bringing it more or less up to date with Highlight.js' syntax file.
Noteworthy changes:
@javiereguiluz please test this out locally. This patch will generally add more color to the code blocks. You might want to tweak the CSS a bit depending on your favor (we seem to have relatively little coloring in our code examples).
E.g. function calls now get
hljs-title
as well (you can use.invoke__
to differentiate them from other titles), and named arguments will be labelled ashljs-attr
(which is currently colored similar tohljs-meta
used for PHP attributes).