summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwiemann <wiemann@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2005-04-02 21:57:06 +0000
committerwiemann <wiemann@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2005-04-02 21:57:06 +0000
commit232e7e218a2c4b14569bd11890ad26ab2d5cb76c (patch)
tree07b11700826288d3bf1f75b8c0e061aae646ffe1
parent2149d14d2dce1fde4ee9fc12d50d9552d57721db (diff)
downloaddocutils-232e7e218a2c4b14569bd11890ad26ab2d5cb76c.tar.gz
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
-rw-r--r--HISTORY.txt1
-rw-r--r--docutils/nodes.py4
-rw-r--r--docutils/parsers/rst/directives/__init__.py4
-rw-r--r--docutils/parsers/rst/directives/admonitions.py6
-rw-r--r--docutils/parsers/rst/directives/body.py16
-rw-r--r--docutils/parsers/rst/directives/images.py8
-rw-r--r--docutils/parsers/rst/directives/parts.py4
-rw-r--r--docutils/parsers/rst/directives/tables.py9
-rw-r--r--docutils/parsers/rst/roles.py4
-rw-r--r--docutils/transforms/misc.py3
-rw-r--r--docutils/transforms/parts.py2
-rw-r--r--docutils/writers/html4css1.py24
-rwxr-xr-xtest/test_parsers/test_rst/test_directives/test_figures.py3
13 files changed, 41 insertions, 47 deletions
diff --git a/HISTORY.txt b/HISTORY.txt
index 8de210214..2bc6e02ed 100644
--- a/HISTORY.txt
+++ b/HISTORY.txt
@@ -41,6 +41,7 @@ Changes Since 0.3.7
- Added ``attr_defaults`` dictionary for default attribute values.
- Added empty list as default value for the following attributes:
``ids``, ``names``, ``dupnames``, ``classes``, and ``backrefs``.
+ - Removed ``Element.set_class()`` method.
* docutils/languages/nl.py: Added to project; Dutch mappings by
Martijn Pieters.
diff --git a/docutils/nodes.py b/docutils/nodes.py
index cbc01cba6..d347d9dda 100644
--- a/docutils/nodes.py
+++ b/docutils/nodes.py
@@ -595,10 +595,6 @@ class Element(Node):
def copy(self):
return self.__class__(**self.attributes)
- def set_class(self, name):
- """Add a new name to the "class" attribute."""
- self['classes'].append(name.lower())
-
def note_referenced_by(self, name=None, id=None):
"""Note that this Element has been referenced by its name
`name` or id `id`."""
diff --git a/docutils/parsers/rst/directives/__init__.py b/docutils/parsers/rst/directives/__init__.py
index b8207599f..05f552edd 100644
--- a/docutils/parsers/rst/directives/__init__.py
+++ b/docutils/parsers/rst/directives/__init__.py
@@ -284,7 +284,7 @@ def nonnegative_int(argument):
def class_option(argument):
"""
- Convert the argument into an ID-compatible string and return it.
+ Convert the argument into a list of ID-compatible strings and return it.
(Directive option conversion function.)
Raise ``ValueError`` if no argument is found.
@@ -298,7 +298,7 @@ def class_option(argument):
if not class_name:
raise ValueError('cannot make "%s" into a class name' % name)
class_names.append(class_name)
- return ' '.join(class_names)
+ return class_names
unicode_pattern = re.compile(
r'(?:0x|x|\\x|U\+?|\\u)([0-9a-f]+)$|&#x([0-9a-f]+);$', re.IGNORECASE)
diff --git a/docutils/parsers/rst/directives/admonitions.py b/docutils/parsers/rst/directives/admonitions.py
index 8e3a92895..73ca18161 100644
--- a/docutils/parsers/rst/directives/admonitions.py
+++ b/docutils/parsers/rst/directives/admonitions.py
@@ -30,10 +30,10 @@ def make_admonition(node_class, name, arguments, options, content, lineno,
admonition_node += nodes.title(title_text, '', *textnodes)
admonition_node += messages
if options.has_key('class'):
- class_value = options['class']
+ classes = options['class']
else:
- class_value = 'admonition-' + nodes.make_id(title_text)
- admonition_node.set_class(class_value)
+ classes = ['admonition-' + nodes.make_id(title_text)]
+ admonition_node['classes'] += classes
state.nested_parse(content, content_offset, admonition_node)
return [admonition_node]
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]
diff --git a/docutils/parsers/rst/directives/images.py b/docutils/parsers/rst/directives/images.py
index 76d0d75eb..d4cd20a7f 100644
--- a/docutils/parsers/rst/directives/images.py
+++ b/docutils/parsers/rst/directives/images.py
@@ -15,6 +15,7 @@ import sys
from docutils import nodes, utils
from docutils.parsers.rst import directives, states
from docutils.nodes import whitespace_normalize_name
+from docutils.parsers.rst.roles import set_classes
try:
import Image # PIL
@@ -45,6 +46,7 @@ def image(name, arguments, options, content, lineno,
else: # malformed target
messages.append(data) # data is a system message
del options['target']
+ set_classes(options)
image_node = nodes.image(block_text, **options)
if reference_node:
reference_node += image_node
@@ -64,7 +66,7 @@ image.options = {'alt': directives.unchanged,
def figure(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
figwidth = options.setdefault('figwidth')
- figclass = options.setdefault('figclass')
+ figclasses = options.setdefault('figclass')
del options['figwidth']
del options['figclass']
(image_node,) = image(name, arguments, options, content, lineno,
@@ -84,8 +86,8 @@ def figure(name, arguments, options, content, lineno,
figure_node['width'] = i.size[0]
elif figwidth is not None:
figure_node['width'] = figwidth
- if figclass:
- figure_node.set_class(figclass)
+ if figclasses:
+ figure_node['classes'] += figclasses
if content:
node = nodes.Element() # anonymous container for parsing
state.nested_parse(content, content_offset, node)
diff --git a/docutils/parsers/rst/directives/parts.py b/docutils/parsers/rst/directives/parts.py
index 217def5b6..c87c239ec 100644
--- a/docutils/parsers/rst/directives/parts.py
+++ b/docutils/parsers/rst/directives/parts.py
@@ -43,9 +43,7 @@ def contents(name, arguments, options, content, lineno,
topic = nodes.topic(classes=['contents'])
- cls = options.get('class')
- if cls:
- topic.set_class(cls)
+ topic['classes'] += options.get('class', [])
if title:
name = title.astext()
diff --git a/docutils/parsers/rst/directives/tables.py b/docutils/parsers/rst/directives/tables.py
index e47c9f9e4..8f16beda0 100644
--- a/docutils/parsers/rst/directives/tables.py
+++ b/docutils/parsers/rst/directives/tables.py
@@ -53,8 +53,7 @@ def table(name, arguments, options, content, lineno,
line=lineno)
return [error]
table_node = node[0]
- if options.has_key('class'):
- table_node.set_class(options['class'])
+ table_node['classes'] += options.get('class', [])
if title:
table_node.insert(0, title)
return [table_node] + messages
@@ -147,8 +146,7 @@ def csv_table(name, arguments, options, content, lineno,
return [error]
table = (col_widths, table_head, table_body)
table_node = state.build_table(table, content_offset)
- if options.has_key('class'):
- table_node.set_class(options['class'])
+ table_node['classes'] += options.get('class', [])
if title:
table_node.insert(0, title)
return [table_node] + messages
@@ -342,8 +340,7 @@ def list_table(name, arguments, options, content, lineno,
except SystemMessagePropagation, detail:
return [detail.args[0]]
table_node = build_table_from_list(table_data, col_widths, header_rows)
- if options.has_key('class'):
- table_node.set_class(options['class'])
+ table_node['classes'] += options.get('class', [])
if title:
table_node.insert(0, title)
return [table_node] + messages
diff --git a/docutils/parsers/rst/roles.py b/docutils/parsers/rst/roles.py
index cf6d5a971..554e1f441 100644
--- a/docutils/parsers/rst/roles.py
+++ b/docutils/parsers/rst/roles.py
@@ -307,7 +307,7 @@ def raw_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
node = nodes.raw(rawtext, utils.unescape(text, 1), **options)
return [node], []
-raw_role.options = {'format': directives.class_option}
+raw_role.options = {'format': directives.unchanged}
register_canonical_role('raw', raw_role)
@@ -343,5 +343,5 @@ def set_classes(options):
"""
if options.has_key('class'):
assert not options.has_key('classes')
- options['classes'] = options['class'].split()
+ options['classes'] = options['class']
del options['class']
diff --git a/docutils/transforms/misc.py b/docutils/transforms/misc.py
index b325f554b..fb01c6c72 100644
--- a/docutils/transforms/misc.py
+++ b/docutils/transforms/misc.py
@@ -45,7 +45,6 @@ class ClassAttribute(Transform):
def apply(self):
pending = self.startnode
- class_value = pending.details['class']
parent = pending.parent
child = pending
while parent:
@@ -55,7 +54,7 @@ class ClassAttribute(Transform):
if (isinstance(element, nodes.Invisible) or
isinstance(element, nodes.system_message)):
continue
- element.set_class(class_value)
+ element['classes'] += pending.details['class']
pending.parent.remove(pending)
return
else:
diff --git a/docutils/transforms/parts.py b/docutils/transforms/parts.py
index a1405f729..20dbec880 100644
--- a/docutils/transforms/parts.py
+++ b/docutils/transforms/parts.py
@@ -135,7 +135,7 @@ class Contents(Transform):
if entries:
contents = nodes.bullet_list('', *entries)
if auto:
- contents.set_class('auto-toc')
+ contents['classes'].append('auto-toc')
return contents
else:
return []
diff --git a/docutils/writers/html4css1.py b/docutils/writers/html4css1.py
index 9a1a83873..4736f54e0 100644
--- a/docutils/writers/html4css1.py
+++ b/docutils/writers/html4css1.py
@@ -297,8 +297,8 @@ class HTMLTranslator(nodes.NodeVisitor):
def set_first_last(self, node):
if len(node):
- node[0].set_class('first')
- node[-1].set_class('last')
+ node[0]['classes'].append('first')
+ node[-1]['classes'].append('last')
def visit_Text(self, node):
self.body.append(self.encode(node.astext()))
@@ -474,10 +474,10 @@ class HTMLTranslator(nodes.NodeVisitor):
def visit_compound(self, node):
self.body.append(self.starttag(node, 'div', CLASS='compound'))
if len(node) > 1:
- node[0].set_class('compound-first')
- node[-1].set_class('compound-last')
+ node[0]['classes'].append('compound-first')
+ node[-1]['classes'].append('compound-last')
for child in node[1:-1]:
- child.set_class('compound-middle')
+ child['classes'].append('compound-middle')
def depart_compound(self, node):
self.body.append('</div>\n')
@@ -566,9 +566,9 @@ class HTMLTranslator(nodes.NodeVisitor):
% self.language.labels[name])
if len(node):
if isinstance(node[0], nodes.Element):
- node[0].set_class('first')
+ node[0]['classes'].append('first')
if isinstance(node[-1], nodes.Element):
- node[-1].set_class('last')
+ node[-1]['classes'].append('last')
def depart_docinfo_item(self):
self.body.append('</td></tr>\n')
@@ -745,8 +745,8 @@ class HTMLTranslator(nodes.NodeVisitor):
# If there are preceding backlinks, we do not set class
# 'first', because we need to retain the top-margin.
if not backlinks:
- node[1].set_class('first')
- node[-1].set_class('last')
+ node[1]['classes'].append('first')
+ node[-1]['classes'].append('last')
def depart_footnote(self, node):
self.body.append('</td></tr>\n'
@@ -801,8 +801,8 @@ class HTMLTranslator(nodes.NodeVisitor):
def visit_image(self, node):
atts = node.non_default_attributes()
- if atts.has_key('class'):
- del atts['class'] # prevent duplication with node attrs
+ if atts.has_key('classes'):
+ del atts['classes'] # prevent duplication with node attrs
atts['src'] = atts['uri']
del atts['uri']
if atts.has_key('scale'):
@@ -889,7 +889,7 @@ class HTMLTranslator(nodes.NodeVisitor):
def visit_list_item(self, node):
self.body.append(self.starttag(node, 'li', ''))
if len(node):
- node[0].set_class('first')
+ node[0]['classes'].append('first')
def depart_list_item(self, node):
self.body.append('</li>\n')
diff --git a/test/test_parsers/test_rst/test_directives/test_figures.py b/test/test_parsers/test_rst/test_directives/test_figures.py
index 355a06825..821841e07 100755
--- a/test/test_parsers/test_rst/test_directives/test_figures.py
+++ b/test/test_parsers/test_rst/test_directives/test_figures.py
@@ -94,12 +94,13 @@ totest['figures'] = [
:width: 200
:scale: 50
:figwidth: 300
+ :figclass: class1 class2
A picture with image options on individual lines, and this caption.
""",
"""\
<document source="test data">
- <figure width="300">
+ <figure classes="class1 class2" width="300">
<image alt="alternate text" height="100" scale="50" uri="picture.png" width="200">
<caption>
A picture with image options on individual lines, and this caption.