<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>funcptr - meta</title>
    <subtitle>An engineer&#x27;s technical notebook</subtitle>
    <link rel="self" type="application/atom+xml" href="https://funcptr.net/category/meta/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://funcptr.net/"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2021-02-15T00:00:00+00:00</updated>
    <id>https://funcptr.net/category/meta/atom.xml</id>
    <entry xml:lang="en">
        <title>Generating stylesheets for pygments</title>
        <published>2011-11-27T00:00:00+00:00</published>
        <updated>2021-02-15T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Delta Regeer
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://funcptr.net/2011/pygments-stylesheets/"/>
        <id>https://funcptr.net/2011/pygments-stylesheets/</id>
        
        <content type="html" xml:base="https://funcptr.net/2011/pygments-stylesheets/">&lt;p&gt;Update: this blog is no longer using the same technology for deployment as
before, the below information is available for historical reasons.&lt;&#x2F;p&gt;
&lt;hr&gt;
&lt;p&gt;For this blog I am using &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;freewisdom.org&#x2F;projects&#x2F;python-markdown&#x2F;&quot;&gt;Python markdown&lt;&#x2F;a&gt; with the &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;pygments.org&#x2F;&quot;&gt;Pygments&lt;&#x2F;a&gt; plugin
that is available. Pygments does all of the code highlighting and outputs the
required &lt;code&gt;span&lt;&#x2F;code&gt; tags and inputs them within the page.&lt;&#x2F;p&gt;
&lt;p&gt;If you were to look at the &lt;code&gt;&amp;lt;div&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;&#x2F;pre&amp;gt;&amp;lt;&#x2F;div&amp;gt;&lt;&#x2F;code&gt; block that is generated
you&#x27;d see something like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;div class=&amp;quot;codehilite&amp;quot;&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;span class=&amp;quot;k&amp;quot;&amp;gt;def&amp;lt;&#x2F;span&amp;gt; &amp;lt;span class=&amp;quot;nf&amp;quot;&amp;gt;function&amp;lt;&#x2F;span&amp;gt;&amp;lt;span class=&amp;quot;p&amp;quot;&amp;gt;(&amp;lt;&#x2F;span&amp;gt;&amp;lt;span class=&amp;quot;n&amp;quot;&amp;gt;var&amp;lt;&#x2F;span&amp;gt;&amp;lt;span class=&amp;quot;o&amp;quot;&amp;gt;=&amp;lt;&#x2F;span&amp;gt;&amp;lt;span class=&amp;quot;bp&amp;quot;&amp;gt;None&amp;lt;&#x2F;span&amp;gt;&amp;lt;span class=&amp;quot;p&amp;quot;&amp;gt;):&amp;lt;&#x2F;span&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;span class=&amp;quot;k&amp;quot;&amp;gt;if&amp;lt;&#x2F;span&amp;gt; &amp;lt;span class=&amp;quot;n&amp;quot;&amp;gt;var&amp;lt;&#x2F;span&amp;gt; &amp;lt;span class=&amp;quot;ow&amp;quot;&amp;gt;is&amp;lt;&#x2F;span&amp;gt; &amp;lt;span class=&amp;quot;ow&amp;quot;&amp;gt;not&amp;lt;&#x2F;span&amp;gt; &amp;lt;span class=&amp;quot;bp&amp;quot;&amp;gt;None&amp;lt;&#x2F;span&amp;gt;&amp;lt;span class=&amp;quot;p&amp;quot;&amp;gt;:&amp;lt;&#x2F;span&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &amp;lt;span class=&amp;quot;k&amp;quot;&amp;gt;print&amp;lt;&#x2F;span&amp;gt; &amp;lt;span class=&amp;quot;n&amp;quot;&amp;gt;var&amp;lt;&#x2F;span&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;&#x2F;pre&amp;gt;&amp;lt;&#x2F;div&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;which is generated from the following snippet of code:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt; function&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt;var=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF5874;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;)&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; var&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; is not&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF5874;&quot;&gt; None&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt;        print&lt;&#x2F;span&gt;&lt;span&gt; var&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;As you see the top css &lt;code&gt;class&lt;&#x2F;code&gt; is &lt;code&gt;codehilite&lt;&#x2F;code&gt;, and then underneath that there
are a bunch of other classes such as &lt;code&gt;k&lt;&#x2F;code&gt;, &lt;code&gt;n&lt;&#x2F;code&gt;, &lt;code&gt;o&lt;&#x2F;code&gt;, and so forth. Those are all
classes that can be styled. Now one could write such a stylesheet by hand or we
can simply use one of the stylesheets that Pygments ships with.&lt;&#x2F;p&gt;
&lt;p&gt;The documentation for Pygments tells you how to get &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;pygments.org&#x2F;docs&#x2F;styles&#x2F;#builtin-styles&quot;&gt;built-in styles&lt;&#x2F;a&gt;, which
is as simple as:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; from&lt;&#x2F;span&gt;&lt;span&gt; pygments.styles&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;font-style: italic;&quot;&gt; import&lt;&#x2F;span&gt;&lt;span&gt; get_all_styles&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; styles&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C5E478;&quot;&gt; list&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #B2CCD6;&quot;&gt;get_all_styles&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C792EA;&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; styles&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;[&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;monokai&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;manni&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;perldoc&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;borland&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;colorful&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt;default&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; ...&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D9F5DD;&quot;&gt;]&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;These are all the styles that are available to you the user, now how do we get
the style into an actual &lt;code&gt;.css&lt;&#x2F;code&gt; file that we can link to in our sites HTML
file? We use the &lt;code&gt;pygmentize&lt;&#x2F;code&gt; command line tool:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #D6DEEB; background-color: #011627;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #82AAFF;font-style: italic;&quot;&gt;pygmentize&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; html&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -S&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; trac&lt;&#x2F;span&gt;&lt;span style=&quot;color: #82AAFF;&quot;&gt; -a&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; .codehilite&lt;&#x2F;span&gt;&lt;span style=&quot;color: #7FDBCA;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #ECC48D;&quot;&gt; pygments.css&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Feel free to replace &lt;code&gt;trac&lt;&#x2F;code&gt; with any of the styles you have installed on your
system. &lt;code&gt;-f&lt;&#x2F;code&gt; tells it what formatter to use, since we want it to output the css
we ask it to use the HTML formatter, &lt;code&gt;-S&lt;&#x2F;code&gt; tells &lt;code&gt;pygmentize&lt;&#x2F;code&gt; what style to
use, and &lt;code&gt;-a&lt;&#x2F;code&gt; prepends the &lt;code&gt;.codehilite&lt;&#x2F;code&gt; class before every rule (this way we
don&#x27;t pollute the whole CSS namespace with all the aforementioned class&#x27;s such
as &lt;code&gt;k&lt;&#x2F;code&gt;, &lt;code&gt;o&lt;&#x2F;code&gt;, &lt;code&gt;ow&lt;&#x2F;code&gt; and others).&lt;&#x2F;p&gt;
</content>
        
    </entry>
</feed>
