Markup: inline php

Created on 9 Apr 2012  路  43Comments  路  Source: github/markup

We often need to highlight PHP code without start

Its easy using Pygments - by set startinline option to true.

But how ho implement this using GFM?

Something like phpi language identifier?

Most helpful comment

The issue looks like it needs to be reopened, indeed. Example https://gist.github.com/polybuildr/69a42db2cca07a14f805 of @polybuildr still does not work.

All 43 comments

I believe this has been resolved when using ```php as the opening of the code block.

I did discover one problem though, the php function substr is not recognized. see substr in manual

/** comments about stuff */
echo "Some stuff echoed";

print_r(array('and' => 'other things all well'));

$str = "Some very long string that we want to cut shorter";

/** this is a problem though */
phpinfo();                         // a php function
my_function();                     // a custom function
echo substr($str, 0, 16);          // not recognized as php function
echo substr($str, -14);            // should look like the other php functions
echo mb_substr($str, 0, 16);       // a php function
echo chunk_split($str, 16, "\n");  // a php function


Is exactly the same as with the <?php added,

<?php
/** comments about stuff */
echo "Some stuff echoed";

print_r(array('and' => 'other things all well'));


/** this is a problem though */
phpinfo();                         // a php function
my_function();                     // a custom function
echo substr($str, 0, 16);          // not recognized as php function
echo substr($str, -14);            // should look like the other php functions
echo mb_substr($str, 0, 16);       // a php function
echo chunk_split($str, 16, "\n");  // a php function


Awesome stuff guys thanx!!! This is going to make php snippets much tidier. You rock! Keep up the good work.

Issue can be closed

It looks like it is fixed for comments, but not for the Github wiki. Should be implemented there too! Issue should remain open!

The wiki is probably the most important place that inline markup is needed. Issue comments are not read nearly as much as documentation!

Would really appreciate this being done for the wiki. Seems a waste of space to have a start

+1 from me for setting startinline option to true

This also doesn't work on _Gist_. Without this Stackoverflow answer my text still wouldn't be highlighted, because I wasn't expecting the <?php tag to be mandatory.

Also still not working for the Wiki. Can we re-open this issue please?

I also vote for reopening. It still doesn't work

double voting on this... don't see why it was closed

Sorry, totally glossed over after reading "Issue can be closed".

Also happy to double vote up! :+1:

good thing we are open again.

@gjtorikian that link to comment would look so much better like this

#158-11622364

=)

Add my vote for startinline option to true for php wiki highlighting without the bloody opening tag.

:+1:

Is this getting fixed any soon?

Still waiting, this is now a year old, please can someone at GitHub look into this.

Syntax highlighting for markdown in Wikis should work the same as on the rest of the site now. It will be fixed for non-markdown formats in a few days.

As for how the syntax highlighting works, we use https://github.com/tmm1/pygments.rb, so any changes can be requested there.

@bkeepers How about gh-pages?

@benbalter can you speak to the current status of syntax highlighting on Pages?

Pages uses Pygments as well (and soon Rouge). It appears you can pass options directly to pygments via the {% highlight %} tag, in this case {% highlight php startinline %}, although I've never tried that before (despite my strong PHP roots). :smile:

@parkr (Jekyll Maintainer) may be able to shed some more light.

As long as startinline is a valid option in pygments, Jekyll will parse {% highlight php startinline %} to use the php lexer with the options { 'startinline' => true }. We just pass the options on to pygments.rb!

It would be great if the Pages supported the @```php@ syntax with the startinline option true by default so that github pages could be edited/previewd via the github web-based editor which doesn't recognize the Liquid syntax at all. Also it is much shorter to type.

Not sure why this doesn't apply everywhere? Isn't working on the readme.md that we setup for our projects.

This still doesn't seem to work for GitHub gists. Will this be fixed anytime soon?

I also encountered this problem, these days has been to consult the relevant materials that I tired like a dog, especially English very poor circumstances, until now I know the problem originally has always been there, ```php code can highlight it in my local, GitHub above is not

This should be working properly on Gist. Post examples here if it is not.

https://gist.github.com/spicycode/9352f01ff026d50df4e4

@bkeepers, if my understanding of the issue is correct, then both the following gists should have been highlighted the same way.

https://gist.github.com/polybuildr/69a42db2cca07a14f805
https://gist.github.com/polybuildr/b79ab80bb453a6232c29

@bkeepers, could you please take a look at the examples I posted above and let me know if this is a problem at my end or GitHub's.

@polybuildr those look ok to me. @aroben or @spicycode, any ideas?

We should probably highlight https://gist.github.com/polybuildr/69a42db2cca07a14f805 even though there's no <?php tag. @vmg fixed this for github.com (at least for inline code in markdown; not sure about full files). Maybe we need to port the fix to Gist.

The examples should be rendering correctly now on Gist.

:heart: @spicycode

@spicycode, @bkeepers, thanks, fixed now. :)

There is no syntax highlight for .php files.

It does seem like there's been a regression. The same two gists I posted before have the same issue as before: the one with the <?php gets highlighted, the other doesn't.

https://gist.github.com/polybuildr/69a42db2cca07a14f805
https://gist.github.com/polybuildr/b79ab80bb453a6232c29

@spicycode can someone reopen this issue then?

Definitely still seeing a problem with the gists which no longer syntax highlight PHP without the opening PHP tag. It's common to use gists to share part of a file rather than the whole file, so this feature should probably be reinstated. I think this is a current bug and the issue should be open

The issue looks like it needs to be reopened, indeed. Example https://gist.github.com/polybuildr/69a42db2cca07a14f805 of @polybuildr still does not work.

This is annoying, why can they fix this?

I'm unsure if this is the right issue. I'm trying to highlight a php template in a README.md and it is just not working as expected.

On GH Pages I'm usually using "```php?start_inline=true" to start an inline code. In github it is different - of course it's not using jekyll to render markdown. Somehow annoying but why to refer on github markdown files instead of the documentation page of your library?

But on github this syntax is not working (it's just not highlighting at all) - instead it is always enabled what is even more worse because you can't disable it.

And this is obviously not highlighted correctly:

Hallo <?= $name ?>
<?php foreach ($messages as $message) : ?>
    <p><?= $message ?></p>
<?php endforeach; ?>

I think it should look if the content contains <?php and if not start inline.

I there anybody alive? This issue should be fixed, we want PHP code to be highlighted!

Was this page helpful?
0 / 5 - 0 ratings