I'm using the Bootstrap Template for ApiGen and I want to replace the default source code views with Highlight.js.
This requires me to remove the existing spans
produced by ApiGen using the Nette replaceRE
filter.
The original code looks like so:
<pre id="source">
<code>{$source|replaceRE:'~<span class="line">(\s*)(\d+):(\s*)</span>([^\\n]*(?:\\n|$))~','<span id="$2" class="l">
<a href="#$2">$1$2$3</a>$4</span>'|noescape}
</code>
</pre>
The variable $4
contains the spans that need replacing, looking like so:
<span class="xlang"><?php</span>
<span class="php-comment">/**</span>
<span class="php-comment"> * app/Base/Controller.php</span>
<span class="php-comment"> *</span>
<span class="php-comment"> * Local base controller for application.</span>
<span class="php-comment"> */</span>
<span class="php-keyword1">use</span> Illuminate\Foundation\Bus\DispatchesJobs;
and so on.
Obviously the code needs to remain unchanged, but the spans:
<span class="whatever">leave code alone</span>
need to be removed.
I tried a nested replaceRE
but got parse errors from ApiGen.
<pre id="source">
<code>{$source|replaceRE:'~<span class="line">(\s*)(\d+):(\s*)</span>([^\\n]*(?:\\n|$))~','<span id="$2" class="l">
<a href="#$2">$1$2$3</a>{$4|replaceRE:'~<span .*?class="(.*?)">~',''|noescape}</span>'|noescape}
</code>
</pre>