diff options
author | wiemann <wiemann@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2006-01-09 20:44:25 +0000 |
---|---|---|
committer | wiemann <wiemann@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2006-01-09 20:44:25 +0000 |
commit | d77fdfef70e08114f57cbef5d91707df8717ea9f (patch) | |
tree | 49444e3486c0c333cb7b33dfa721296c08ee4ece /docutils/parsers/rst/directives/admonitions.py | |
parent | 53cd16ca6ca5f638cbe5956988e88f9339e355cf (diff) | |
parent | 3993c4097756e9885bcfbd07cb1cc1e4e95e50e4 (diff) | |
download | docutils-0.4.tar.gz |
Release 0.4: tagging released revisiondocutils-0.4
git-svn-id: http://svn.code.sf.net/p/docutils/code/tags/docutils-0.4@4268 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils/parsers/rst/directives/admonitions.py')
-rw-r--r-- | docutils/parsers/rst/directives/admonitions.py | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/docutils/parsers/rst/directives/admonitions.py b/docutils/parsers/rst/directives/admonitions.py new file mode 100644 index 000000000..73ca18161 --- /dev/null +++ b/docutils/parsers/rst/directives/admonitions.py @@ -0,0 +1,90 @@ +# Author: David Goodger +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Admonition directives. +""" + +__docformat__ = 'reStructuredText' + + +from docutils.parsers.rst import states, directives +from docutils import nodes + + +def make_admonition(node_class, name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine): + if not content: + error = state_machine.reporter.error( + 'The "%s" admonition is empty; content required.' % (name), + nodes.literal_block(block_text, block_text), line=lineno) + return [error] + text = '\n'.join(content) + admonition_node = node_class(text) + if arguments: + title_text = arguments[0] + textnodes, messages = state.inline_text(title_text, lineno) + admonition_node += nodes.title(title_text, '', *textnodes) + admonition_node += messages + if options.has_key('class'): + classes = options['class'] + else: + classes = ['admonition-' + nodes.make_id(title_text)] + admonition_node['classes'] += classes + state.nested_parse(content, content_offset, admonition_node) + return [admonition_node] + +def admonition(*args): + return make_admonition(nodes.admonition, *args) + +admonition.arguments = (1, 0, 1) +admonition.options = {'class': directives.class_option} +admonition.content = 1 + +def attention(*args): + return make_admonition(nodes.attention, *args) + +attention.content = 1 + +def caution(*args): + return make_admonition(nodes.caution, *args) + +caution.content = 1 + +def danger(*args): + return make_admonition(nodes.danger, *args) + +danger.content = 1 + +def error(*args): + return make_admonition(nodes.error, *args) + +error.content = 1 + +def hint(*args): + return make_admonition(nodes.hint, *args) + +hint.content = 1 + +def important(*args): + return make_admonition(nodes.important, *args) + +important.content = 1 + +def note(*args): + return make_admonition(nodes.note, *args) + +note.content = 1 + +def tip(*args): + return make_admonition(nodes.tip, *args) + +tip.content = 1 + +def warning(*args): + return make_admonition(nodes.warning, *args) + +warning.content = 1 |