felixwiemann | 2 Apr 2005 23:57
Picon

r3155 - in trunk/docutils: HISTORY.txt docutils/nodes.py docutils/parsers/rst/directives/__init__.py docutils/parsers/rst/directives/admonitions.py docutils/parsers/rst/directives/body.py docutils/parsers/rst/directives/images.py docutils/parsers/rst/directives/parts.py docutils/parsers/rst/directives/tables.py docutils/parsers/rst/roles.py docutils/transforms/misc.py docutils/transforms/parts.py docutils/writers/html4css1.py test/test_parsers/test_rst/test_directives/test_figures.py

Author: felixwiemann
Date: 2005-04-02 23:57:06 +0200 (Sat, 02 Apr 2005)
New Revision: 3155

Modified:
   trunk/docutils/HISTORY.txt
   trunk/docutils/docutils/nodes.py
   trunk/docutils/docutils/parsers/rst/directives/__init__.py
   trunk/docutils/docutils/parsers/rst/directives/admonitions.py
   trunk/docutils/docutils/parsers/rst/directives/body.py
   trunk/docutils/docutils/parsers/rst/directives/images.py
   trunk/docutils/docutils/parsers/rst/directives/parts.py
   trunk/docutils/docutils/parsers/rst/directives/tables.py
   trunk/docutils/docutils/parsers/rst/roles.py
   trunk/docutils/docutils/transforms/misc.py
   trunk/docutils/docutils/transforms/parts.py
   trunk/docutils/docutils/writers/html4css1.py
   trunk/docutils/test/test_parsers/test_rst/test_directives/test_figures.py
Log:
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

Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt	2005-04-02 21:32:12 UTC (rev 3154)
+++ trunk/docutils/HISTORY.txt	2005-04-02 21:57:06 UTC (rev 3155)
 <at>  <at>  -41,6 +41,7  <at>  <at> 
   - 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.

Modified: trunk/docutils/docutils/nodes.py
===================================================================
--- trunk/docutils/docutils/nodes.py	2005-04-02 21:32:12 UTC (rev 3154)
+++ trunk/docutils/docutils/nodes.py	2005-04-02 21:57:06 UTC (rev 3155)
 <at>  <at>  -595,10 +595,6  <at>  <at> 
     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`."""

Modified: trunk/docutils/docutils/parsers/rst/directives/__init__.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/__init__.py	2005-04-02 21:32:12 UTC (rev 3154)
+++ trunk/docutils/docutils/parsers/rst/directives/__init__.py	2005-04-02 21:57:06 UTC (rev 3155)
 <at>  <at>  -284,7 +284,7  <at>  <at> 

 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.
 <at>  <at>  -298,7 +298,7  <at>  <at> 
         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)

Modified: trunk/docutils/docutils/parsers/rst/directives/admonitions.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/admonitions.py	2005-04-02 21:32:12 UTC (rev 3154)
+++ trunk/docutils/docutils/parsers/rst/directives/admonitions.py	2005-04-02 21:57:06 UTC (rev 3155)
 <at>  <at>  -30,10 +30,10  <at>  <at> 
         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]

Modified: trunk/docutils/docutils/parsers/rst/directives/body.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/body.py	2005-04-02 21:32:12 UTC (rev 3154)
+++ trunk/docutils/docutils/parsers/rst/directives/body.py	2005-04-02 21:57:06 UTC (rev 3155)
 <at>  <at>  -16,6 +16,7  <at>  <at> 
 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,
 <at>  <at>  -44,8 +45,7  <at>  <at> 
         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]
 <at>  <at>  -72,7 +72,7  <at>  <at> 
             '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(),
 <at>  <at>  -91,6 +91,7  <at>  <at> 

 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)
 <at>  <at>  -124,7 +125,7  <at>  <at> 
 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
 <at>  <at>  -132,7 +133,7  <at>  <at> 
 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
 <at>  <at>  -140,7 +141,7  <at>  <at> 
 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
 <at>  <at>  -154,8 +155,7  <at>  <at> 
             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]

Modified: trunk/docutils/docutils/parsers/rst/directives/images.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/images.py	2005-04-02 21:32:12 UTC (rev 3154)
+++ trunk/docutils/docutils/parsers/rst/directives/images.py	2005-04-02 21:57:06 UTC (rev 3155)
 <at>  <at>  -15,6 +15,7  <at>  <at> 
 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
 <at>  <at>  -45,6 +46,7  <at>  <at> 
         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
 <at>  <at>  -64,7 +66,7  <at>  <at> 
 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,
 <at>  <at>  -84,8 +86,8  <at>  <at> 
                 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)

Modified: trunk/docutils/docutils/parsers/rst/directives/parts.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/parts.py	2005-04-02 21:32:12 UTC (rev 3154)
+++ trunk/docutils/docutils/parsers/rst/directives/parts.py	2005-04-02 21:57:06 UTC (rev 3155)
 <at>  <at>  -43,9 +43,7  <at>  <at> 

     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()

Modified: trunk/docutils/docutils/parsers/rst/directives/tables.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/tables.py	2005-04-02 21:32:12 UTC (rev 3154)
+++ trunk/docutils/docutils/parsers/rst/directives/tables.py	2005-04-02 21:57:06 UTC (rev 3155)
 <at>  <at>  -53,8 +53,7  <at>  <at> 
             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
 <at>  <at>  -147,8 +146,7  <at>  <at> 
         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
 <at>  <at>  -342,8 +340,7  <at>  <at> 
     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

Modified: trunk/docutils/docutils/parsers/rst/roles.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/roles.py	2005-04-02 21:32:12 UTC (rev 3154)
+++ trunk/docutils/docutils/parsers/rst/roles.py	2005-04-02 21:57:06 UTC (rev 3155)
 <at>  <at>  -307,7 +307,7  <at>  <at> 
     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)

 <at>  <at>  -343,5 +343,5  <at>  <at> 
     """
     if options.has_key('class'):
         assert not options.has_key('classes')
-        options['classes'] = options['class'].split()
+        options['classes'] = options['class']
         del options['class']

Modified: trunk/docutils/docutils/transforms/misc.py
===================================================================
--- trunk/docutils/docutils/transforms/misc.py	2005-04-02 21:32:12 UTC (rev 3154)
+++ trunk/docutils/docutils/transforms/misc.py	2005-04-02 21:57:06 UTC (rev 3155)
 <at>  <at>  -45,7 +45,6  <at>  <at> 

     def apply(self):
         pending = self.startnode
-        class_value = pending.details['class']
         parent = pending.parent
         child = pending
         while parent:
 <at>  <at>  -55,7 +54,7  <at>  <at> 
                 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:

Modified: trunk/docutils/docutils/transforms/parts.py
===================================================================
--- trunk/docutils/docutils/transforms/parts.py	2005-04-02 21:32:12 UTC (rev 3154)
+++ trunk/docutils/docutils/transforms/parts.py	2005-04-02 21:57:06 UTC (rev 3155)
 <at>  <at>  -135,7 +135,7  <at>  <at> 
         if entries:
             contents = nodes.bullet_list('', *entries)
             if auto:
-                contents.set_class('auto-toc')
+                contents['classes'].append('auto-toc')
             return contents
         else:
             return []

Modified: trunk/docutils/docutils/writers/html4css1.py
===================================================================
--- trunk/docutils/docutils/writers/html4css1.py	2005-04-02 21:32:12 UTC (rev 3154)
+++ trunk/docutils/docutils/writers/html4css1.py	2005-04-02 21:57:06 UTC (rev 3155)
 <at>  <at>  -297,8 +297,8  <at>  <at> 

     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()))
 <at>  <at>  -474,10 +474,10  <at>  <at> 
     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')
 <at>  <at>  -566,9 +566,9  <at>  <at> 
                          % 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')
 <at>  <at>  -745,8 +745,8  <at>  <at> 
             # 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'
 <at>  <at>  -801,8 +801,8  <at>  <at> 

     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'):
 <at>  <at>  -889,7 +889,7  <at>  <at> 
     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')

Modified: trunk/docutils/test/test_parsers/test_rst/test_directives/test_figures.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_directives/test_figures.py	2005-04-02
21:32:12 UTC (rev 3154)
+++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_figures.py	2005-04-02
21:57:06 UTC (rev 3155)
 <at>  <at>  -94,12 +94,13  <at>  <at> 
    :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.

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click

Gmane