Hello guys:
pygments version: 1.6
python version :3.3.1(64bits, use msi installer install)
os:windows 7 (64bits)
Hereis my python source code:

#!/usr/bin/env python
#-*- coding=utf-8 -*-

import os
import sys
from pygments import highlight as html_highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
from pygments.styles import get_style_by_name

def highlight(filename):
   formatter = HtmlFormatter(linenos=True, style="vim")
   filename_split = filename.split('.')

   if len(filename_split) == 1:
       return None

   lexer = get_lexer_by_name(filename_split[len(filename_split) - 1])

   try:
       with open(filename, 'r') as fp:
           content = fp.read()
   except Exception:
       return None

   html_content = html_highlight(content, lexer, formatter)
   return html_content

def main():
   filename = r'test.c'
   print(highlight(filename))

if __name__ == "__main__":
   main()


Here is test.c source code:
#include <stdio.h>

int main(int argc, char * argv[])
{
   printf("This is a test!\n");
   return 0;
}

And hereis the output file:
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4
5
6
7</pre></div></td><td class="code"><div class="highlight"><pre><span class="cp">#include &lt;stdio.h&gt;</span>

<span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span> <span class="n">argv</span><span class="p">[])</span>
<span class="p">{</span>
<span class="n">printf</span><span class="p">(</span><span class="s">&quot;This is a test!</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
</td></tr></table>

It looks like:
1 #include <stdio.h>
2
3 int main(int argc, char * argv[])
4 {
5     printf("This is a test!\n");
6     return 0;
7 }
8
with no color in firefox (20.0.1)

I want to know why output html file with no color ?
Is my code error ?

Best regard!
--peipei

--- news://freenews.netfront.net/ - complaints: n...@netfront.net ---
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to