pythonhtmlpython-3.xpygments

How to customize Pygments css classes output


How do i change the classes of the Pygments output? for example, this is the output of pygments default:

<div class="highlight">
    <pre>
        <span class="kn">import</span> <span class="nn">samplemodule</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Hello World!&#39;</span><span class="p">)</span>
    </pre>
</div>

I want the output of the span elements to use the classes i provided. How do i do that?


Solution

  • Turns out it was easily done with the .replace() function. You only need to know which class is which so you can replace it with your own css class