::

from docutils import core
def rst2html(rst):
overrides = {'input_encoding': 'unicode',
'doctitle_xform': 1,
'initial_header_level': 1}
parts = core.publish_parts(
source=rst,
writer_name='html', settings_overrides=overrides)
fragment = parts['html_body']
return fragment

summarized from earlier entries
easy to just include when and where needed
see also:
http://code.activestate.com/recipes/193890/

#http://docutils.sourceforge.net/docutils/examples.py
def html_parts(input_string, source_path=None, destination_path=None,
input_encoding='unicode', doctitle=1, initial_header_level=1):
"""
Given an input string, returns a dictionary of HTML document parts.

Dictionary keys are the names of parts, and values are Unicode strings;
encoding is up to the client.

Parameters:

- `input_string`: A multi-line text string; required.
- `source_path`: Path to the source file or object. Optional, but useful
for diagnostic output (system messages).
- `destination_path`: Path to the file or object which will receive the
output; optional. Used for determining relative paths (stylesheets,
source links, etc.).
- `input_encoding`: The encoding of `input_string`. If it is an encoded
8-bit string, provide the correct encoding. If it is a Unicode string,
use "unicode", the default.
- `doctitle`: Disable the promotion of a lone top-level section title to
document title (and subsequent section title to document subtitle
promotion); enabled by default.
- `initial_header_level`: The initial level for header elements (e.g. 1
for "

").
"""
overrides = {'input_encoding': input_encoding,
'doctitle_xform': doctitle,
'initial_header_level': initial_header_level}
parts = core.publish_parts(
source=input_string, source_path=source_path,
destination_path=destination_path,
writer_name='html', settings_overrides=overrides)
return parts

def html_body(input_string, source_path=None, destination_path=None,
input_encoding='unicode', output_encoding='unicode',
doctitle=1, initial_header_level=1):
"""
Given an input string, returns an HTML fragment as a string.

The return value is the contents of the element.

Parameters (see `html_parts()` for the remainder):

- `output_encoding`: The desired encoding of the output. If a Unicode
string is desired, use the default value of "unicode" .
"""
parts = html_parts(
input_string=input_string, source_path=source_path,
destination_path=destination_path,
input_encoding=input_encoding, doctitle=doctitle,
initial_header_level=initial_header_level)
fragment = parts['html_body']
if output_encoding != 'unicode':
fragment = fragment.encode(output_encoding)
return fragment

def text2html(content):
"""
not sure if there is a way to do this with docutils, but just want
to have html line breaks where there are new lines (\n ->
\n)
"""
#http://docutils.sourceforge.net/docs/user/rst/quickref.html
new = ''
for line in content.split('\n'):

#\s matches whitespace
#\S matches alphanumeric
#
#if it has characters, make it a 'line block'
#http://docutils.sourceforge.net/docs/user/rst/quickref.html
if re.search('\S', line):
new += "| " + line + '\n'
html = html_body(new)
return literal(html)


http://www.google.com/search?hl=en&q=restructuredtext+add+line+breaks&btnG=Search
restructuredtext add line breaks - Google Search
http://pypi.python.org/pypi?%3Aaction=search&term=templates
Python Package Index : Index of Packages Matching 'templates'
http://pypi.python.org/pypi/rest2web/0.5.0%20Final
Python Package Index : rest2web 0.5.0 Final
http://docutils.sourceforge.net/README.html#quick-start
README: Docutils
http://docutils.sourceforge.net/docs/user/tools.html#the-tools
Docutils Front-End Tools
http://docutils.sourceforge.net/docs/user/tools.html#rst2html-py
Docutils Front-End Tools
http://docutils.sourceforge.net/docs/api/publisher.html
The Docutils Publisher
http://docutils.sourceforge.net/docutils/examples.py
http://docutils.sourceforge.net/docutils/examples.py
http://docutils.sourceforge.net/docs/api/publisher.html#publish-parts-details
The Docutils Publisher
http://docutils.sourceforge.net/docs/user/tools.html#configuration-file
Docutils Front-End Tools
http://docutils.sourceforge.net/docs/howto/html-stylesheets.html
Writing HTML (CSS) Stylesheets for Docutils
http://docutils.sourceforge.net/FAQ.html
Docutils FAQ (Frequently Asked Questions)
http://docutils.sourceforge.net/FAQ.html#are-there-any-weblog-blog-projects-that-use-restructuredtext-syntax
Docutils FAQ (Frequently Asked Questions)
http://docutils.sourceforge.net/FAQ.html#how-can-i-make-a-literal-block-with-some-formatting
Docutils FAQ (Frequently Asked Questions)
http://docutils.sourceforge.net/docs/user/rst/quickref.html
Quick reStructuredText
http://www.google.com/search?q=python+regular+expressions&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:official&client=firefox-a
python regular expressions - Google Search
http://docs.python.org/lib/module-re.html
4.2 re -- Regular expression operations
http://www.amk.ca/python/howto/regex/
Regular Expression HOWTO

adding in helpers to memory/web/browser/lib/helper.py

restructured text is part of the docutils library

in that library, there are scripts to do conversions in examples:

http://docutils.sourceforge.net/README.html#quick-start

#2008.07.06 11:43:02 ubuntu@ubuntu:~
sudo easy_install docutils

edit:
/usr/bin/rst2html.py
# EASY-INSTALL-SCRIPT: 'docutils==0.4','rst2html.py'
__requires__ = 'docutils==0.4'
import pkg_resources
pkg_resources.run_script('docutils==0.4', 'rst2html.py')


/usr/lib/python2.5/site-packages/
cd /usr/lib/python2.5/site-packages/docutils-0.4-py2.5.egg/docutils/

from docutils.core import publish_cmdline, default_description


description = ('Generates HTML from standalone reStructuredText '
'sources (for testing purposes). ' + default_description)

publish_cmdline(writer_name='html', description=description)

vi core.py

http://docutils.sf.net/docs/api/publisher.html