Re: Anybody familiar with pygments ?
On Thu, May 9, 2013 at 10:40 AM, Fábio Santos fabiosantos...@gmail.com wrote: On 9 May 2013 05:19, dabaichi valben...@outlook.com wrote: And hereis the output file: That's not the output file. That is just an HTML fragment to put on your page. A full HTML file will need more things, which is the reason why you don't see color output. I want to know why output html file with no color ? Because there is no CSS. The output has a lot of span tags with classes. You are supposed to use a CSS file along with it. So, first put that output into a complete HTML document (with a head, a body...) And in that document add or link to your CSS file with the color information. I never used pygments but there may be some readily available. -- http://mail.python.org/mailman/listinfo/python-list First off, the Python code was unnecessary in this case, because it would be cheaper to use the pygmentize app included. Second off, CSS is available at https://github.com/richleland/pygments-css or by running `pygmentize -f html -O full FILE`. -- Kwpolska http://kwpolska.tk | GPG KEY: 5EAAEA16 stop html mail| always bottom-post http://asciiribbon.org| http://caliburn.nl/topposting.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Anybody familiar with pygments ?
On 9 May 2013 05:19, dabaichi valben...@outlook.com wrote: And hereis the output file: That's not the output file. That is just an HTML fragment to put on your page. A full HTML file will need more things, which is the reason why you don't see color output. I want to know why output html file with no color ? Because there is no CSS. The output has a lot of span tags with classes. You are supposed to use a CSS file along with it. So, first put that output into a complete HTML document (with a head, a body...) And in that document add or link to your CSS file with the color information. I never used pygments but there may be some readily available. -- http://mail.python.org/mailman/listinfo/python-list
Anybody familiar with pygments ?
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=highlighttabletrtd class=linenosdiv class=linenodivpre1 2 3 4 5 6 7/pre/div/tdtd class=codediv class=highlightprespan class=cp#include lt;stdio.hgt;/span span class=ktint/span span class=nfmain/spanspan class=p(/spanspan class=ktint/span span class=nargc/spanspan class=p,/span span class=ktchar/span span class=o*/span span class=nargv/spanspan class=p[])/span span class=p{/span span class=nprintf/spanspan class=p(/spanspan class=squot;This is a test!/spanspan class=se\n/spanspan class=squot;/spanspan class=p);/span span class=kreturn/span span class=mi0/spanspan 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