patch for rst.py
Jan-Wijbrand Kolman <[email protected]>
| Newsgroups | gmane.comp.web.pyblosxom.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, I'd like to propose the changes in the attached patch to the rst.py entry parser. It allows for more control over the rendered HTML, by introducing two optional configuration parameters. The default settings should keep the behaviour of the parser identical to that of the current version. Triggered by Will's call for additional fixes and because it wasn't clear to me who actually is maintaining this entry parser I thought to post the patch here. I hope this is not inappropiate. If there's anything unclear or if you have any remark, please let me know. kind regards, jw -- Jan-Wijbrand Kolman [email protected] http://jw.n--tree.net/
rst.py.patch
(text/plain, 2.7 KB)
--- pyblosxom/plugins/rst.py 2005-06-21 20:23:14.000000000 +0200
+++ pyblosxom-dev/plugins/rst.py 2005-10-29 21:49:22.000000000 +0200
@@ -22,6 +22,18 @@
#parser reST
My main story...
+There's two optional configuration parameter you can for additional control
+over the rendered HTML::
+
+ # To set the starting level for the rendered heading elements.
+ # 1 is the default.
+ py['reST_initial_header_level'] = 1
+
+ # Enable or disable the promotion of a lone top-level section title to
+ # document title (and subsequent section title to document subtitle
+ # promotion); enabled by default.
+ py['reST_transform_doctitle'] = 1
+
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without restriction,
@@ -47,7 +59,7 @@
__version__ = '$Id: rst.py,v 1.5.4.1 2005/05/04 04:48:44 twl Exp $'
__author__ = 'Sean Bowman <sean dot bowman at acm dot org>'
-from docutils.core import publish_string
+from docutils.core import publish_parts
from Pyblosxom import tools
def cb_entryparser(args):
@@ -55,24 +67,30 @@
return args
def cb_preformat(args):
- if args['parser'] == PREFORMATTER_ID:
- return parse(''.join(args['story']))
-
-def parse(story):
- html = publish_string(story, writer_name='html')
- return html[html.find('<body>') + 6:html.find('</body>')]
+ parser = args.get('parser')
+ if parser is None or parser != PREFORMATTER_ID:
+ return
+ return parse(''.join(args['story']), args['request'])
+
+def parse(story, request):
+ config = request.getConfiguration()
+ initial_header_level = config.get('reST_initial_header_level', 1)
+ transform_doctile = config.get('reST_transform_doctitle', 1)
+ settings = {
+ 'initial_header_level': initial_header_level,
+ 'doctitle_xform': transform_doctile
+ }
+ parts = publish_parts(
+ story, writer_name='html', settings_overrides=settings)
+ return parts['html_body']
def readfile(filename, request):
entryData = {}
- d = open(filename).read()
- title = d.split('\n')[0]
- d = d[len(title):]
- body = parse(d)
- entryData = {'title': title,
- 'body': body}
+ lines = open(filename).readlines()
+ title = lines.pop(0)
+ body = parse(''.join(lines), request)
+ entryData = {'title': title, 'body': body}
# Call the postformat callbacks
- tools.run_callback('postformat',
- {'request': request,
- 'entry_data': entryData})
-
+ tools.run_callback(
+ 'postformat', {'request': request, 'entry_data': entryData})
return entryData