3 # Copyright (C) 2010 Stefan Merten
5 # rstdiff.py is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published
7 # by the Free Software Foundation; either version 2 of the License,
8 # or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 Translates a reStructuredText document to a plain text outline. This
22 can then be transformed_ to PowerPoint.
24 .. _transformed: http://www.pptfaq.com/FAQ00246.htm
29 locale
.setlocale(locale
.LC_ALL
, '')
33 from docutils
import frontend
, writers
, nodes
34 from docutils
.core
import publish_cmdline
, default_description
36 description
= ('Generates a plain text outline from a standalone '
37 'reStructuredText source. ' + default_description
)
39 class Writer(writers
.Writer
):
41 supported
= ('outline',)
42 """Formats this writer supports."""
45 'Outline Writer Options',
50 settings_defaults
= { }
52 config_section
= 'outline writer'
53 config_section_dependencies
= ( 'writers', )
56 """Final translated form of `document`."""
59 settings
= self
.document
.settings
60 visitor
= OutlineTranslator(self
.document
)
61 self
.document
.walkabout(visitor
)
62 self
.output
= visitor
.doc
64 class OutlineTranslator(nodes
.SparseNodeVisitor
):
67 """The resulting document."""
74 def __init__(self
, document
):
75 nodes
.SparseNodeVisitor
.__init
__(self
, document
)
77 def visit_title(self
, node
):
81 def depart_title(self
, node
):
85 def visit_bullet_list(self
, node
):
88 def depart_bullet_list(self
, node
):
91 # TODO Other list types need to be included as well
93 def visit_list_item(self
, node
):
96 def depart_list_item(self
, node
):
99 def visit_paragraph(self
, node
):
103 self
.addBol(self
.inBullet
)
105 def depart_paragraph(self
, node
):
110 def visit_Text(self
, node
):
111 if self
.inTitle
or self
.inPara
:
112 self
.addText(node
.astext())
114 def addBol(self
, level
):
115 self
.doc
+= "\t" * level
117 def addText(self
, text
):
118 self
.doc
+= text
.replace("\n", " ")
123 # TODO References to images should be included somehow
125 publish_cmdline(writer
=Writer(), description
=description
)