Highlighting php without "<?php" #5553
-
Hello there, I'm trying to have syntax highlighting for all the languages that github itself supports using the same grammars too. I'm hitting a problem that I'm not sure how to solve at the moment, PHP code blocks containing something like the following (e.g. without "<?php") are highlighted by GitHub: // Hello world in PHP
echo 'Hello World!'; But they don't seem to be supported by the underlying TextMate grammar: According to a comment from @maxbrunsfeld it seems like some languages are special-cased, presumably to fix issues such as the one I'm getting. If so is that code open source by any chance? If not does anybody have any clues on how to fix this? Also is there a list somewhere of all the languages that are special-cased by github for syntax highlighting purposes? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
No. It's within the main GitHub.com code which isn't open source. It essentially detects the scope
Nope, but I know VSCode has the same behaviour: That said, you're not really comparing like-for-like. Inline snippets are code blocks in Markdown, so if you change your TextMate example to use Markdown, I'd expect you to get the same behaviour. I've not tested it as I don't have TextMate installed, but this is how VSCode works:
PHP is the only one.
As an FYI: We convert all grammars into JSON and attach a tarball of all of these files to each release if you want to use grammars exactly as they're used by GitHub. One thing to keep in mind, is we use the public tree-sitter grammars for the following languages and not those included in Linguist:
We still bundle these grammars with Linguist so other grammars can still pull in components of each and also for those languages that share a common grammar but with different language names. |
Beta Was this translation helpful? Give feedback.
No. It's within the main GitHub.com code which isn't open source. It essentially detects the scope
text.html.php
and prepends<?php\n
to the text if it's not there, colourises it, and then strips it from the beginning of the output before rendering. This only applies to inline code snippets.Nope, but I know VSCode has the same behaviour:
That said, you're not really comparing like-for-like. Inline snippets are code blocks in Markdown, so if you change your TextMate example to use Markdown, I'd expect you to get the same behaviour. I've not tested it as I don't have TextMate installe…