Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Any tool to convert Python source code to HTML?

27 views
Skip to first unread message

Aki Niimura

unread,
Feb 23, 2003, 3:16:57 PM2/23/03
to
Hello everyone,

I thought finding such was very easy but I couldn't find any pointer
in the Internet. I would like to put my Python code to my Intranet.

Instead of putting a plain text, I would like to put a HTMLized code
(with keyword coloring, simple links to def, class, ...)

I found so many articles, postings regarding to Python's HTML modules.
Also, there must be a tool to create a HTML page summarizing a class
(class name, member function, ...). But not python source code itself.

Yes, I understand putting a whole source code is not so useful for a
big complex program. But my program is not so big such that showing
the entire source code is still very helpful.

Is there any software tool to create a HTML page from Python source code?

Any info would be highly appreciated.

Best regards,
Aki Niimura

Alex Martelli

unread,
Feb 23, 2003, 3:34:04 PM2/23/03
to
Aki Niimura wrote:

> Hello everyone,
>
> I thought finding such was very easy but I couldn't find any pointer
> in the Internet. I would like to put my Python code to my Intranet.
>
> Instead of putting a plain text, I would like to put a HTMLized code
> (with keyword coloring, simple links to def, class, ...)

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52298

(most popular recipe currently in the Cookbook, apparently!)

or for somewhat-richer functionality:

http://www.norvig.com/python/py2html.html

http://www.danbala.com/python/lpy/lpy.py.html


and no doubt many others.


Alex

Brian Quinlan

unread,
Feb 23, 2003, 4:59:00 PM2/23/03
to
> Is there any software tool to create a HTML page from Python source
code?

There is a pure Python solution here:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52298

There is a (somewhat more robust) C solution here:
http://silvercity.sourceforge.net/

Just ask on this list if you need help figuring out either.

Cheers,
Brian


Irmen de Jong

unread,
Feb 23, 2003, 6:55:22 PM2/23/03
to
Aki Niimura wrote:

> Is there any software tool to create a HTML page from Python source code?

VIM! (www.vim.org)

Vim can write any file that it can syntax-colorize (Python is among the
large set of recognised file types ofcourse) as colorized HTML.

Just type in command mode:

ru syntax/2html.vim

and save the generated HTML buffer.

Irmen de Jong

Brian Quinlan

unread,
Feb 23, 2003, 6:05:40 PM2/23/03
to
> I prefer pure Python solution as I can easily fiddle if necessary.

None of the solutions are pure Python: the cookbook recipe uses the
Python tokenizer, which is written in C. Similarly, in SilverCity, only
the tokenizer is written in C.

SilverCity also corrects a few little weaknesses in the Python tokenizer
solution (*). For example, using the Python tokenizer, line
continuations are removed so continued lines will appear on the same
line in your HTML output.

* BIAS: I wrote SilverCity

Cheers,
Brian


François Pinard

unread,
Feb 23, 2003, 7:06:30 PM2/23/03
to
[Aki Niimura]

> Is there any software tool to create a HTML page from Python source code?

My usual tool for this kind of work is `enscript', probably available on
your Linux distribution, or obtainable from any GNU repository.

> Instead of putting a plain text, I would like to put a HTMLized code
> (with keyword coloring, simple links to def, class, ...)

However, `enscript' only gives you highlighting, you will not get links.

--
François Pinard http://www.iro.umontreal.ca/~pinard

Andrew Bennetts

unread,
Feb 23, 2003, 7:17:03 PM2/23/03
to
On Sun, Feb 23, 2003 at 12:16:57PM -0800, Aki Niimura wrote:
> Hello everyone,
>
> I thought finding such was very easy but I couldn't find any pointer
> in the Internet. I would like to put my Python code to my Intranet.
>
> Instead of putting a plain text, I would like to put a HTMLized code
> (with keyword coloring, simple links to def, class, ...)

Twisted has a very neat (and small!) module written by Moshe Zadka, called
twisted.python.htmlizer. It basically wraps your source inside lots of
spans tag, e.g. <span class="py-src-identifier">foo</span>. This means you
can do pretty much all the customisation you need in CSS, without touching
the htmlizer source. It works very well for the HOWTO docs on
twistedmatrix.com -- have a read through them for a demonstration of what it
can do.

-Andrew.


Brian Quinlan

unread,
Feb 23, 2003, 8:30:45 PM2/23/03
to
> Yes, I noticed it while I was customizing the code.
> (I was looking for keyword list ...)

SilverCity does allow you to use your own keywords.

> I'm using a similar tool for another language (HDL), v2html.

That looks like a very cool tool! It would be hard to create a similar
one in Python because of the lack of statically available information.

> I was hoping to have a similar one (more than just coloring ...).
> But probably I'm asking too much.

SilverCity generates hyperlinks for PEPs and URLs, but that's pretty
much all the "extra" that you get. Oh, it also allows you to do
multilingual coloring e.g. embedded SGML code can be styled as SGML, not
just given the Python string style.

> I will try SilverCity when I have a time.

Don't bother if the recipe does what you want. I'm just playing salesman
and telling you about the (probably useless) extra features available in
my model :-)

Cheers,
Brian


Terry Reedy

unread,
Feb 24, 2003, 12:04:23 AM2/24/03
to

> Is there any software tool to create a HTML page from Python source
code?

If you view source files in SourceForge CVS with browser, they come
out with language-specific colorization. IE, *.py have Python
keywords in keyword color. No idea what use. Assume not written in
Python.

TJR

Steve Holden

unread,
Feb 24, 2003, 7:47:05 AM2/24/03
to
"Brian Quinlan" <br...@sweetapp.com> wrote in message
news:mailman.1046050084...@python.org...

A common techie misconception. If you were *really* playing salesman you
would be emphasising the benefits those features would bring to your
prospect :-)

but-then-i'm-not-terrific-at-sales-either-ly y'rs - steve
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/
Register for PyCon now! http://www.python.org/pycon/reg.html

logistix

unread,
Feb 24, 2003, 9:30:11 AM2/24/03
to
aki...@pacbell.net (Aki Niimura) wrote in message news:<b714b8de.03022...@posting.google.com>...


There will be in about a week ;)

I'm polishing up my first beta of PyXR right now. It does a
reasonable job of creating cross-referenced hyperlinks. There should
be something on comp.lang.python.announce by this weekend.

Mike Meyer

unread,
Feb 24, 2003, 11:16:48 AM2/24/03
to
logi...@zworg.com (logistix) writes:

> aki...@pacbell.net (Aki Niimura) wrote in message news:<b714b8de.03022...@posting.google.com>...

> > Is there any software tool to create a HTML page from Python source code?

> I'm polishing up my first beta of PyXR right now. It does a
> reasonable job of creating cross-referenced hyperlinks. There should
> be something on comp.lang.python.announce by this weekend.

How does it do at colorizing? Or - given that there are lots of tools
to do colorizing (the cookbook solution, VIM, Emacs, enscript, and
others), how about making it ignore existing HTML tags so I can
colorize it and then use PyXR to create the xreferene links?

<mike
--
Mike Meyer <m...@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

Dave

unread,
Feb 24, 2003, 2:06:05 PM2/24/03
to
aki...@pacbell.net (Aki Niimura) wrote in message news:<b714b8de.03022...@posting.google.com>...


Hi Aki,

Hope you don't mind if I wade in with my shameless plug;

http://www.thuswise.co.uk/py2html.html

This is no relation to other "py2html"s that may have been
suggested; it's based on Xavier Defrang's string replacement recipe,
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81330 .

Easily adaptible to any other language syntax.


Best Regards,


Dave.

Erik Price

unread,
Feb 24, 2003, 10:03:36 PM2/24/03
to

[I have heard that] There are plugins for the jEdit text editor that do
this (generate an HTML representation of source code with syntax
coloring).

Erik

--
Erik Price

email: erik...@mac.com
jabber: erik...@jabber.org


Aki Niimura

unread,
Feb 25, 2003, 2:21:12 AM2/25/03
to
Hi everyone,

Thank you very much for so many replies. It is almost overwhelming.
This also indicates that there is a reasonable needs for such tool.

At this moment, I used the cookbook solution as I can easily fiddle.
After putting such HTML pages into my Intranet, I concluded coloring
was helpful but not enough. I ended up putting links into the HTML pages
manually.

I hope this kind of tool will be a part of the Python distribution.
(I'm not suggesting one tool for everyone. But one tool could cover 90%)

Cheers,
Aki-

Klaus Alexander Seistrup

unread,
Feb 25, 2003, 2:22:34 AM2/25/03
to
Aki Niimura wrote:

> Is there any software tool to create a HTML page from Python
> source code?

There's GNU source-highlight:

<http://www.gnu.org/software/src-highlite/>

Also available as a Debian package:

<http://packages.debian.org/source-highlight>


Cheers,

// Klaus

--
><> vandag, môre, altyd saam

logistix

unread,
Feb 25, 2003, 7:15:40 AM2/25/03
to
Mike Meyer <m...@mired.org> wrote in message news:<x73cmdf...@guru.mired.org>...

> logi...@zworg.com (logistix) writes:
>
> > aki...@pacbell.net (Aki Niimura) wrote in message news:<b714b8de.03022...@posting.google.com>...
> > > Is there any software tool to create a HTML page from Python source code?
> > I'm polishing up my first beta of PyXR right now. It does a
> > reasonable job of creating cross-referenced hyperlinks. There should
> > be something on comp.lang.python.announce by this weekend.
>
> How does it do at colorizing? Or - given that there are lots of tools
> to do colorizing (the cookbook solution, VIM, Emacs, enscript, and
> others), how about making it ignore existing HTML tags so I can
> colorize it and then use PyXR to create the xreferene links?
>

You need to build a syntax-tree to build the xref'd links. I would
prefer a pure python input to do this. In release one you'll be stuck
with my color scheme, but I plan to yank it out into a customizable
class eventually.

Christian Aastorp

unread,
Feb 25, 2003, 7:31:07 AM2/25/03
to
On Mon, 24 Feb 2003 16:16:48 GMT, Mike Meyer <m...@mired.org> wrote:

>logi...@zworg.com (logistix) writes:

>How does it do at colorizing? Or - given that there are lots of tools
>to do colorizing (the cookbook solution, VIM, Emacs, enscript, and
>others), how about making it ignore existing HTML tags so I can
>colorize it and then use PyXR to create the xreferene links?

Pardon my ignorance, but what is PyXR? I've googled for the term,
without finding anything relevant.

Perica Zivkovic

unread,
Feb 25, 2003, 7:42:37 AM2/25/03
to
install SciTE from http://www.scintilla.org/SciTE.html

open your python file

and then File > Export > As HTML

Miki Tebeka

unread,
Feb 25, 2003, 9:13:06 AM2/25/03
to
Hello,
> VIM! (www.vim.org)
>
> Vim can write any file that it can syntax-colorize (Python is among the
> large set of recognised file types ofcourse) as colorized HTML.
>
> Just type in command mode:
>
> ru syntax/2html.vim
>
> and save the generated HTML buffer.

You can use this script (will work for many other languages as well):
----------
#!/bin/bash

# Prepare files for code review
# Author: Miki Tebeka <teb...@cs.bgu.ac.il>

if [ $# -lt 1 ]; then
echo "usage: `basename $0` FILE[s]"
exit 1
fi

for file in $*
do
vim -c 'se nu' -c 'so $VIMRUNTIME/syntax/2html.vim' -c w -c 'qa!' $file
done
---------

HTH.
Miki

Dave Kuhlman

unread,
Feb 25, 2003, 12:37:52 PM2/25/03
to
Erik Price wrote:

>
> On Monday, February 24, 2003, at 12:04 AM, Terry Reedy wrote:
>
>>> Is there any software tool to create a HTML page from Python source
>> code?

The SciTE text editor can export to HTML. It does colored syntax
high-lighting for a variety of languages. SciTE is at:

http://www.scintilla.org/SciTE.html

- Dave

>>
>> If you view source files in SourceForge CVS with browser, they come
>> out with language-specific colorization. IE, *.py have Python
>> keywords in keyword color. No idea what use. Assume not written in
>> Python.
>
> [I have heard that] There are plugins for the jEdit text editor that do
> this (generate an HTML representation of source code with syntax
> coloring).
>
>
>
> Erik
>
>
>
>
>

--
Dave Kuhlman
dkuh...@rexx.com
http://www.rexx.com/~dkuhlman

0 new messages