[3] | 1 | # Authors: Felix Wiemann |
---|
| 2 | # Contact: Felix_Wiemann@ososo.de |
---|
| 3 | # Revision: $Revision: 3909 $ |
---|
| 4 | # Date: $Date: 2005-09-26 20:17:31 +0200 (Mon, 26 Sep 2005) $ |
---|
| 5 | # Copyright: This module has been placed in the public domain. |
---|
| 6 | |
---|
| 7 | """ |
---|
| 8 | Auxiliary transforms mainly to be used by Writer components. |
---|
| 9 | |
---|
| 10 | This module is called "writer_aux" because otherwise there would be |
---|
| 11 | conflicting imports like this one:: |
---|
| 12 | |
---|
| 13 | from docutils import writers |
---|
| 14 | from docutils.transforms import writers |
---|
| 15 | """ |
---|
| 16 | |
---|
| 17 | __docformat__ = 'reStructuredText' |
---|
| 18 | |
---|
| 19 | from docutils import nodes, utils |
---|
| 20 | from docutils.transforms import Transform |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | class Compound(Transform): |
---|
| 24 | |
---|
| 25 | """ |
---|
| 26 | Flatten all compound paragraphs. For example, transform :: |
---|
| 27 | |
---|
| 28 | <compound> |
---|
| 29 | <paragraph> |
---|
| 30 | <literal_block> |
---|
| 31 | <paragraph> |
---|
| 32 | |
---|
| 33 | into :: |
---|
| 34 | |
---|
| 35 | <paragraph> |
---|
| 36 | <literal_block classes="continued"> |
---|
| 37 | <paragraph classes="continued"> |
---|
| 38 | """ |
---|
| 39 | |
---|
| 40 | default_priority = 810 |
---|
| 41 | |
---|
| 42 | def apply(self): |
---|
| 43 | for compound in self.document.traverse(nodes.compound): |
---|
| 44 | first_child = 1 |
---|
| 45 | for child in compound: |
---|
| 46 | if first_child: |
---|
| 47 | if not isinstance(child, nodes.Invisible): |
---|
| 48 | first_child = 0 |
---|
| 49 | else: |
---|
| 50 | child['classes'].append('continued') |
---|
| 51 | # Substitute children for compound. |
---|
| 52 | compound.replace_self(compound[:]) |
---|