[Zope-Checkins] CVS: Zope/lib/python/reStructuredText -
__init__.py:1.7.2.4
Christian 'Tiran' Heimes
heimes at faho.rwth-aachen.de
Fri May 14 10:54:52 EDT 2004
Update of /cvs-repository/Zope/lib/python/reStructuredText
In directory cvs.zope.org:/tmp/cvs-serv2161/lib/python/reStructuredText
Modified Files:
Tag: Zope-2_7-branch
__init__.py
Log Message:
Added a render() method to reStructuredText which returns the rendered parts and the warning object
Added default configuration values to App.config
=== Zope/lib/python/reStructuredText/__init__.py 1.7.2.3 => 1.7.2.4 ===
--- Zope/lib/python/reStructuredText/__init__.py:1.7.2.3 Thu May 13 12:20:04 2004
+++ Zope/lib/python/reStructuredText/__init__.py Fri May 14 10:54:52 2004
@@ -25,7 +25,7 @@
default_input_encoding = getConfiguration().rest_input_encoding or default_enc
# starting level for <H> elements (default behaviour inside Zope is <H3>)
-default_level = int(os.environ.get('STX_DEFAULT_LEVEL', 3))
+default_level = 3
initial_header_level = getConfiguration().rest_header_level or default_level
# default language
@@ -42,6 +42,38 @@
def write(self, message):
self.messages.append(message)
+def render(src,
+ writer='html4css1',
+ report_level=1,
+ stylesheet='default.css',
+ input_encoding=default_input_encoding,
+ output_encoding=default_output_encoding,
+ language_code=default_lang,
+ initial_header_level = initial_header_level,
+ settings = {}):
+ """get the rendered parts of the document the and warning object
+ """
+ # Docutils settings:
+ settings = settings.copy()
+ settings['input_encoding'] = input_encoding
+ settings['output_encoding'] = output_encoding
+ settings['stylesheet'] = stylesheet
+ settings['language_code'] = language_code
+ # starting level for <H> elements:
+ settings['initial_header_level'] = initial_header_level
+ # set the reporting level to something sane:
+ settings['report_level'] = report_level
+ # don't break if we get errors:
+ settings['halt_level'] = 6
+ # remember warnings:
+ settings['warning_stream'] = warning_stream = Warnings()
+
+ parts = publish_parts(source=src, writer_name=writer,
+ settings_overrides=settings,
+ config_section='zope application')
+
+ return parts, warning_stream
+
def HTML(src,
writer='html4css1',
report_level=1,
@@ -49,9 +81,9 @@
input_encoding=default_input_encoding,
output_encoding=default_output_encoding,
language_code=default_lang,
+ initial_header_level = initial_header_level,
warnings = None,
settings = {}):
-
""" render HTML from a reStructuredText string
- 'src' -- string containing a valid reST document
@@ -70,39 +102,34 @@
- 'language_code' - docutils language
+ - 'initial_header_level' - level of the first header tag
+
- 'warnings' - will be overwritten with a string containing the warnings
- 'settings' - dict of settings to pass in to Docutils, with priority
"""
- # Docutils settings:
- settings = settings.copy()
- settings['input_encoding'] = input_encoding
- settings['output_encoding'] = output_encoding
- settings['stylesheet'] = stylesheet
- settings['language_code'] = language_code
- # starting level for <H> elements:
- settings['initial_header_level'] = initial_header_level
- # set the reporting level to something sane:
- settings['report_level'] = report_level
- # don't break if we get errors:
- settings['halt_level'] = 6
- # remember warnings:
- settings['warning_stream'] = warning_stream = Warnings()
-
- parts = publish_parts(source=src, writer_name=writer,
- settings_overrides=settings,
- config_section='zope application')
-
- output = ('<h%(level)s class="title">%(title)s</h%(level)s>\n%(body)s'
- % {'level': initial_header_level,
- 'title': parts['title'],
- 'body': parts['body']}).encode(output_encoding)
+ parts, warning_stream = render(src,
+ writer = writer,
+ report_level = report_level,
+ stylesheet = stylesheet,
+ input_encoding = input_encoding,
+ output_encoding = output_encoding,
+ language_code=language_code,
+ initial_header_level = initial_header_level,
+ settings = settings)
+
+ output = ('<h%(level)s class="title">%(title)s</h%(level)s>\n'
+ '%(docinfo)s%(body)s' % {
+ 'level': initial_header_level,
+ 'title': parts['title'],
+ 'docinfo': parts['docinfo'],
+ 'body': parts['body']
+ }).encode(output_encoding)
- # what to do with this? (not used in the original code)
warnings = ''.join(warning_stream.messages)
return output
-__all__ = ("HTML", )
+__all__ = ("HTML", 'render')
More information about the Zope-Checkins
mailing list