From 66dca2559e93fca4d221305e15099438b00ddc5a Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 7 Aug 2002 01:06:41 +0000 Subject: Added to project. Contains the "topic" directive. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@463 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 docutils/parsers/rst/directives/body.py (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py new file mode 100644 index 000000000..3cdc1d382 --- /dev/null +++ b/docutils/parsers/rst/directives/body.py @@ -0,0 +1,47 @@ +#! /usr/bin/env python + +""" +:Author: David Goodger +:Contact: goodger@users.sourceforge.net +:Revision: $Revision$ +:Date: $Date$ +:Copyright: This module has been placed in the public domain. + +Directives for additional body elements. +""" + +__docformat__ = 'reStructuredText' + +from docutils import nodes + + +def topic(match, type_name, data, state, state_machine, attributes): + lineno = state_machine.abs_line_number() + initial_offset = state_machine.line_offset + indented, indent, line_offset, blank_finish \ + = state_machine.get_first_known_indented(match.end()) + blocktext = '\n'.join(state_machine.input_lines[ + initial_offset : line_offset + len(indented)]) + if not state_machine.match_titles: + error = state_machine.reporter.error( + 'Topics may not be nested within body elements (line %s).' + % lineno, '', nodes.literal_block(blocktext, blocktext)) + return [error], blank_finish + if not indented: + return [], blank_finish + title_text = indented.pop(0) + textnodes, messages = state.inline_text(title_text, lineno) + title = nodes.title(title_text, '', *textnodes) + if indented: + if indented[0].strip(): + warning = state_machine.reporter.warning( + 'The second line of a topic block must be blank (line %s).' + % (lineno + 1 + line_offset - initial_offset), '') + messages.append(warning) + text = '\n'.join(indented) + else: + text = '' + topic_node = nodes.topic(text, title, *messages) + if text: + state.nested_parse(indented, line_offset, topic_node) + return [topic_node], blank_finish -- cgit v1.2.1 From 0e0945034dac85d840bcf15384b533a41ece4d49 Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 16 Aug 2002 00:32:36 +0000 Subject: Added the "line-block" and "parsed-literal" directives. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@537 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index 3cdc1d382..98f04d237 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -12,6 +12,8 @@ Directives for additional body elements. __docformat__ = 'reStructuredText' + +import sys from docutils import nodes @@ -45,3 +47,37 @@ def topic(match, type_name, data, state, state_machine, attributes): if text: state.nested_parse(indented, line_offset, topic_node) return [topic_node], blank_finish + + +def parsed_literal(match, type_name, data, state, state_machine, attributes): + lineno = state_machine.abs_line_number() + initial_offset = state_machine.line_offset + indented, indent, line_offset, blank_finish \ + = state_machine.get_first_known_indented(match.end()) + while indented and not indented[-1].strip(): + indented.pop() + blocktext = '\n'.join(state_machine.input_lines[ + initial_offset : line_offset + len(indented)]) + if not indented: + return [], blank_finish + text = '\n'.join(indented) + textnodes, messages = state.inline_text(text, lineno) + literal = nodes.literal_block(text, '', *textnodes) + return [literal] + messages, blank_finish + + +def line_block(match, type_name, data, state, state_machine, attributes): + lineno = state_machine.abs_line_number() + initial_offset = state_machine.line_offset + indented, indent, line_offset, blank_finish \ + = state_machine.get_first_known_indented(match.end()) + while indented and not indented[-1].strip(): + indented.pop() + blocktext = '\n'.join(state_machine.input_lines[ + initial_offset : line_offset + len(indented)]) + if not indented: + return [], blank_finish + text = '\n'.join(indented) + textnodes, messages = state.inline_text(text, lineno) + line_block_node = nodes.line_block(text, '', *textnodes) + return [line_block_node] + messages, blank_finish -- cgit v1.2.1 From 09f7c959981a2e5f51ab2c28b1388cb4d91c2bff Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 16 Aug 2002 01:49:44 +0000 Subject: simplified git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@547 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index 98f04d237..d60bb98e9 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -49,35 +49,22 @@ def topic(match, type_name, data, state, state_machine, attributes): return [topic_node], blank_finish -def parsed_literal(match, type_name, data, state, state_machine, attributes): +def parsed_literal(match, type_name, data, state, state_machine, attributes, + node_class=nodes.literal_block): lineno = state_machine.abs_line_number() initial_offset = state_machine.line_offset indented, indent, line_offset, blank_finish \ = state_machine.get_first_known_indented(match.end()) while indented and not indented[-1].strip(): indented.pop() - blocktext = '\n'.join(state_machine.input_lines[ - initial_offset : line_offset + len(indented)]) if not indented: return [], blank_finish text = '\n'.join(indented) textnodes, messages = state.inline_text(text, lineno) - literal = nodes.literal_block(text, '', *textnodes) - return [literal] + messages, blank_finish + node = node_class(text, '', *textnodes) + return [node] + messages, blank_finish def line_block(match, type_name, data, state, state_machine, attributes): - lineno = state_machine.abs_line_number() - initial_offset = state_machine.line_offset - indented, indent, line_offset, blank_finish \ - = state_machine.get_first_known_indented(match.end()) - while indented and not indented[-1].strip(): - indented.pop() - blocktext = '\n'.join(state_machine.input_lines[ - initial_offset : line_offset + len(indented)]) - if not indented: - return [], blank_finish - text = '\n'.join(indented) - textnodes, messages = state.inline_text(text, lineno) - line_block_node = nodes.line_block(text, '', *textnodes) - return [line_block_node] + messages, blank_finish + return parsed_literal(match, type_name, data, state, state_machine, + attributes, node_class=nodes.line_block) -- cgit v1.2.1 From f0b8b4564b132e5d6622d98c56b93deeabffc1cc Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 17 Aug 2002 01:22:29 +0000 Subject: Simplified and improved the "line-block" and "parsed-literal" code. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@548 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index d60bb98e9..ad603dae6 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -49,22 +49,24 @@ def topic(match, type_name, data, state, state_machine, attributes): return [topic_node], blank_finish -def parsed_literal(match, type_name, data, state, state_machine, attributes, - node_class=nodes.literal_block): +def line_block(match, type_name, data, state, state_machine, attributes, + node_class=nodes.line_block): lineno = state_machine.abs_line_number() - initial_offset = state_machine.line_offset indented, indent, line_offset, blank_finish \ = state_machine.get_first_known_indented(match.end()) while indented and not indented[-1].strip(): indented.pop() if not indented: - return [], blank_finish + warning = state_machine.reporter.warning( + 'Text block expected for the "%s" directive after line %s; none ' + 'found.' % (type_name, lineno)) + return [warning], blank_finish text = '\n'.join(indented) textnodes, messages = state.inline_text(text, lineno) node = node_class(text, '', *textnodes) return [node] + messages, blank_finish -def line_block(match, type_name, data, state, state_machine, attributes): - return parsed_literal(match, type_name, data, state, state_machine, - attributes, node_class=nodes.line_block) +def parsed_literal(match, type_name, data, state, state_machine, attributes): + return line_block(match, type_name, data, state, state_machine, + attributes, node_class=nodes.literal_block) -- cgit v1.2.1 From f14be8cb9b05636ef65e921923ecd74a7cd8304d Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 27 Aug 2002 00:40:51 +0000 Subject: Changed "attribute" to "option" for directives/extensions. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@597 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index ad603dae6..9ba25844e 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -17,7 +17,7 @@ import sys from docutils import nodes -def topic(match, type_name, data, state, state_machine, attributes): +def topic(match, type_name, data, state, state_machine, option_presets): lineno = state_machine.abs_line_number() initial_offset = state_machine.line_offset indented, indent, line_offset, blank_finish \ @@ -49,7 +49,7 @@ def topic(match, type_name, data, state, state_machine, attributes): return [topic_node], blank_finish -def line_block(match, type_name, data, state, state_machine, attributes, +def line_block(match, type_name, data, state, state_machine, option_presets, node_class=nodes.line_block): lineno = state_machine.abs_line_number() indented, indent, line_offset, blank_finish \ @@ -67,6 +67,7 @@ def line_block(match, type_name, data, state, state_machine, attributes, return [node] + messages, blank_finish -def parsed_literal(match, type_name, data, state, state_machine, attributes): +def parsed_literal(match, type_name, data, state, state_machine, + option_presets): return line_block(match, type_name, data, state, state_machine, - attributes, node_class=nodes.literal_block) + option_presets, node_class=nodes.literal_block) -- cgit v1.2.1 From a024b2b067ec8a092d783c9baed4b43dd5898d56 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 4 Sep 2002 01:33:22 +0000 Subject: Converted system messages to use the new "line" attribute. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@622 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index 9ba25844e..7d74e7a2b 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -23,11 +23,11 @@ def topic(match, type_name, data, state, state_machine, option_presets): indented, indent, line_offset, blank_finish \ = state_machine.get_first_known_indented(match.end()) blocktext = '\n'.join(state_machine.input_lines[ - initial_offset : line_offset + len(indented)]) + initial_offset : line_offset + len(indented) - 1]) if not state_machine.match_titles: error = state_machine.reporter.error( - 'Topics may not be nested within body elements (line %s).' - % lineno, '', nodes.literal_block(blocktext, blocktext)) + 'Topics may not be nested within body elements.', '', + nodes.literal_block(blocktext, blocktext), line=lineno) return [error], blank_finish if not indented: return [], blank_finish @@ -37,15 +37,15 @@ def topic(match, type_name, data, state, state_machine, option_presets): if indented: if indented[0].strip(): warning = state_machine.reporter.warning( - 'The second line of a topic block must be blank (line %s).' - % (lineno + 1 + line_offset - initial_offset), '') + 'The second line of a topic block must be blank.', + line=lineno + 1 + line_offset - initial_offset) messages.append(warning) text = '\n'.join(indented) else: text = '' topic_node = nodes.topic(text, title, *messages) if text: - state.nested_parse(indented, line_offset, topic_node) + state.nested_parse(indented, line_offset + 1, topic_node) return [topic_node], blank_finish @@ -58,8 +58,8 @@ def line_block(match, type_name, data, state, state_machine, option_presets, indented.pop() if not indented: warning = state_machine.reporter.warning( - 'Text block expected for the "%s" directive after line %s; none ' - 'found.' % (type_name, lineno)) + 'Text block expected for the "%s" directive; none found.' + % type_name, line=lineno) return [warning], blank_finish text = '\n'.join(indented) textnodes, messages = state.inline_text(text, lineno) -- cgit v1.2.1 From 7b12a12a016617200529e8b611ad2f2a866ad7f9 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 2 Oct 2002 03:17:43 +0000 Subject: Updated all directive functions to new API, including better reporting. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@744 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 89 +++++++++++++++------------------ 1 file changed, 40 insertions(+), 49 deletions(-) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index 7d74e7a2b..55be7e36f 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -1,12 +1,10 @@ -#! /usr/bin/env python +# Author: David Goodger +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. """ -:Author: David Goodger -:Contact: goodger@users.sourceforge.net -:Revision: $Revision$ -:Date: $Date$ -:Copyright: This module has been placed in the public domain. - Directives for additional body elements. """ @@ -17,57 +15,50 @@ import sys from docutils import nodes -def topic(match, type_name, data, state, state_machine, option_presets): - lineno = state_machine.abs_line_number() - initial_offset = state_machine.line_offset - indented, indent, line_offset, blank_finish \ - = state_machine.get_first_known_indented(match.end()) - blocktext = '\n'.join(state_machine.input_lines[ - initial_offset : line_offset + len(indented) - 1]) +def topic(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine): if not state_machine.match_titles: error = state_machine.reporter.error( - 'Topics may not be nested within body elements.', '', - nodes.literal_block(blocktext, blocktext), line=lineno) - return [error], blank_finish - if not indented: - return [], blank_finish - title_text = indented.pop(0) + 'Topics may not be nested within topics 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) - if indented: - if indented[0].strip(): - warning = state_machine.reporter.warning( - 'The second line of a topic block must be blank.', - line=lineno + 1 + line_offset - initial_offset) - messages.append(warning) - text = '\n'.join(indented) - else: - text = '' + text = '\n'.join(content) topic_node = nodes.topic(text, title, *messages) if text: - state.nested_parse(indented, line_offset + 1, topic_node) - return [topic_node], blank_finish + state.nested_parse(content, content_offset, topic_node) + return [topic_node] +topic.arguments = (1, 0, 1) +topic.content = 1 -def line_block(match, type_name, data, state, state_machine, option_presets, +def line_block(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine, node_class=nodes.line_block): - lineno = state_machine.abs_line_number() - indented, indent, line_offset, blank_finish \ - = state_machine.get_first_known_indented(match.end()) - while indented and not indented[-1].strip(): - indented.pop() - if not indented: + if not content: warning = state_machine.reporter.warning( - 'Text block expected for the "%s" directive; none found.' - % type_name, line=lineno) - return [warning], blank_finish - text = '\n'.join(indented) - textnodes, messages = state.inline_text(text, lineno) - node = node_class(text, '', *textnodes) - return [node] + messages, blank_finish + 'Content block expected for the "%s" directive; none found.' + % name, nodes.literal_block(block_text, block_text), line=lineno) + return [warning] + text = '\n'.join(content) + text_nodes, messages = state.inline_text(text, lineno) + node = node_class(text, '', *text_nodes) + return [node] + messages + +line_block.content = 1 +def parsed_literal(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine): + return line_block(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine, + node_class=nodes.literal_block) -def parsed_literal(match, type_name, data, state, state_machine, - option_presets): - return line_block(match, type_name, data, state, state_machine, - option_presets, node_class=nodes.literal_block) +parsed_literal.content = 1 -- cgit v1.2.1 From 3b4c2985f3efb3e92507e3067995f7a313bee040 Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 8 Oct 2002 01:25:17 +0000 Subject: Updated (Reporter API). git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@769 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index 55be7e36f..8bc2d7a4f 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -19,13 +19,13 @@ def topic(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine): if not state_machine.match_titles: error = state_machine.reporter.error( - 'Topics may not be nested within topics or body elements.', '', + 'Topics may not be nested within topics 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), + % name, nodes.literal_block(block_text, block_text), line=lineno) return [warning] title_text = arguments[0] -- cgit v1.2.1 From 9d4fcb00e8f6023b8ab16b20679198ffbd1acf45 Mon Sep 17 00:00:00 2001 From: pobrien Date: Thu, 20 Feb 2003 14:19:55 +0000 Subject: Added sidebar directive. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1193 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index 8bc2d7a4f..9793e0bc3 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -13,6 +13,7 @@ __docformat__ = 'reStructuredText' import sys from docutils import nodes +from docutils.parsers.rst import directives def topic(name, arguments, options, content, lineno, @@ -40,6 +41,32 @@ def topic(name, arguments, options, content, lineno, 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, node_class=nodes.line_block): -- cgit v1.2.1 From 813c817e2696f9eba43e10cd147ba4a04244a1d1 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 20 Feb 2003 22:35:49 +0000 Subject: sidebar improvements git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1196 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 41 +++++++++++++-------------------- 1 file changed, 16 insertions(+), 25 deletions(-) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index 9793e0bc3..f24edb325 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -17,10 +17,12 @@ from docutils.parsers.rst import directives def topic(name, arguments, options, content, lineno, - content_offset, block_text, state, state_machine): + content_offset, block_text, state, state_machine, + node_class=nodes.topic): if not state_machine.match_titles: error = state_machine.reporter.error( - 'Topics may not be nested within topics or body elements.', + 'The "%s" directive may not be used within topics, sidebars, ' + 'or body elements.' % name, nodes.literal_block(block_text, block_text), line=lineno) return [error] if not content: @@ -31,37 +33,26 @@ def topic(name, arguments, options, content, lineno, return [warning] title_text = arguments[0] textnodes, messages = state.inline_text(title_text, lineno) - title = nodes.title(title_text, '', *textnodes) + titles = [nodes.title(title_text, '', *textnodes)] + if options.has_key('subtitle'): + textnodes, more_messages = state.inline_text(options['subtitle'], + lineno) + titles.append(nodes.subtitle(options['subtitle'], '', *textnodes)) + messages.extend(more_messages) text = '\n'.join(content) - topic_node = nodes.topic(text, title, *messages) + node = node_class(text, *(titles + messages)) if text: - state.nested_parse(content, content_offset, topic_node) - return [topic_node] + state.nested_parse(content, content_offset, node) + return [node] 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] + return topic(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine, + node_class=nodes.sidebar) sidebar.arguments = (1, 0, 1) sidebar.options = {'subtitle': directives.unchanged} -- cgit v1.2.1 From 0e4f3603edbe99da05838c005078328d55fe4ec3 Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 24 May 2003 20:47:32 +0000 Subject: Added "rubric", "epigraph", and "highlights" directives. Added "class" options to "topic", "sidebar", "line-block", and "parsed-literal". git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1330 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 36 +++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index f24edb325..bc3f5b742 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -41,11 +41,14 @@ def topic(name, arguments, options, content, lineno, messages.extend(more_messages) text = '\n'.join(content) node = node_class(text, *(titles + messages)) + if options.has_key('class'): + node.set_class(options['class']) if text: state.nested_parse(content, content_offset, node) return [node] topic.arguments = (1, 0, 1) +topic.options = {'class': directives.class_option} topic.content = 1 def sidebar(name, arguments, options, content, lineno, @@ -55,7 +58,8 @@ def sidebar(name, arguments, options, content, lineno, node_class=nodes.sidebar) sidebar.arguments = (1, 0, 1) -sidebar.options = {'subtitle': directives.unchanged} +sidebar.options = {'subtitle': directives.unchanged, + 'class': directives.class_option} sidebar.content = 1 def line_block(name, arguments, options, content, lineno, @@ -68,9 +72,10 @@ def line_block(name, arguments, options, content, lineno, return [warning] text = '\n'.join(content) text_nodes, messages = state.inline_text(text, lineno) - node = node_class(text, '', *text_nodes) + node = node_class(text, '', *text_nodes, **options) return [node] + messages +line_block.options = {'class': directives.class_option} line_block.content = 1 def parsed_literal(name, arguments, options, content, lineno, @@ -79,4 +84,31 @@ def parsed_literal(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine, node_class=nodes.literal_block) +parsed_literal.options = {'class': directives.class_option} parsed_literal.content = 1 + +def rubric(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine): + rubric_text = arguments[0] + textnodes, messages = state.inline_text(rubric_text, lineno) + rubric = nodes.rubric(rubric_text, '', *textnodes, **options) + return [rubric] + messages + +rubric.arguments = (1, 0, 1) +rubric.options = {'class': directives.class_option} + +def epigraph(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine): + block_quote, messages = state.block_quote(content, content_offset) + block_quote.set_class('epigraph') + return [block_quote] + messages + +epigraph.content = 1 + +def highlights(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine): + block_quote, messages = state.block_quote(content, content_offset) + block_quote.set_class('highlights') + return [block_quote] + messages + +highlights.content = 1 -- cgit v1.2.1 From f43900b985a1c3fae98d7a99847250750039b6b4 Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 3 Jun 2003 02:16:59 +0000 Subject: Added "pull-quote" directive. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1373 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index bc3f5b742..c2fd6b99d 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -112,3 +112,11 @@ def highlights(name, arguments, options, content, lineno, return [block_quote] + messages highlights.content = 1 + +def pull_quote(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine): + block_quote, messages = state.block_quote(content, content_offset) + block_quote.set_class('pull-quote') + return [block_quote] + messages + +pull_quote.content = 1 -- cgit v1.2.1 From 5fa4d3b2f10a3fb657a03e04733b4f0a346b6dcc Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 9 Jul 2003 18:00:50 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1578 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index c2fd6b99d..47e1423c8 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -58,7 +58,7 @@ def sidebar(name, arguments, options, content, lineno, node_class=nodes.sidebar) sidebar.arguments = (1, 0, 1) -sidebar.options = {'subtitle': directives.unchanged, +sidebar.options = {'subtitle': directives.unchanged_required, 'class': directives.class_option} sidebar.content = 1 -- cgit v1.2.1 From 74bc7e3a7d5fe2ece9a48ffb4d368879e986b1bc Mon Sep 17 00:00:00 2001 From: goodger Date: Mon, 12 Jan 2004 16:27:25 +0000 Subject: added "table" directive git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1799 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index 47e1423c8..122b2ccc4 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -120,3 +120,38 @@ def pull_quote(name, arguments, options, content, lineno, return [block_quote] + messages pull_quote.content = 1 + +def table(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine): + 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] + if arguments: + title_text = arguments[0] + text_nodes, messages = state.inline_text(title_text, lineno) + title = nodes.title(title_text, '', *text_nodes) + else: + title = None + node = nodes.Element() # anonymous container for parsing + text = '\n'.join(content) + state.nested_parse(content, content_offset, node) + if len(node) != 1 or not isinstance(node[0], nodes.table): + error = state_machine.reporter.error( + 'Error parsing content block for the "%s" directive: ' + 'exactly one table expected.' + % name, nodes.literal_block(block_text, block_text), + line=lineno) + return [error] + table_node = node[0] + if options.has_key('class'): + table_node.set_class(options['class']) + if title: + table_node.insert(0, title) + return [table_node] + +table.arguments = (0, 1, 1) +table.options = {'class': directives.class_option} +table.content = 1 -- cgit v1.2.1 From 2c868af6838d363ed0ca7fc5571b515622ecf3e2 Mon Sep 17 00:00:00 2001 From: reggie Date: Mon, 22 Mar 2004 01:12:45 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1857 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 1 + 1 file changed, 1 insertion(+) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index 122b2ccc4..6c29d037e 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -34,6 +34,7 @@ def topic(name, arguments, options, content, lineno, title_text = arguments[0] textnodes, messages = state.inline_text(title_text, lineno) titles = [nodes.title(title_text, '', *textnodes)] + # sidebar uses this code if options.has_key('subtitle'): textnodes, more_messages = state.inline_text(options['subtitle'], lineno) -- cgit v1.2.1 From 16bbd9314c3d45a98742ce519ddd160516334c5a Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 17 Jun 2004 16:08:46 +0000 Subject: fixed omission git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2296 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index 6c29d037e..4fc015b21 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -136,6 +136,7 @@ def table(name, arguments, options, content, lineno, title = nodes.title(title_text, '', *text_nodes) else: title = None + messages = [] node = nodes.Element() # anonymous container for parsing text = '\n'.join(content) state.nested_parse(content, content_offset, node) @@ -151,7 +152,7 @@ def table(name, arguments, options, content, lineno, table_node.set_class(options['class']) if title: table_node.insert(0, title) - return [table_node] + return [table_node] + messages table.arguments = (0, 1, 1) table.options = {'class': directives.class_option} -- cgit v1.2.1 From c059e577bf3d4e3a261faee5d824f76a06a942a2 Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 18 Jun 2004 21:35:35 +0000 Subject: moved "table" directive to tables.py git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2305 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 38 +-------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index 4fc015b21..c63ac8aef 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -1,5 +1,5 @@ # Author: David Goodger -# Contact: goodger@users.sourceforge.net +# Contact: goodger@python.org # Revision: $Revision$ # Date: $Date$ # Copyright: This module has been placed in the public domain. @@ -121,39 +121,3 @@ def pull_quote(name, arguments, options, content, lineno, return [block_quote] + messages pull_quote.content = 1 - -def table(name, arguments, options, content, lineno, - content_offset, block_text, state, state_machine): - 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] - if arguments: - title_text = arguments[0] - text_nodes, messages = state.inline_text(title_text, lineno) - title = nodes.title(title_text, '', *text_nodes) - else: - title = None - messages = [] - node = nodes.Element() # anonymous container for parsing - text = '\n'.join(content) - state.nested_parse(content, content_offset, node) - if len(node) != 1 or not isinstance(node[0], nodes.table): - error = state_machine.reporter.error( - 'Error parsing content block for the "%s" directive: ' - 'exactly one table expected.' - % name, nodes.literal_block(block_text, block_text), - line=lineno) - return [error] - table_node = node[0] - if options.has_key('class'): - table_node.set_class(options['class']) - if title: - table_node.insert(0, title) - return [table_node] + messages - -table.arguments = (0, 1, 1) -table.options = {'class': directives.class_option} -table.content = 1 -- cgit v1.2.1 From e9392a97370514aa39851a14552563be3b5c8584 Mon Sep 17 00:00:00 2001 From: david_abrahams Date: Wed, 23 Jun 2004 02:17:11 +0000 Subject: Fix the line numbering of nodes produced by line_block directives. This is a total shot-in-the-dark, since it's unclear why lineno is 97 and content_offset is the right line number. Without some description of the protocol I can't really know, but it seems to be working... for now. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2361 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index c63ac8aef..bfe2e695f 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -15,7 +15,25 @@ import sys from docutils import nodes from docutils.parsers.rst import directives - +# Directive Handler Functions +# +# What they do is blah blah +# +# They are called by blah blah after being looked up blah blah +# +# Parameter Required Type Role +# ============== ============= ============================= +# name str ??? +# arguments ??? ??? +# options ??? ??? +# content ??? ??? +# lineno ??? ??? +# content_offset ??? ??? +# block_text ??? ??? +# state ??? ??? +# state_machine ??? ??? +# node_class ??? ??? + def topic(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine, node_class=nodes.topic): @@ -74,6 +92,7 @@ def line_block(name, arguments, options, content, lineno, text = '\n'.join(content) text_nodes, messages = state.inline_text(text, lineno) node = node_class(text, '', *text_nodes, **options) + node.line = content_offset return [node] + messages line_block.options = {'class': directives.class_option} -- cgit v1.2.1 From 5522058d7b68c055e68752ff4a5f3ff2138238af Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 23 Jun 2004 02:29:02 +0000 Subject: line number == (line offset + 1); check module docstring of directives/__init__.py for detailed instructions git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2363 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index bfe2e695f..9e93b3aff 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -15,24 +15,6 @@ import sys from docutils import nodes from docutils.parsers.rst import directives -# Directive Handler Functions -# -# What they do is blah blah -# -# They are called by blah blah after being looked up blah blah -# -# Parameter Required Type Role -# ============== ============= ============================= -# name str ??? -# arguments ??? ??? -# options ??? ??? -# content ??? ??? -# lineno ??? ??? -# content_offset ??? ??? -# block_text ??? ??? -# state ??? ??? -# state_machine ??? ??? -# node_class ??? ??? def topic(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine, @@ -92,7 +74,7 @@ def line_block(name, arguments, options, content, lineno, text = '\n'.join(content) text_nodes, messages = state.inline_text(text, lineno) node = node_class(text, '', *text_nodes, **options) - node.line = content_offset + node.line = content_offset + 1 return [node] + messages line_block.options = {'class': directives.class_option} -- cgit v1.2.1 From ea6bc82584ed1a16423aadc5d88af6baca1cda47 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 23 Jun 2004 02:35:59 +0000 Subject: docstrings git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2364 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index 9e93b3aff..85adda981 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -6,6 +6,8 @@ """ Directives for additional body elements. + +See `docutils.parsers.rst.directives` for API details. """ __docformat__ = 'reStructuredText' -- cgit v1.2.1 From ef553a1fe8a6033a97e97a4c72d07632de6fbd7c Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 5 Oct 2004 01:21:47 +0000 Subject: Converted the line-block directive to use the new structure. Extracted the old line-block functionality to the ``block`` function (still used). git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2689 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 40 ++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index 85adda981..9d40331ca 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -66,31 +66,51 @@ sidebar.options = {'subtitle': directives.unchanged_required, sidebar.content = 1 def line_block(name, arguments, options, content, lineno, - content_offset, block_text, state, state_machine, - node_class=nodes.line_block): + content_offset, block_text, state, state_machine): 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] - text = '\n'.join(content) - text_nodes, messages = state.inline_text(text, lineno) - node = node_class(text, '', *text_nodes, **options) - node.line = content_offset + 1 - return [node] + messages + block = nodes.line_block() + node_list = [block] + for line_text in content: + text_nodes, messages = state.inline_text(line_text.strip(), + lineno + content_offset) + line = nodes.line(line_text, '', *text_nodes) + if line_text.strip(): + line.indent = len(line_text) - len(line_text.lstrip()) + block += line + node_list.extend(messages) + content_offset += 1 + state.nest_line_block_lines(block) + return node_list line_block.options = {'class': directives.class_option} line_block.content = 1 def parsed_literal(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine): - return line_block(name, arguments, options, content, lineno, - content_offset, block_text, state, state_machine, - node_class=nodes.literal_block) + return block(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine, + node_class=nodes.literal_block) parsed_literal.options = {'class': directives.class_option} parsed_literal.content = 1 +def block(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine, node_class): + 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] + text = '\n'.join(content) + text_nodes, messages = state.inline_text(text, lineno) + node = node_class(text, '', *text_nodes, **options) + node.line = content_offset + 1 + return [node] + messages + def rubric(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine): rubric_text = arguments[0] -- cgit v1.2.1 From 54ce70ca93e577ba2bdddfb18bbae692cfdb57aa Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 20 Oct 2004 13:46:31 +0000 Subject: Added ``compound`` directive. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2732 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index 9d40331ca..cfc3c04f4 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -144,3 +144,20 @@ def pull_quote(name, arguments, options, content, lineno, return [block_quote] + messages pull_quote.content = 1 + +def compound(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine): + text = '\n'.join(content) + if not text: + error = state_machine.reporter.error( + 'The "%s" directive is empty; content required.' % name, + nodes.literal_block(block_text, block_text), line=lineno) + return [error] + node = nodes.compound(text) + if options.has_key('class'): + node.set_class(options['class']) + state.nested_parse(content, content_offset, node) + return [node] + +compound.options = {'class': directives.class_option} +compound.content = 1 -- cgit v1.2.1 From 232e7e218a2c4b14569bd11890ad26ab2d5cb76c Mon Sep 17 00:00:00 2001 From: wiemann Date: Sat, 2 Apr 2005 21:57:06 +0000 Subject: removed nodes.Element.set_class() method; directives.class_option now returns a *list* of classes; added test for :figclass: option of figure directive; the raw role's :format: option is now "unchanged", not "class_option"; some fixes: the :class: option should now always be propagated correctly from directives git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3155 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index cfc3c04f4..117311720 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -16,6 +16,7 @@ __docformat__ = 'reStructuredText' import sys from docutils import nodes from docutils.parsers.rst import directives +from docutils.parsers.rst.roles import set_classes def topic(name, arguments, options, content, lineno, @@ -44,8 +45,7 @@ def topic(name, arguments, options, content, lineno, messages.extend(more_messages) text = '\n'.join(content) node = node_class(text, *(titles + messages)) - if options.has_key('class'): - node.set_class(options['class']) + node['classes'] += options.get('class', []) if text: state.nested_parse(content, content_offset, node) return [node] @@ -72,7 +72,7 @@ def line_block(name, arguments, options, content, lineno, 'Content block expected for the "%s" directive; none found.' % name, nodes.literal_block(block_text, block_text), line=lineno) return [warning] - block = nodes.line_block() + block = nodes.line_block(classes=options.get('class', [])) node_list = [block] for line_text in content: text_nodes, messages = state.inline_text(line_text.strip(), @@ -91,6 +91,7 @@ line_block.content = 1 def parsed_literal(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine): + set_classes(options) return block(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine, node_class=nodes.literal_block) @@ -124,7 +125,7 @@ rubric.options = {'class': directives.class_option} def epigraph(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine): block_quote, messages = state.block_quote(content, content_offset) - block_quote.set_class('epigraph') + block_quote['classes'].append('epigraph') return [block_quote] + messages epigraph.content = 1 @@ -132,7 +133,7 @@ epigraph.content = 1 def highlights(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine): block_quote, messages = state.block_quote(content, content_offset) - block_quote.set_class('highlights') + block_quote['classes'].append('highlights') return [block_quote] + messages highlights.content = 1 @@ -140,7 +141,7 @@ highlights.content = 1 def pull_quote(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine): block_quote, messages = state.block_quote(content, content_offset) - block_quote.set_class('pull-quote') + block_quote['classes'].append('pull-quote') return [block_quote] + messages pull_quote.content = 1 @@ -154,8 +155,7 @@ def compound(name, arguments, options, content, lineno, nodes.literal_block(block_text, block_text), line=lineno) return [error] node = nodes.compound(text) - if options.has_key('class'): - node.set_class(options['class']) + node['classes'] += options.get('class', []) state.nested_parse(content, content_offset, node) return [node] -- cgit v1.2.1 From a65d49465f32f45cc8152ccfdd0ee4d26c398353 Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 9 Apr 2005 01:32:29 +0000 Subject: allow topics within sidebars; no topics within body elements git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3199 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index 117311720..61c58daad 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -22,9 +22,10 @@ from docutils.parsers.rst.roles import set_classes def topic(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine, node_class=nodes.topic): - if not state_machine.match_titles: + if not (state_machine.match_titles + or isinstance(state_machine.node, nodes.sidebar)): error = state_machine.reporter.error( - 'The "%s" directive may not be used within topics, sidebars, ' + 'The "%s" directive may not be used within topics ' 'or body elements.' % name, nodes.literal_block(block_text, block_text), line=lineno) return [error] -- cgit v1.2.1 From f74332157ab86e93794a4e9566f6737aefa7328d Mon Sep 17 00:00:00 2001 From: goodger Date: Mon, 11 Apr 2005 23:16:11 +0000 Subject: added checks for recursive sidebars git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3206 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index 61c58daad..28682328a 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -57,6 +57,11 @@ topic.content = 1 def sidebar(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine): + if isinstance(state_machine.node, nodes.sidebar): + error = state_machine.reporter.error( + 'The "%s" directive may not be used within a sidebar element.' + % name, nodes.literal_block(block_text, block_text), line=lineno) + return [error] return topic(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine, node_class=nodes.sidebar) -- cgit v1.2.1 From 5eaa35732246484d010b80d2848eba8cd77158d8 Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 28 Oct 2005 16:12:56 +0000 Subject: added the "container" element & directive, a generic container git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3963 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/body.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'docutils/parsers/rst/directives/body.py') diff --git a/docutils/parsers/rst/directives/body.py b/docutils/parsers/rst/directives/body.py index 28682328a..2ff89e617 100644 --- a/docutils/parsers/rst/directives/body.py +++ b/docutils/parsers/rst/directives/body.py @@ -167,3 +167,30 @@ def compound(name, arguments, options, content, lineno, compound.options = {'class': directives.class_option} compound.content = 1 + +def container(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine): + text = '\n'.join(content) + if not text: + error = state_machine.reporter.error( + 'The "%s" directive is empty; content required.' % name, + nodes.literal_block(block_text, block_text), line=lineno) + return [error] + try: + if arguments: + classes = directives.class_option(arguments[0]) + else: + classes = [] + except ValueError: + error = state_machine.reporter.error( + 'Invalid class attribute value for "%s" directive: "%s".' + % (name, arguments[0]), + nodes.literal_block(block_text, block_text), line=lineno) + return [error] + node = nodes.container(text) + node['classes'].extend(classes) + state.nested_parse(content, content_offset, node) + return [node] + +container.arguments = (0, 1, 1) +container.content = 1 -- cgit v1.2.1