Python2Html regex question

G

Gerard Flanagan

Hello

I've been using the Html Formatter at
http://www.manoli.net/csharpformat to format c# code (paste your code
into the box, click the button and get html/css). Is there anything
similar for Python code, does anyone know?

Either way, the (c#) source is available for the above formatter and it
looks like it would be straightforward to create a Python formatter by
extending a base class and providing the following three things:

1) a list of python keywords
2) a regex to match python comments
3) a regex to match python strings

Even my limited talents can handle the first, can anyone help me with
2) and 3)?

C# uses '@' where Python uses 'r' as a 'raw-input' prefix for regex's,
but I'm assuming the expressions themselves are the same in both
languages?

Thanks in advance.
 
F

Fredrik Lundh

Gerard said:
Either way, the (c#) source is available for the above formatter and it
looks like it would be straightforward to create a Python formatter by
extending a base class and providing the following three things:

1) a list of python keywords

import keyword
print keyword.kwlist
2) a regex to match python comments

import tokenize
print tokenize.Comment
3) a regex to match python strings

import tokenize
print tokenize.String
print tokenize.Triple

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,318
Members
47,998
Latest member
GretaCjy4

Latest Threads

Top