LeaVerou/prism — pull request #337 by zeitgeist87 (2014-08-19 10:32:46+00:00)
Title: Fix line-numbers for PHP in markup

This should fix the problem mentioned in #149

The problem is, that inline php code can be anywhere inside of a html
element. To properly highlight this the php language implementation
temporarily replaces all inline php code with something like `{{PHP0}}`.
After the markup highlighting is finished it replaces it again with the
real code. In the process `\n`s are removed and then added again, which
throws off the line-numbers plugin. Additionally, depending on the order
the hooks are executed, the php implementation replaces the entire code
with `env.element.innerHTML = env.highlightedCode;`, thereby deleting
the line numbers previously added by the line-numbers plugin.

So to fix this, it must be ensured, that the lines are counted before
the php hooks execute, and the line numbering must be added after php
restored the highlighted code. But in the current Prism implementation
there is no way to ensure the order in which the callback functions of
hooks are called.

The new function `addOnTop()` adds the callback to the start of the
array, ensuring it will be called first. With this function it is
possible to solve the php line numbering bug.