From: Patrick K. O'B. <po...@us...> - 2003-02-20 14:19:56
|
Update of /cvsroot/docutils/docutils/docutils/parsers/rst/directives In directory sc8-pr-cvs1:/tmp/cvs-serv23370/docutils/parsers/rst/directives Modified Files: __init__.py body.py Log Message: Added sidebar directive. Index: __init__.py =================================================================== RCS file: /cvsroot/docutils/docutils/docutils/parsers/rst/directives/__init__.py,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- __init__.py 14 Nov 2002 02:24:57 -0000 1.17 +++ __init__.py 20 Feb 2003 14:19:53 -0000 1.18 @@ -92,6 +92,7 @@ 'tip': ('admonitions', 'tip'), 'hint': ('admonitions', 'hint'), 'warning': ('admonitions', 'warning'), + 'sidebar': ('body', 'sidebar'), 'topic': ('body', 'topic'), 'line-block': ('body', 'line_block'), 'parsed-literal': ('body', 'parsed_literal'), Index: body.py =================================================================== RCS file: /cvsroot/docutils/docutils/docutils/parsers/rst/directives/body.py,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- body.py 8 Oct 2002 01:24:51 -0000 1.8 +++ body.py 20 Feb 2003 14:19:53 -0000 1.9 @@ -13,6 +13,7 @@ import sys from docutils import nodes +from docutils.parsers.rst import directives def topic(name, arguments, options, content, lineno, @@ -39,6 +40,32 @@ topic.arguments = (1, 0, 1) topic.content = 1 + +def sidebar(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine): + if not state_machine.match_titles: + error = state_machine.reporter.error( + 'Sidebars may not be nested within sidebars or body elements.', + nodes.literal_block(block_text, block_text), line=lineno) + return [error] + if not content: + warning = state_machine.reporter.warning( + 'Content block expected for the "%s" directive; none found.' + % name, nodes.literal_block(block_text, block_text), + line=lineno) + return [warning] + title_text = arguments[0] + textnodes, messages = state.inline_text(title_text, lineno) + title = nodes.title(title_text, '', *textnodes) + text = '\n'.join(content) + sidebar_node = nodes.sidebar(text, title, *messages, **options) + if text: + state.nested_parse(content, content_offset, sidebar_node) + return [sidebar_node] + +sidebar.arguments = (1, 0, 1) +sidebar.options = {'subtitle': directives.unchanged} +sidebar.content = 1 def line_block(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine, |