[Zope-Checkins] CVS: Zope/lib/python/reStructuredText -
__init__.py:1.7.2.2.4.1 html4zope.py:1.1.2.1.8.1
Christian 'Tiran' Heimes
heimes at faho.rwth-aachen.de
Sat Apr 24 19:00:19 EDT 2004
Update of /cvs-repository/Zope/lib/python/reStructuredText
In directory cvs.zope.org:/tmp/cvs-serv25228/lib/python/reStructuredText
Modified Files:
Tag: tiran-restfixing-branch
__init__.py html4zope.py
Log Message:
Added rest-header-level configuration option
Changed rest HTML parser to use less ugly tricks
=== Zope/lib/python/reStructuredText/__init__.py 1.7.2.2 => 1.7.2.2.4.1 ===
--- Zope/lib/python/reStructuredText/__init__.py:1.7.2.2 Tue Mar 23 01:57:22 2004
+++ Zope/lib/python/reStructuredText/__init__.py Sat Apr 24 18:59:48 2004
@@ -16,14 +16,21 @@
__all__ = ("HTML", )
import sys, os
-import docutils.core
-from docutils.io import StringOutput, StringInput
+from docutils.core import Publisher
+from docutils import io, writers
from App.config import getConfiguration
+# get encoding
default_enc = sys.getdefaultencoding()
default_output_encoding = getConfiguration().rest_output_encoding or default_enc
default_input_encoding = getConfiguration().rest_input_encoding or default_enc
+# add html4zope to the docutils.writers
+import html4zope
+writers.html4zope = html4zope
+sys.modules['docutils.writers.html4zope'] = html4zope
+
+
class Warnings:
def __init__(self):
@@ -37,7 +44,8 @@
report_level=1,
stylesheet='default.css',
input_encoding=default_input_encoding,
- output_encoding=default_output_encoding):
+ output_encoding=default_output_encoding,
+ **kwargs):
""" render HTML from a reStructuredText string
@@ -52,48 +60,41 @@
- 'input_encoding' - encoding of the reST input string
- 'output_encoding' - encoding of the rendered HTML output
+
+ - 'kwargs' - more keyword args which are applied to the parser
"""
-
- pub = docutils.core.Publisher()
+ pub = Publisher(source_class=io.StringInput,
+ destination_class=io.StringOutput
+ )
+
+ # set reader and writer. Needs to be done before settings
pub.set_reader('standalone', None, 'restructuredtext')
pub.set_writer(writer)
- # go with the defaults
- pub.get_settings()
-
- pub.settings.stylesheet = stylesheet
-
- # this is needed, but doesn't seem to do anything
- pub.settings._destination = ''
-
- # set the reporting level to something sane
- pub.settings.report_level = report_level
-
- # don't break if we get errors
- pub.settings.halt_level = 6
-
- # remember warnings
- pub.settings.warning_stream = Warnings()
-
- # input
- pub.source = StringInput(source=src, encoding=input_encoding)
-
- # output - not that it's needed
- pub.destination = StringOutput(encoding=output_encoding)
-
+ # update settings for kwargs
+ settings = pub.get_settings()
+ kwargs.update({
+ 'stylesheet' : stylesheet,
+ '_destination' : None, # this is needed, but doesn't seem to do anything
+ 'report_level' : report_level,
+ 'halt_level' : 6, # don't break if we get errors
+ 'warning_stream' : Warnings(),
+ 'input_encoding' : input_encoding,
+ 'output_encoding' : output_encoding,
+ })
+ settings._update(kwargs, 'loose')
+
+ # set source and destination
+ pub.set_source(source=src)
+ pub.set_destination()
+
# parse!
document = pub.reader.read(pub.source, pub.parser, pub.settings)
-
# transform
pub.apply_transforms(document)
-
+
warnings = ''.join(pub.settings.warning_stream.messages)
# do the format
return pub.writer.write(document, pub.destination)
-from docutils import writers
-import html4zope
-
-writers.html4zope = html4zope
-sys.modules['docutils.writers.html4zope'] = html4zope
=== Zope/lib/python/reStructuredText/html4zope.py 1.1.2.1 => 1.1.2.1.8.1 ===
--- Zope/lib/python/reStructuredText/html4zope.py:1.1.2.1 Sun Nov 30 11:17:04 2003
+++ Zope/lib/python/reStructuredText/html4zope.py Sat Apr 24 18:59:48 2004
@@ -16,7 +16,9 @@
from docutils.writers.html4css1 import Writer as CSS1Writer, HTMLTranslator as CSS1HTMLTranslator
import os
-default_level = int(os.environ.get('STX_DEFAULT_LEVEL', 3))
+from App.config import getConfiguration
+default_level = getConfiguration().rest_header_level
+print "REST: %s " % default_level
class Writer(CSS1Writer):
def __init__(self):
More information about the Zope-Checkins
mailing list