Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the css for a pygments formatter?

I'm using pygments in the basic manner from http://pygments.org/docs/quickstart/

My formatter is created like this:

                formatter = HtmlFormatter(cssclass="codehilite", linenos='table',
                    linenostart = lineno - len(excerpt) + 1,
                    hl_lines = important_lines,
                    style='colorful')           

It works fine but I don't get any CSS from the output, just the classes. Where do I get the CSS? I want to put it in the <head> of my HTML file so I don't need a separate .css file. All I get from pygments.highlight() is this:

<table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre>44
45
46
47
48
49
50
51
52
53
54
55
56
57</pre></div></td><td class="code"><div class="codehilite"><pre><span class="cm">/* *********** Interrupt Service Routines *********************************** */</span>

<span class="cm">/**</span>
<span class="cm"> * UART1_RX interrupt service routine.</span>
<span class="cm"> * Clears the UARTRX interrupt flag and disables the interrupt.</span>
<span class="cm"> */</span>
<span class="n">UART1_RXISR_FUNCTION_HEADER</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">UART1_DISABLE_IRQ_RX</span><span class="p">;</span>
    <span class="n">UART1_CLEAR_IRQ_RX_FLAG</span><span class="p">;</span>
<span class="p">}</span>

<span class="o">/**</span> 
 <span class="o">*</span> <span class="n">UART1_TX</span> <span class="n">interrupt</span> <span class="n">service</span> <span class="n">routine</span><span class="p">.</span>
</pre></div>
</td></tr></table>
like image 585
Jason S Avatar asked Oct 15 '25 09:10

Jason S


1 Answers

Unless you use the full=True option in the formatter, you can get the CSS like this:

the_css = formatter.get_style_defs()

Then you can insert it in your html header.

like image 64
lorenzog Avatar answered Oct 16 '25 22:10

lorenzog



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!