Skip to content

Clean up code sample generated by MediaWiki SyntaxHighlight GeSHi extension to get raw code  #19

@renoirb

Description

@renoirb

Code sample in html output when using <syntaxHighlight> in wiki content;

<syntaxHighlight>
<div class="container">
    <div class="box bottom">This box is at the bottom with z-index set to auto.</div>
    <div class="box middle">This box is in the middle with z-index set to auto.</div>
    <div class="box top">This box is at the top with z-index set to auto.</div>
</div>
</syntaxHighlight>

Becomes this in the generated HTML;

<div>
 <p><span class="language">HTML</span>
 </p>
 <pre>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr"><div class="html5 source-html5"><pre class="de1"><span class="sc2">&lt;<span class="kw
2">div</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;container&quot;</span>&gt;</span>
    <span class="sc2">&lt;<span class="kw2">div</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;box to
p&quot;</span>&gt;</span>This box is at the top with z-index set to 30.<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">div</span>&gt;</span>
    <span class="sc2">&lt;<span class="kw2">div</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;box middle-level-one&quot;</span>&gt;</span>This box is in the middle level 1 with z-index set to 20.<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">div</span>&gt;</span>
    <span class="sc2">&lt;<span class="kw2">div</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;box middle-level-two&quot;</span>&gt;</span>This box is in at middle level 2 with z-index set to 20.<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">div</span>&gt;</span>
    <span class="sc2">&lt;<span class="kw2">div</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;box bottom&quot;</span>&gt;</span>This box is at the bottom with z-index set to 10.<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">div</span>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">div</span>&gt;</span></pre></div></div>

Which makes it hard to work with code samples within a static site.

The desired output for static site generator, so we can use a syntax highlighter out of the box, is:

<pre class="language-html5" data-lang="html5">
<div class="container">
    <div class="box bottom">This box is at the bottom with z-index set to auto.</div>
    <div class="box middle">This box is in the middle with z-index set to auto.</div>
    <div class="box top">This box is at the top with z-index set to auto.</div>
</div>
</pre>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions