Title: Highlighting inline PHP code in Pelican
Date: 2021-05-10 16:45

When writing my [blogpost on Wordpress' latest
XXE]({filename}/php/xxe_wordpress.md), I was surprised when I saw that my
inline PHP code wasn't properly syntactically colourised. 

Internally, Pelican is using [python-markdown](https://python-markdown.github.io/),
which comes with an extension named [codehilite](https://python-markdown.github.io/extensions/code_hilite/)
for syntax highlighting via [Pygments](https://pygments.org/).
There is an interesting small note at the end of its
[documentation](https://python-markdown.github.io/extensions/code_hilite/#usage) about its options:

> All other options are accepted and passed on to Pygments’ lexer and
formatter. Therefore, valid options include any options which are accepted by
the html formatter or whichever lexer the code’s language uses. Invalid
options are ignored without error.

A quick look at `pygments.lexers.php.PhpLexer`'s
[code](https://github.com/pygments/pygments/blob/debda34e2d4f28d6d369cdafdcba4791702f63fc/pygments/lexers/php.py#L287)
tells use that the option we're looking for is `startinline`, or
[`_startinline`](https://github.com/pygments/pygments/blob/debda34e2d4f28d6d369cdafdcba4791702f63fc/pygments/lexers/php.py#L290-L291)
if you prefer.

Long story short, this is what you have to put in your [`pelican.conf`](https://docs.getpelican.com/en/latest/settings.html) if you
want your inline php code to be highlighted:

```python
MARKDOWN = {
    'extension_configs': {
        'markdown.extensions.codehilite': {'startinline': True},
    },
}
```

An other, albeit über-gross and not future-proof solution, is to [monkey patch
the PHP lexer](https://jasonstitt.com/tech-blog-pelican-git) from within your
`pelicanconf.py`.

