pythonhtmlcsspygments

How to include pygments in vimwiki html /smarty file?


I'm using vimwiki which allows me to add a smarty/html template file along with the css. I know how to generate the css file with pygments but the problem is how do I get that css to include all the classes based on the input of the <pre> tag?

For example if the pre tag is this:

<pre class='pygments highlight'>
echom 'hello'
function! DeleteUnloadedBuffers()
for buf in getbufinfoprettyprint
    if ! buf.loaded 
    execute 'bd ' . buf.bufnr
    endif
    echom repeat('-',78)
    endfor
endfunction!
</pre>

I need for it to produce this, so that it can have syntax highlighting:

<div class="highlight"><pre><span></span><span class="k">echom</span> <span class="s1">&#39;hello&#39;</span>
<span class="k">function</span><span class="p">!</span> DeleteUnloadedBuffers<span class="p">()</span>
<span class="k">for</span> <span class="k">buf</span> <span class="k">in</span> getbufinfoprettyprint
    <span class="k">if</span> <span class="p">!</span> <span class="k">buf</span>.loaded 
    execute <span class="s1">&#39;bd &#39;</span> . <span class="k">buf</span>.bufnr
    <span class="k">endif</span>
    <span class="k">echom</span> repeat<span class="p">(</span><span class="s1">&#39;-&#39;</span><span class="p">,</span><span class="m">78</span><span class="p">)</span>
    <span class="k">endfor</span>
<span class="p">&lt;</span>/<span class="k">pre</span><span class="p">&gt;</span>
</pre></div>

I'm guessing the answer is somewhere along the lines of...

%pygments%
<pre class='pygments highlight'>
print('foo')
</pre>

I could write a python script and import pygments and do a regex for pre tags but that would be overkill just to get some syntax highlighting. For now, I've been using prettyprint which looks to be an abandon repo on github but it works.


Solution

  • Ended up using bs4 to solve this issue.